SR-002 — Document Service Audit Trail: System Requirements
By Engineering Team•September 24, 2026•6 min read
| Metadata | Details |
|---|---|
| System Name | Document Service — Centralized Audit Trail Sink |
| Document ID | SR-2026-AUDIT-001 |
| Author | Engineering Team |
| Status | Approved |
Traces back to BRD-002 — Document Service: Centralized Audit Trail.
Functional Requirements
Ingestion
- FR-01 (Subscribe-Only Ingestion):
document-serviceMUST consumeAuditEventPayloadmessages from itsdocument-auditPub/Sub subscription only — it MUST NOT expose any gRPC or REST ingestion endpoint. - FR-02 (Standard Envelope): every audit event MUST carry
{tenant_id, service_name, transaction_name, transaction_id, date_time, request, response}—tenant_id,service_name,transaction_name, andtransaction_idtogether form the idempotency key.
Masking & Persistence
- FR-03 (Mask-Once-At-Persistence):
document-serviceMUST mask every field matching itsPII_KEYSset in bothrequestandresponsebefore the JSON is ever written to storage — phone/mobile keys receive a partial regex mask, email keys receive a partial mask, token/password/authorization keys receive full[REDACTED_SECRET]redaction, and every otherPII_KEYSmatch receives full[REDACTED_PII]redaction. Publishers MUST NOT mask their own payloads. - FR-04 (Masked Storage): the masked JSON object MUST be uploaded to the configured GCS bucket under the object key
{service_name}/{transaction_name}/{uuid_v4}.json— the filename MUST be a freshly generated UUID, never derived fromtransaction_id. - FR-05 (Transaction Tracking):
document-serviceMUST record(tenant_id, service_name, transaction_name, transaction_id) → storage_pathplus astatus(PENDING/SUCCESS/FAILED) and an optionalerror_messagein thedocument_trackMongoDB collection. - FR-06 (Two-Phase Idempotent Write):
document-serviceMUST insert thedocument_trackrow asPENDINGbefore attempting the GCS upload, and MUST update it toSUCCESSorFAILEDafter the upload attempt completes — a duplicate delivery for an already-tracked(tenant_id, service_name, transaction_name, transaction_id)MUST be a no-op, never a duplicate row or a duplicate GCS object.
Surface
- FR-07 (Health-Only Surface):
document-serviceMUST expose exactly one HTTP route, a health check — no other REST or gRPC surface, per its subscribe-only design.
Publisher Contract
- FR-08 (Fire-and-Forget Publish): a publisher MUST publish its audit event fire-and-forget (
tokio::spawnin Rust, a goroutine overcontext.WithoutCancel(ctx)in Go) — a publish failure MUST be logged, never propagated into the RPC/webhook response that triggered it. - FR-09 (Raw, Unmasked Payload): a publisher MUST send the full, unmasked
request/responseJSON — masking is exclusivelydocument-service’s responsibility, never the publisher’s.
Non-Functional Requirements
Reliability
- NFR-01 (Non-Blocking Publish Latency): a publisher’s audit-event publish MUST add no observable latency to, and MUST NOT be able to fail, the RPC/webhook response path that triggered it (verified: both
payment-serviceandshipment-servicecall sites are fire-and-forget). - NFR-02 (Redelivery / Retry on Handler Failure): a failed
process_audit_eventhandler invocation SHOULD be retried via Pub/Sub redelivery. (Gap — the shared core-lib Pub/Sub receiver acks every message unconditionally once the handler returns, even on failure, so no redelivery ever occurs for a failed audit event. Tracked as technical debt — see Technical Debt — Document Service Audit Trail Gaps, TD-01.)
Traceability & Multi-Tenancy
- NFR-03 (Trace Propagation):
traceparent/correlation_idMUST propagate through the Pub/Sub envelope header from the publisher’s originating request through todocument-service’s processing span, per SR-003 FR-08. - NFR-04 (Tenant Scoping): every persisted
document_trackrow MUST carrytenant_idsourced from the audit event envelope — never invented or defaulted server-side.
Masking Integrity
- NFR-05 (Masking Idempotency): masking MUST run exactly once, only inside
document-service, at persistence time — a publisher pre-masking its own payload, or a second masking pass anywhere else, is explicitly disallowed, since masking is not guaranteed idempotent under double-application. - NFR-06 (Extensible Coverage): adding a new sensitive field name to masking coverage MUST require a change in exactly one place (
PII_KEYSindocumentaudit_masking.rs), never a change to any publisher.
Data Retention
- NFR-07 (Retention Policy): a
document_trackrow and its corresponding masked GCS object SHOULD be retained only as long as the tenant’s compliance/audit window requires, not indefinitely by default. (Gap — no TTL index exists ondocument_track, no GCS bucket lifecycle rule exists on the audit bucket, and no scheduled cleanup job exists anywhere indocument-service— every row and object persists forever. Tracked as technical debt — see Technical Debt — Document Service Audit Trail Gaps, TD-02.)