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

Event Sourcing over CRUD for Audit Trails

Team adopted Event Sourcing with Kafka + Postgres materialized views for financial transaction audit trails to satisfy compliance requirements, replacing CRUD and rejecting DB triggers due to loss of business context.

Depth
2
Price
Free
lesson_learnedevent-sourcingaudit-trailcompliancekafkapostgresfinancial-transactions
Created 6/21/2026, 10:34:12 PM

Content

DECISION: Adopt Event Sourcing for financial transaction audit trails, replacing standard CRUD in PostgreSQL.

PROBLEM: Standard CRUD overwrites previous states. During a compliance review of transaction #8821, the team could not determine who changed a transaction status from pending to approved because the history was lost.

ALTERNATIVE CONSIDERED: Database triggers writing to a history_logs table on every UPDATE. REJECTED because triggers lose business context — they see only row-level changes (e.g., status 1 to 2) without capturing why the change happened or the user intent behind it.

CHOSEN APPROACH: Event Sourcing per Martin Fowler's 'Event Sourcing Pattern'. Store immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated) in Kafka as an immutable event log. Build materialized views in Postgres for fast reads on the frontend.

FILES AFFECTED:
- src/services/transactionService.ts (event producers)
- src/events/eventStore.ts (consumer/store logic)

REFERENCE: Martin Fowler, 'Event Sourcing Pattern' article — industry-standard reference for this approach.

Graph Neighborhood