Coding Standard — Audit Trail (Pub/Sub → document-service)
This page is the Coding Standards home for the audit-trail publishing pattern — pushing a service’s request/response JSON into document-service’s audit sink. payment-service (Rust) and shipment-service (Go) are instrumented today; this documents the pattern so a future publisher adopts it consistently, not a requirement that every service retrofit it immediately. Adopt it incrementally, one service at a time, when that service’s own audit/compliance need calls for it.
Envelope shape
A publisher sends a Pub/Sub message whose body carries tenant_id, service_name, transaction_name, transaction_id, date_time, and the full, raw request/response JSON:
{
"tenant_id": "...",
"service_name": "payment-service",
"transaction_name": "create_payment_order",
"transaction_id": "...",
"date_time": "2026-09-04T10:15:00Z",
"request": { },
"response": { }
}
(tenant_id, service_name, transaction_name, transaction_id) is the idempotency key document-service uses to dedupe redelivered messages — transaction_name must stay stable across calls to the same logical operation.
Masking responsibility boundary — mandatory
The publisher never masks anything. document-service masks exactly once, at persistence time, before writing the JSON object to GCS. A publisher always sends the raw, unmasked request/response — this preserves the source of truth for any future re-processing, and masking is only idempotent if it runs in exactly one place. Never mask at the publisher, and never add a second masking pass anywhere else; a newly-instrumented publisher that introduces a sensitive field not already covered extends document-service’s own masked-field set, rather than pre-masking its own payload.
Publishing — one flat file per event type, fire-and-forget
Both language implementations place the publisher in a message_publisher/ layer, sibling to repository/service/domain/transport — one flat file per event type, never a message_publisher/<feature>/ subdirectory.
Rust (payment-service) |
Go (shipment-service) |
|
|---|---|---|
| Call site | tokio::spawn fire-and-forget |
context.WithoutCancel(ctx) + a goroutine |
| Publish helper | rust_lang_core_lib::pubsub::publish — never a raw Pub/Sub client held in service/ |
Hand-assembled message.MessageEnvelope[D] + client.Topic(topicID).Publish — Go’s core lib has no publish helper the way Rust’s does |
| Failure handling | Logged, never fails the RPC/webhook response that triggered it | Logged (log.LogErrorWithTrace), never fails the RPC/webhook response |
A new required *_TOPIC_ID environment variable per topic fails fast at boot, per Coding Standard — Deployment & Local Infrastructure’s fail-fast principle.
Related Documents
- Microservices — payment-service
- Microservices — shipment-service
- Microservices — document-service
- SR-011 — Multi-Courier Fulfillment (Shiprocket)
- SR-016 — Payment Capture and Confirmation
- Technical Debt — Multi-Courier Fulfillment Gaps
- Layered Architecture Across Languages
- Cross-Cutting Principles Across Languages