← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
Adopted Event Sourcing over CRUD with Kafka for immutable audit trails in financial transactions to satisfy compliance requirements, using materialized views in Postgres for reads.
lesson_learnedevent-sourcingaudit-trailcompliancekafkapostgresmaterialized-views
Created 7/30/2026, 12:27:49 AM
Content
The team decided to replace standard CRUD operations in PostgreSQL with Event Sourcing for financial transaction audit trails. Instead of mutable state tables that overwrite previous values, the system will store immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated) via Kafka as the event log, with materialized views in Postgres for fast reads. This was chosen because: (1) Standard CRUD overwrites previous states, losing the ability to provide compliance history (e.g., who changed transaction #8821 from pending to approved). (2) The alternative of adding a history_logs table with database triggers was rejected because triggers only see row-level changes and lose business context — they don't capture why a change happened or the user's intent. Implementation files: src/services/transactionService.ts (event producers) and src/events/eventStore.ts (consumer/store logic). The decision is informed by Martin Fowler's 'Event Sourcing Pattern' article.