Audit Event Schema
An audit event schema defines a consistent structure for recording security- or accountability-relevant actions. It captures who performed an action, what happened, when and where it occurred, and which resource was affected.
An audit event is a structured record of an action that matters for accountability, security, or troubleshooting. A schema makes these records consistent so applications and downstream systems can process them reliably.
A useful event commonly includes an event identifier, timestamp, actor, action, target resource, outcome, and request or correlation identifier. Depending on the system, actor and target may be represented by stable IDs rather than human-readable names.
The timestamp should represent when the event occurred, and the event should normally use a consistent time representation such as UTC. The action should describe the operation precisely, while the outcome distinguishes cases such as success and failure.
In a Java backend, the schema can be represented by a DTO or record and serialized as JSON. Keeping the structure stable helps log collectors, security tools, and auditors consume events without special handling for every application.
Audit records should avoid unnecessary sensitive data. Authentication credentials, access tokens, and other secrets should not be written into audit events merely because they were present in the request.
Key points
- Use a consistent structure for audit records.
- Capture actor, action, target, timestamp, and outcome.
- Prefer stable identifiers and a consistent timestamp convention.
- Include correlation information when events must be traced across requests or services.
- Do not put passwords, tokens, or other secrets into audit records.
Interview questions
What fields would you include in an audit event schema?
I would include an event ID, timestamp, actor ID, action, target resource, outcome, and usually a correlation or request ID. The exact fields depend on the system's auditing requirements. I would keep identifiers stable and use a consistent timestamp format. I would also avoid recording secrets or unnecessary sensitive information.
Why should audit events use a structured schema instead of plain log messages?
Structured events give every record predictable fields and types, which makes querying and aggregation much easier. A security system can reliably filter by actor, action, resource, or outcome without parsing arbitrary sentences. Consistency also makes events easier to consume across multiple services. It reduces ambiguity when investigating an incident.
What is the difference between an audit event and a normal application log?
A normal application log is often written to help developers understand application behavior or diagnose failures. An audit event has a more deliberate structure and records an action that matters for accountability or security. For example, a stack trace is useful for debugging but is not by itself a complete audit record. The two can coexist and may be sent to different systems.
How would you prevent sensitive information from leaking through audit logging?
I would define an allowlist of fields that are permitted in audit events rather than serializing an entire request or object. Secrets such as passwords, session tokens, and authorization credentials should be excluded or redacted. I would also review nested objects and exception data because they can unexpectedly contain sensitive values. Tests and centralized logging controls can help enforce the policy.
How would you design audit events for a distributed Java backend?
I would define a versioned, language-neutral schema with stable identifiers and a consistent timestamp convention. Each event would carry correlation or trace information so activity can be connected across services, while actor and resource identifiers preserve business context. I would separate the audit stream from ordinary diagnostic logs when retention, access control, or integrity requirements differ. Schema evolution should be backward-compatible or explicitly versioned so consumers do not break unexpectedly.