← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
Team chose Event Sourcing over CRUD with database triggers for financial transaction audit trails. Kafka immutable event log with Postgres materialized views, replacing standard PostgreSQL CRUD to satisfy compliance audit requirements.
lesson_learnedevent-sourcingaudit-trailcompliancekafkapostgresql
Created 6/16/2026, 10:35:28 PM
Content
DECIDED: The team chose Event Sourcing over standard CRUD with database triggers for financial transaction audit trails. Instead of storing mutable state in PostgreSQL, we will store a sequence of immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated). Kafka will serve as the immutable event log, with materialized views in Postgres for fast frontend reads. ALTERNATIVE CONSIDERED: Database triggers with a history_logs table were considered, but rejected because triggers only see row-level changes (e.g., status changed from 1 to 2) and lose business context — they don't capture why the change happened or the user intent behind it. FILES: src/services/transactionService.ts (event producers), src/events/eventStore.ts (consumer/store logic). REFERENCE: Martin Fowler's Event Sourcing Pattern article — industry-standard reference architecture for this approach.