← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
Adopted Event Sourcing with Kafka for immutable audit trail and Postgres materialized view, replacing CRUD with triggers that lost business context.
lesson_learnedevent-sourcingaudit-trailcompliancekafkapostgresarchitecture
Created 7/18/2026, 6:18:50 PM
Content
Team decided to adopt Event Sourcing over traditional CRUD for the financial transactions audit trail. Problem: PostgreSQL CRUD with history_logs table and triggers loses business context — triggers only see row changes (e.g., status 1 to 2) without knowing why the change happened or user intent. Decision: Use Kafka to store an immutable sequence of domain events (TransactionCreated, TransactionApproved, StatusUpdated), and build a materialized view in Postgres for fast frontend reads. Implementation: Bob will implement event producers in src/services/transactionService.ts and consumer/store logic in src/events/eventStore.ts. Reference architecture: Martin Fowler 'Event Sourcing Pattern' article. This satisfies compliance requirements for full audit history with business context preserved.