← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
Adopted Event Sourcing over CRUD for financial transaction audit trails, using Kafka for immutable event storage and Postgres materialized views for reads, because CRUD overwrites state and database triggers lose business context required by compliance.
lesson_learnedevent-sourcingaudit-trailcrudkafkapostgrescompliance
Created 7/26/2026, 5:06:06 PM
Content
The team decided to replace standard CRUD operations in PostgreSQL with Event Sourcing for financial transaction audit trails. The current CRUD approach overwrites previous states, making it impossible to provide compliance officers with a history of who changed transaction #8821 status from pending to approved. Database triggers were considered as an alternative (adding a history_logs table) but rejected because triggers only capture row-level changes (status values) and lose business context such as why the change happened or the user intent. The chosen approach stores immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated) in Kafka, with materialized views in Postgres for fast frontend reads. This follows Martin Fowler's Event Sourcing Pattern article. Implementation will involve event producers in src/services/transactionService.ts and consumer/store logic in src/events/eventStore.ts.