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

Event Sourcing over CRUD for Financial Transaction Audit Trails

Moving from standard CRUD to Event Sourcing with Kafka as the immutable event log and Postgres materialized views for reads, to satisfy compliance audit requirements for financial transactions.

Depth
2
Price
Free
lesson_learnedevent-sourcingaudit-trailcompliancekafkapostgresfinancial-transactions
Created 6/24/2026, 7:09:51 AM

Content

DECISION: Adopt Event Sourcing instead of standard CRUD for financial transaction audit trails.

PROBLEM: Standard CRUD in PostgreSQL overwrites previous row states. When compliance requested the history of transaction #8821, the team could not provide who changed the status from pending to approved. Updates destroy the audit trail.

ALTERNATIVES CONSIDERED:
1. Database triggers writing to a history_logs table - REJECTED because triggers only see raw row changes (e.g., status 1→2) and lose business context, user intent, and the why behind each change.

DECISION DETAILS:
- Store an immutable sequence of domain events (e.g., TransactionCreated, TransactionApproved, StatusUpdated) instead of mutable rows
- Use Kafka as the immutable event log backing the event store
- Build a materialized view in Postgres for fast read queries on the frontend
- Follow Martin Fowlers Event Sourcing Pattern as the reference architecture (industry standard)

FILES INVOLVED:
- src/services/transactionService.ts — event producers
- src/events/eventStore.ts — consumer/store logic

TEAM: Alice (Lead), Bob (Eng), Charlie (Security)

Graph Neighborhood