wasAsked.

Design an audit trail for sensitive changes that is useful to support teams and resistant to tampering.

Swiggy · Full Stack Developer · 3-4-years · technical

Published

Year not specified · .NET, Authentication & Security, System Design

Community answers

Posted by wasAsked editorial collection

An audit record should capture who, what, when, where, and the business correlation: actor ID, action, entity type/ID, UTC timestamp, tenant, request ID, and safe before/after values. Write it in the same transaction as the change when omission is unacceptable. Example fields: Audit(Id, RestaurantId, OutletId, ActorId, Action, EntityType, EntityId, OccurredAtUtc, CorrelationId, BeforeJson, AfterJson) Make the log append-only with tightly restricted access and tamper-evidence or immutable storage for high-risk systems. Redact secrets, tokens, payment data, and unnecessary personal data. Index tenant/time/entity queries, define retention, and distinguish audit events from diagnostic logs. Capture the authenticated actor and tenant server-side, not from request payloads.

Backbencher Developer · · 0 likes

An audit trail must answer "who changed what, when, from where and why", and it must be trustworthy. What to record - Actor (user ID, impersonator if any, service identity), timestamp in UTC, action, entity type and ID, tenant, before and after values of changed fields, request or correlation ID, IP address, user agent, and a reason when the action requires one. - Mask or omit secrets and sensitive values (passwords, full card numbers) but record that they changed. How to capture it - Write audit records in the same database transaction as the business change, so a change cannot happen without its audit entry. In EF Core, a SaveChanges interceptor can read the ChangeTracker and create audit rows automatically. - For high volume, use an outbox to ship audit events to a dedicated store (a separate database, Azure Data Explorer, or an append-only log). Tamper resistance - Make the audit store append-only: the application identity can insert but not update or delete (enforced with database permissions). - Chain records with hashes: each entry stores hash(previous hash + entry content). Any modification breaks the chain and can be detected by a verification job. - Periodically anchor the latest hash or export batches to immutable storage (Azure Blob immutability policies, S3 Object Lock / WORM). - Restrict access to audit data and audit who reads it. - Use synchronised clocks and server-side timestamps. Useful for support teams - Provide a searchable UI: filter by entity, user, time range and action, with a readable diff ("Status: Pending to Approved"). - Link entries with correlation IDs to application logs. - Define retention to meet legal requirements, and archive older data. Separate audit logs (business evidence, long retention) from technical logs (debugging, short retention); they have different consumers and rules.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics