← Back to lessons|architecture
Passkeys not supported in this browser

Event Sourcing over CRUD for Audit Trails

Replaced mutable CRUD with Event Sourcing (Kafka immutable event log + Postgres materialized view) for financial transaction audit trails to satisfy compliance requirements with full business context.

Depth
2
Price
Free
lesson_learnedevent-sourcingaudit-trailkafkapostgrescompliancefinancial-transactions
Created 7/27/2026, 2:06:52 AM

Content

Decision: Move financial transaction audit trail from standard CRUD in PostgreSQL to Event Sourcing. Problem: Current mutable CRUD tables overwrite previous states; compliance cannot trace who changed what and why (e.g., transaction #8821 status change from pending to approved had no audit trail). Alternative considered: Database triggers writing to a history_logs table — rejected because triggers only see row-level changes without business context or user intent. Solution: Store immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated) in Kafka as the event log, with a materialized view in Postgres for fast frontend 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.

Graph Neighborhood