tech, developers, and the code underneath

issue 240· essay·

The audit log

Who did what, when, and to what. Getting it right is mostly about deciding it is a product feature rather than a log.

Audit logs get built twice. First as a side effect of application logging, which turns out to be unqueryable and incomplete. Then properly, under deadline, because a customer's security review asked for one.

The second build is not much harder than the first if you know what it needs.

what it is not#

Not your application log. Application logs are for debugging, high-volume, sampled, and deleted after a week. Audit records are low-volume, complete, and retained for years. Conflating them means either drowning in noise or losing records to retention.

Not the database's change log. WAL and binlogs record row changes, not intent. "UPDATE users SET role='admin' WHERE id=42" does not tell you who did it, through what interface, or why.

Not analytics events. Those are sampled and lossy by design.

the record#

Every entry answers six questions:

json
{
  "id": "aud_01J9F3K2M4N5P6Q7R8S9",
  "occurred_at": "2026-10-29T14:22:11.482Z",
  "actor": {
    "type": "user",
    "id": "usr_8812",
    "email_at_time": "priya@example.com",
    "ip": "203.0.113.42",
    "user_agent": "Mozilla/5.0 ..."
  },
  "action": "role.granted",
  "target": { "type": "user", "id": "usr_4417" },
  "context": {
    "org_id": "org_44",
    "interface": "web",
    "request_id": "req_01J9F3K2M4",
    "reason": "onboarding — ticket SUP-3312"
  },
  "changes": { "role": { "from": "member", "to": "admin" } }
}

Who (actor, with identity captured at the time — emails change), what (a stable action name), to what (target), when, from where (interface, IP, request ID), and what changed (before and after).

email_at_time is the detail people miss. Resolving actor IDs to current names at read time means a record from 2024 shows the person's current email, or "deleted user," and your audit trail has quietly rewritten history.

the properties that matter#

Append-only. No updates, no deletes, enforced by permissions rather than by convention. An audit log an administrator can edit is not evidence.

Complete for what it covers. Better to audit ten actions completely than fifty with gaps. A log with holes is worse than none, because it invites false confidence.

Written in the same transaction as the change. If the change commits and the audit write fails, you have an unrecorded change. Same transaction, or an outbox pattern if it must be asynchronous.

Queryable by the axes people ask about. Every real question is "what did this user do," "what happened to this resource," or "what happened in this window." Index for those three from the start.

Retained on its own schedule. Usually years, often driven by a compliance requirement. Separate storage from your operational database so retention does not fight with performance.

what to record#

Not everything. Anything that would matter in an investigation:

  • Authentication — login, logout, failure, MFA enrolment, password change.
  • Authorisation — role grants, permission changes, API key creation. The highest-value category by a distance.
  • Data access for sensitive records, if your regulatory environment requires it. Expensive and sometimes mandatory.
  • Data modification for anything a customer would dispute.
  • Configuration — settings, integrations, webhooks, billing.
  • Administrative action, especially anything done by your own staff on behalf of a customer. This is the one customers ask about in security reviews and the one most products cannot answer.
  • Export and deletion — who took the data out.

make it a product feature#

The organisations that do this well expose it to customers rather than keeping it internal.

A searchable audit log in the UI, filterable by actor and date, exportable to CSV, and streamable to a customer's own SIEM. That turns a compliance obligation into something that closes enterprise deals, and it forces the log to be good — because customers will notice the gaps that an internal-only log gets away with.

It also removes an entire class of support ticket, since "who changed this?" becomes self-service.

the test#

Pick a change made last month. Answer: who made it, when, from where, what was the previous value, and what else did they do that session.

If any of those takes more than a query, that is the gap — and it is much cheaper to find now than during an incident, when the question is being asked by someone with a lawyer.

get README in your inbox

One dispatch, no noise. Tech and developer news, plus the occasional long piece on the craft.

subscribe →