Q&A-2Decide what a new payment service should log for security.
Answer
What I'd say first
Log at the decision point, not at the edge. For a payment service the security-relevant decisions are: session establishment, authorization on every money-moving call, the payment state transition, refunds and voids, privileged support actions, key and config changes, and bulk data export. One structured event per decision, one schema, and the log pipeline gets its own SLO, because logging is detective, not preventive. It never stops a fraudulent refund; it makes that refund findable in 90 seconds instead of 9 hours.
Assumption I'd state out loud: this service stores PAN, so PCI DSS v4.0 applies. If it's tokenization-only and never sees a PAN, the field list shrinks and retention becomes a business call.
The event
PCI DSS v4.0 Req 10.2.2 names the minimum: user identification, event type, date/time, success or failure, origination, and the affected resource. Everything else is what your investigation needs.
| field | why | example |
|---|---|---|
| event_id | dedupe on retry | uuidv4 |
| event_time, receipt_time | detect clock skew and pipeline lag | RFC 3339, UTC |
| actor_id, actor_type | who | sup_8812 / customer / service |
| on_behalf_of | delegated support access | cust_3391 |
| action, outcome | what was attempted and decided | refund / allow |
| object, tenant | what it touched | ord_5521, merchant_44 |
| amount, currency | money-moving events only | 4200, USD |
| reason_code | why, without free text | goodwill |
| trace_id | joins to gateway and DB evidence | W3C traceparent |
| schema_version, service, env | parse and route | pay.audit.v1 |
Never in the event: PAN beyond the first six and last four digits, CVV, full track data, PINs, passwords, tokens, private keys. PCI DSS v4.0 Req 3.3.1 forbids storing SAD after authorization, and Req 3.4.1 requires stored PAN to be rendered unreadable.
Trade-offs
Volume vs investigability. Size it: 200 TPS × ~6 audit events per payment = 1,200 events/s; at 1 KB each that's ~1.2 MB/s, ~100 GB/day, ~3 TB/month. PCI DSS v4.0 Req 10.5.1 wants 12 months retained with the most recent 3 months immediately searchable: ~37 TB raw, ~4 TB after JSON compression in object storage. That number is what kills "log the whole request body".
Exclusion vs field-level encryption. Encrypting a PAN into the log keeps it in PCI scope and in your key-rotation path; excluding it doesn't. Exclude by default; encrypt only where a dispute or regulator genuinely needs the value.
Synchronous vs asynchronous. Writing the audit event in the same DB transaction as the payment guarantees no money moves unrecorded, but couples payment availability to log storage. The outbox pattern gets both: write to a local outbox table inside the payment transaction, ship asynchronously to the central store. Never block the payment on the central sink.
Failure modes
- Log injection. A merchant name of
Acme\n{"outcome":"allow"}forges a second event in a line-delimited sink. JSON-encode every value, strip control characters, alert on parse failures. - PAN in free text. A decline reason or support note carrying a full PAN. Regex-scan the stream at ingest and in CI.
- Clock skew. A host four minutes off reorders the trace. PCI DSS v4.0 Req 10.6 requires time sync; alert above 1s offset.
- Duplicates on retry. Dedupe on event_id at ingest.
- Pipeline outage. If the payment path blocks on the sink, a logging outage becomes a payment outage.
Worked trace
Support agent sup_8812 refunds ord_5521 twice in 90 seconds:
{"event_id":"a1","event_time":"2025-03-04T10:00:00Z","actor_id":"sup_8812","actor_type":"support","on_behalf_of":"cust_3391","action":"payment.refund","outcome":"allow","object":"ord_5521","amount":4200,"currency":"USD","reason_code":"goodwill","trace_id":"4bf92f..."}
{"event_id":"b7","event_time":"2025-03-04T10:01:30Z","actor_id":"sup_8812","actor_type":"support","on_behalf_of":"cust_3391","action":"payment.refund","outcome":"allow","object":"ord_5521","amount":4200,"currency":"USD","reason_code":"goodwill","trace_id":"9c1d04..."}Detection rule: two payment.refund events with outcome=allow, same object, different event_id, within 300s → page. That rule is only writable because object, amount and actor are structured fields rather than prose.
What would change the decision
If the service never stores PAN, drop the masking machinery and the 12-month floor becomes a business choice. If a financial-records rule sets a longer retention, that dominates PCI's 12 months. And if the payment path can't tolerate the outbox write, you're choosing between losing audit events and losing payments: pick the outbox.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.