Data & Integrity

Audit Trails & Traceability

Intermediate

An audit trail is a data structure with legal weight. It is an append-only, attributable record of what changed, who changed it, and when. This is the implementation view: how to model and write that trail correctly in the data tier. It complements the compliance view in Auditability & Evidence.

Traceability means that for any record or decision you can rebuild its history: the sequence of changes, the actor behind each one, and enough context to understand why. Building that well is a data-modelling problem. You capture the right events with the right fields, write them in the same transaction as the action, and store them so they cannot be quietly altered.

Get the mechanism right and audit becomes a reliable by-product of normal operation, not a scramble when an investigator asks. Get it wrong, with entries that can be edited, actions that commit without their audit row, or timestamps you cannot trust, and the trail is worse than useless. It looks authoritative while being incomplete.

Capture the right record

Make it trustworthy

Mutable, detached audit db.Execute("UPDATE Audit SET Detail=@d WHERE Id=@id"); // editable
// ...and written in a separate call that can fail independently of the action

An editable audit row can drift out of sync with the action it claims to record. Under scrutiny it proves nothing, and may prove the wrong thing.

Append-only, in-transaction using var tx = conn.BeginTransaction();
conn.Execute("UPDATE Customers SET RiskBand=@to WHERE Id=@id AND TenantId=@t", p, tx);
conn.Execute(@"INSERT INTO AuditLog(Entity,Action,ActorId,FromValue,ToValue,OccurredUtc)
VALUES('Customer','RiskBand',@actor,@from,@to,@now)", p, tx);
tx.Commit();

Insert-only, committed atomically with the change, attributed and timestamped. The record holds up because it cannot have happened any other way.

Self-review checklist

Why it matters: The audit trail is the system's memory, and in a regulated business it is its testimony. It is the record we rely on to investigate incidents and to answer to regulators. Modelled as append-only, attributable, in-transaction data, it stays trustworthy exactly when it is needed most. Built carelessly, it gives false confidence and fails under scrutiny.