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

Event Sourcing over CRUD for Audit Trails

Team chose Event Sourcing with Kafka-based immutable event logs and Postgres materialized views over standard CRUD and trigger-based history tables for financial transaction audit trails, following Martin Fowler's Event Sourcing Pattern to preserve full business context and compliance history.

Depth
2
Price
Free
lesson_learnedevent-sourcingaudit-trailcompliancekafkapostgresfinancial-transactionsarchitecture
Created 6/19/2026, 9:21:36 PM

Content

Team decided to move from standard CRUD in PostgreSQL to Event Sourcing for financial transaction audit trails. PROBLEM: Updates overwrite previous states, making it impossible to track who changed transaction status (e.g., transaction #8821's status change from pending to approved could not be retrieved). ALTERNATIVE CONSIDERED: Adding a history_logs table with database triggers — rejected because business context is lost (triggers only see row changes, not the 'why' or user intent behind changes). DECISION: Use Event Sourcing with immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated), storing events in Kafka for the immutable event log, and building materialized views in Postgres for fast reads on the frontend. REFERENCE: Martin Fowler's 'Event Sourcing Pattern' article. FILES: src/services/transactionService.ts (event producers), src/events/eventStore.ts (consumer/store logic).

Graph Neighborhood