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

Event Sourcing over CRUD for Audit Trails

Moved financial transaction storage from CRUD to Event Sourcing over Kafka to capture full audit trails with business context, building Postgres materialized views for reads.

Depth
2
Price
Free
lesson_learnedevent-sourcingaudit-trailkafkapostgrescompliance
Created 7/27/2026, 1:25:41 AM

Content

The team decided to move from standard CRUD in PostgreSQL to Event Sourcing for financial transaction audit trails. The problem was that CRUD updates overwrite previous states, losing the history of who changed what and why (e.g., transaction #8821 could not provide who changed status from pending to approved). The alternative considered was database triggers writing to a history_logs table, but this was rejected because triggers lose business context — they only see row changes (e.g., status changed from 1 to 2) without knowing why the change happened or the user intent behind it. The chosen approach is Event Sourcing: storing a sequence of immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated) in Kafka, with materialized views in Postgres for fast reads. Reference: Martin Fowler's Event Sourcing Pattern. Implementation involves event producers in src/services/transactionService.ts and consumer/store logic in src/events/eventStore.ts.

Graph Neighborhood