← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
Team decided to implement Event Sourcing using Kafka as the immutable event log with a Postgres materialized view for reads, replacing the current PostgreSQL CRUD approach that loses audit history and cannot satisfy compliance requirements.
lesson_learnedevent-sourcingkafkaaudit-trailpostgresqlcompliancefinancial-transactions
Created 6/20/2026, 10:33:07 PM
Content
Decision to move from standard CRUD in PostgreSQL to Event Sourcing for financial transaction audit compliance. The current CRUD approach overwrites previous states on update, making it impossible to provide audit history (e.g., who changed a transaction status from pending to approved). Alternative considered: adding a history_logs table with database triggers on UPDATE - rejected because triggers only see row-level changes (e.g., status changed from 1 to 2) and lose business context and user intent. Final decision: use Kafka to store an immutable event log (e.g., TransactionCreated, TransactionApproved, StatusUpdated), and build a materialized view in Postgres for fast reads on the frontend. Implementation: event producers in src/services/transactionService.ts, consumer/store logic in src/events/eventStore.ts. Reference: Martin Fowler's Event Sourcing Pattern article.