
3. Real-World Use Cases
1. Financial Services
Scenario: Banking transaction processing
Use Case: Track every transaction, balance change, and access attempt
Requirements:
- Immutable records of all transactions
- 7-10 year retention for compliance
- Millisecond-precision timestamps
- Ability to prove no tampering
Implementation:
- Separate audit database with write-only access
- Cryptographic signatures on audit entries
- Regular backup to immutable storage (S3 Glacier)2. Healthcare (HIPAA Compliance)
Scenario: Patient record access tracking
Use Case: Track who viewed/modified patient records
Requirements:
- Log every access to protected health information (PHI)
- Capture: user, timestamp, patient ID, action, reason
- Alert on suspicious access patterns
- Retain for 6+ years
Implementation:
- Real-time audit logging on every PHI access
- Automated alerting for unusual patterns
- Encrypted audit logs
- Regular compliance reports3. E-Commerce Order Management
Scenario: Order lifecycle tracking
Use Case: Track order state transitions from creation to delivery
Requirements:
- Capture state changes: created → paid → shipped → delivered
- Record who authorized changes
- Support dispute resolution
- Enable order reconstruction
Implementation:
- State machine with audit trail
- Transition validation rules
- Rollback capability for specific states4. API Access Control
Scenario: RESTful API request tracking
Use Case: Monitor API usage, detect abuse, support debugging
Requirements:
- Log API requests: endpoint, method, user, parameters
- Track rate limiting violations
- Capture response status and errors
- Enable analytics and billing
Implementation:
- Middleware-based request/response logging
- Async logging to not block requests
- Log aggregation (ELK stack, Splunk)
- Real-time alerting on anomalies5. Multi-Tenant SaaS
Scenario: User action tracking across tenants
Use Case: Provide audit trails to enterprise customers
Requirements:
- Per-tenant audit logs
- Customer-accessible audit UI
- GDPR right-to-erasure support
- Role-based audit log access
Implementation:
- Tenant-isolated audit tables or schemas
- Audit API endpoints for customers
- Export functionality (CSV, JSON)
- Data retention policies per tenant6. Incident Management System
Scenario: Tracking incident status and updates
Use Case: Track incident lifecycle and all updates
Requirements:
- Every status change logged
- Update history with timestamps
- Severity changes tracked
- Automated timeline generation
Implementation:
- Event-sourced incident aggregate
- Rich timeline reconstruction
- Audit log as secondary index
- Real-time status boardFollowing an Editorial Audit Trail
A content edit in this API illustrates how a state-changing workflow can create an audit trail. The application checks the submitted version, merges and validates the edit, writes a new content_revisions row, advances current_revision_id, and inserts an audit row with the actor, action, and entry ID. Approval, withdrawal, and archival each update their corresponding content state and write an audit action.
The PostgreSQL adapter runs editorial writes in a transaction and takes an advisory transaction lock before invoking the application workflow. The audit insert uses the same transaction-scoped repository. If a write step returns an error, the transaction callback returns the error, so the content change and audit row are committed together or rolled back together.
This concrete path can be used to reason about other business workflows: name the state transition, decide which actor and target identify it, and place the audit write inside the same transaction as the state change when both records must agree.
References: GORM transactions.
Expanded from the supplied audit-log article
Why RefactorRoom separates audit logs from revisions
The RefactorRoom editorial design has three related concepts:
audit_logsrecords the actor, action, target, and timestamps.content_revisionsstores versioned article content as JSONB, along with its actor.content_entriesidentifies the article and points to its current revision and, when approved, its approved revision.
The existing AuditLog model has been described as embedding Base, then adding Actor, Action, and Target. The extended schema later in this article is a suggested design, not a reproduction of that model or its migration.

Operation history, version history, and current pointers answer different questions.
Think of the three tables as three different responsibilities:
| Table | Main question | Example |
|---|---|---|
audit_logs |
What operation happened? | Editor 42 edited entry 17 at a specific time. |
content_revisions |
What content was saved? | Revision 203 contains the article JSONB document. |
content_entries |
Which version is active? | Entry 17 points to current revision 203. |
This separation avoids a common mistake: turning every audit record into a full copy of the entire business object.
The audit event can reference a revision ID. The revision stores the content. The entry stores the pointer that the application uses to decide which version to serve.
PostgreSQL's jsonb data type is a practical choice for structured revision documents. It supports querying and indexing JSON content, but it does not preserve the original whitespace or object-key ordering. If exact byte-level reproduction is a requirement, you need a different storage decision.
Further reading
Originally published on DEV Community.


