How do you track who changed what across multiple microservices?
While working on a microservices platform, I implemented centralized audit logging to make business actions easier to trace and investigate.
Here’s the implementation, step by step:
1 Define a consistent audit event
Each service captures structured information about an action: the actor, source service, event type, affected resource, outcome, and relevant request context.
A shared format makes events easier to understand across service boundaries.
2 Create a reusable Spring Boot client
A shared audit logging library provides a consistent interface for administrative actions, business events, errors, and application logs.
Services inject an AuditLogger and publish events without duplicating Kafka integration code.
3 Capture events at the business operation
Audit calls sit alongside meaningful operations such as creating, updating, submitting, approving, or rejecting a record.
Where transaction-aware publishing is implemented, events are sent after the database transaction commits, helping avoid reporting changes that were rolled back.
4 Publish asynchronously through Kafka
The client serializes the event and delegates Kafka publishing to a background thread.
This keeps broker communication off the business request thread and separates event production from centralized processing.
5 Normalize and sanitize centrally
A dedicated audit log microservice consumes Kafka events, converts supported payloads into a standard format, and applies sensitive-data redaction before storage.
Centralizing this processing gives services a consistent audit pipeline.
6 Use storage according to purpose
Processed events are written to rotated log files. Events that meet the audit persistence policy are also stored in PostgreSQL.
Routine reads and application logs remain file-only, while qualifying changes and authentication events become searchable audit records.
7 Make investigations practical
The audit interface supports searching and filtering by actor, category, status, date range, and affected record.
Request and trace identifiers, when available, help connect related activity across services.
One important engineering tradeoff: asynchronous publishing improves request isolation, but the current client uses best-effort delivery. Guaranteed delivery would require additional mechanisms, such as a transactional outbox and durable retries.
The biggest lesson for me: useful audit logging starts with meaningful business events, consistent context, and clear delivery guarantees.

Join the discussion
Ask a question or share what you learned. Comments are reviewed before appearing.