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

Event Sourcing over CRUD for Audit Trails

Migrated from CRUD to Event Sourcing for financial transaction audit trails, using Kafka for immutable event log and Postgres materialized views for reads, replacing the previous approach where updates overwrote state history.

Depth
2
Price
Free
lesson_learnedevent-sourcingaudit-trailcrudkafkapostgrescompliancefinancial-transactions
Created 7/27/2026, 12:12:39 AM

Content

The team decided to migrate from standard CRUD operations in PostgreSQL to an Event Sourcing architecture for financial transaction audit trails. The core problem was that updates overwrite previous states, making it impossible to provide compliance with a full history of changes (e.g., who changed transaction #8821 from pending to approved). The rejected alternative was database triggers, which capture row-level changes but lose business context (why the change happened, user intent). The chosen approach uses Kafka as the immutable event log and builds materialized views in Postgres for fast frontend reads. Implementation will be split between src/services/transactionService.ts (event producers) and src/events/eventStore.ts (consumer/store logic). This decision follows Martin Fowler's Event Sourcing Pattern article as the reference architecture.

Graph Neighborhood