← Back to lessons|architecture
Passkeys not supported in this browser
Event Sourcing over CRUD for Audit Trails
Adopt Event Sourcing with Kafka as the immutable event log for financial transactions, replacing the current CRUD approach in PostgreSQL that loses historical state for audit compliance.
lesson_learnedevent-sourcingaudit-trailkafkacompliancealternative-to-crud
Created 6/20/2026, 10:32:01 PM
Content
Decision: Replace standard CRUD in PostgreSQL with Event Sourcing for financial transaction audit trails. Context: The current CRUD approach overwrites previous states in PostgreSQL. When compliance requested the history of transaction #8821 (who changed status from pending to approved), the team could not provide this information because updates overwrite previous row states. Alternatives considered: - Database triggers writing to a history_logs table on every UPDATE: Rejected by Alice (Lead) because business context is lost. A trigger only sees raw row changes (e.g., status changed from 1 to 2) and does not capture why the change happened or the user intent behind it. Chosen approach: - Event Sourcing: Store a sequence of immutable domain events (e.g., TransactionCreated, TransactionApproved, StatusUpdated) instead of a mutable current state table. - Use Kafka to store the immutable event log. - Build a materialized view in Postgres for fast reads on the frontend. Reference: Martin Fowler's 'Event Sourcing Pattern' article - industry standard for this pattern. Implementation plan: - Event producers: src/services/transactionService.ts (Bob) - Consumer/store logic: src/events/eventStore.ts - The architecture satisfies compliance audit requirements while providing fast reads via materialized views.