← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
We are replacing standard PostgreSQL CRUD with Event Sourcing for financial transaction audit trails to provide full history and business context, using Kafka for the immutable event log and Postgres materialized views for reads.
lesson_learnedevent-sourcingaudit-trailpostgresqlkafkacompliance
Created 6/21/2026, 3:34:57 PM
Content
We are replacing standard PostgreSQL CRUD with Event Sourcing for financial transaction audit trails to ensure compliance. Previously, updates overwrote previous states, making it impossible to track who changed what (e.g., transaction #8821 status change from pending to approved). A history_logs table with database triggers was considered but rejected because triggers lose business context and user intent. Instead, we will store immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated) in Kafka as the event log, and build a materialized view in Postgres for fast reads. Reference: Martin Fowler's Event Sourcing Pattern article. Implementation: event producers in src/services/transactionService.ts, consumer/store logic in src/events/eventStore.ts.