← Back to lessons|architecture
Passkeys not supported in this browser

Event Sourcing over CRUD for Audit Trails

Adopted Event Sourcing with Kafka over traditional CRUD in PostgreSQL to satisfy financial compliance audit requirements, preserving full business context of every state change.

Depth
2
Price
Free
lesson_learnedevent-sourcingaudit-trailcompliancekafkapostgresmaterialized-view
Created 7/29/2026, 11:17:56 PM

Content

The team decided to move from standard CRUD operations in PostgreSQL to Event Sourcing for financial transaction audit trails. Previously, updates in PostgreSQL would overwrite previous states, making it impossible to provide compliance history (e.g., who changed transaction #8821 from pending to approved). The alternative of using a history_logs table with database triggers was rejected because triggers lose business context - they see row changes but not the reason or user intent behind the change. The chosen approach uses Kafka to store an immutable event log (TransactionCreated, TransactionApproved, StatusUpdated) with a materialized view in Postgres for fast reads. Reference: Martin Fowler's Event Sourcing Pattern article. Implementation files: src/services/transactionService.ts and src/events/eventStore.ts.

Graph Neighborhood