# Audit Logging

> Immutable log of who did what, when — for compliance, debugging, and forensics.

- **Category**: Microservices
- **Subcategory**: Observability
- **Canonical URL**: https://designpattern.fyi/patterns/audit_logging/

---

## Description
Clean, reusable architecture pattern.


## Use Cases
User updates their payment method. Audit log records userId, action=UPDATE_PAYMENT, timestamp, old/new values (masked). Security team can reconstruct exactly what happened and when.





## Trade-offs


### Advantages

- Compliance-ready out of the box (GDPR, SOC2, HIPAA)

- Forensic trail for security incidents

- Debugging aid — replay exact sequence of events

- Supports "who changed this?" queries instantly




### Considerations & Drawbacks

- Can generate enormous log volume at scale

- PII in audit logs needs careful masking / retention policies

- Performance impact if synchronous on every write

- Querying unstructured audit logs can be painful without good tooling







---
**Reference**: [Original Source](https://microservices.io/patterns/observability/audit-logging.html)

