Document-Service — Centralized Audit Trail Sink

By Engineering Team•September 24, 2026•5 min read

Responsibility

document-service is the platform’s single audit-trail sink — the only service that writes a masked, durable record of what an instrumented publisher microservice sent to, and received from, a third-party provider.

  • Subscribes to the document-audit Pub/Sub topic — the only way an audit event reaches this service. No gRPC or REST ingestion surface exists.
  • Masks every PII/PCI-shaped field in the raw request/response JSON before anything is persisted — phone/mobile and email fields get a partial mask, token/password/authorization fields get full redaction, every other sensitive field gets full redaction.
  • Uploads the masked JSON to GCS under a UUID-keyed object path ({service_name}/{transaction_name}/{uuid_v4}.json) and tracks (tenant_id, service_name, transaction_name, transaction_id) → storage_path plus a status/error_message in the document_track MongoDB collection.
  • Exposes exactly one HTTP route — a health check — and nothing else.

payment-service and shipment-service are the two publishers instrumented today; the pattern is designed so a future publisher can adopt it with zero change inside document-service itself.

Tech Stack

Concern Choice
Language Rust
Web framework Axum (health check only)
Data store MongoDB — document_track collection, via rust-lang-core-lib’s db::connect_mongo
Object storage Firebase Storage / GCS — masked JSON audit records
Messaging Firebase Pub/Sub — subscriber only, document-audit subscription
Core library rust-lang-core-lib (typed errors, logging macros, Pub/Sub receiver)
Observability Tracing + OpenTelemetry

Ports

Gateway HTTP Service
No Nginx-routed feature surface — health check only 8095 (host) → 8080 (container) document-service

Implementation Notes

  • Masking runs exactly once, inside mask_pii (service/documentaudit/documentaudit_masking.rs) — a publisher never masks its own payload; see the audit trail standard’s masking-boundary rule.
  • The document_track row is inserted as PENDING before the GCS upload is attempted, then updated to SUCCESS/FAILED after — the unique compound index on (tenant_id, service_name, transaction_name, transaction_id) is what actually stops a redelivered message from double-processing, not the two-phase write by itself.
  • The Pub/Sub receiver acks every message once the handler returns, even on failure — a failed process_audit_event call is never retried by redelivery, only logged and recorded as a FAILED tracking row. See Technical Debt — Document Service Audit Trail Gaps, TD-01.
  • The GCS object filename is always a fresh UUID, never transaction_id — so a reused or redelivered transaction_id can never collide with an already-written object, even before the Mongo idempotency check runs.
  • SYSTEM_USER_ID = "system:document-service" is used for created_user_id/updated_user_id on every document_track row, since this service has no authenticated human/request actor of its own — it only ever acts on a Pub/Sub message.
  • PII_KEYS (documentaudit_masking.rs) is a flat, exact-match key set, not a pattern/heuristic — a new publisher field only gets masked if its lowercased JSON key is literally in the set. shipment-service’s create_order audit event introduced city/state/pincode fields inside its resolved ShippingAddress/BillingAddress objects that are not yet in this set and currently pass through unmasked — see Technical Debt — Multi-Courier Fulfillment Gaps, TD-05.

Full service reference: document-service/CLAUDE.md. Pipeline overview: ADR-00002 — Subscribe-Only Audit Sink, Mask-Once-At-Persistence.