← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
Moved financial transaction audit trail from CRUD to Event Sourcing using Kafka for immutable event storage and Postgres materialized views, satisfying compliance with full change history.
lesson_learnedevent-sourcingaudit-trailcrudkafkapostgrescompliancemartin-fowler
Created 7/26/2026, 12:31:32 PM
Content
The team decided to move from standard CRUD in PostgreSQL to Event Sourcing for financial transaction audit trails. CRUD updates overwrite previous states, making it impossible to provide compliance history (e.g., who changed transaction #8821 from pending to approved). Database triggers were considered but rejected because they lose business context — they see row changes but not why the change happened or user intent. Event Sourcing stores immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated) instead of mutable state. Kafka will store the immutable event log, with a materialized view in Postgres for fast reads. This follows Martin Fowler Event Sourcing Pattern article. Implementation: event producers in src/services/transactionService.ts, consumer/store logic in src/events/eventStore.ts.