← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
Adopt Event Sourcing over the current CRUD approach for financial transaction audit trails — using Kafka for the immutable event log and Postgres materialized views for reads — to satisfy compliance requirements while preserving full business context and user intent.
lesson_learnedevent-sourcingkafkapostgresaudit-trailcompliancecrud
Created 6/16/2026, 1:41:19 PM
Content
The team decided to move from standard CRUD in PostgreSQL to Event Sourcing for financial transaction audit trails. WHY: Updates in the current CRUD system overwrite previous states, making it impossible to provide compliance with the history of who changed what and when (e.g., transaction #8821 status change from pending to approved). ALTERNATIVES CONSIDERED: Database triggers to write to a history_logs table on every UPDATE — rejected because triggers lose business context. A trigger just sees row changes and does not know why the change happened or the user intent behind it. DECISION: Event Sourcing using Kafka to store the immutable event log with Postgres materialized views for fast reads. REFERENCE: Martin Fowler's 'Event Sourcing Pattern' article — industry standard for audit requirements. FILES: src/services/transactionService.ts (event producers), src/events/eventStore.ts (consumer/store logic).