{
"type": "SET",
"op_list": [
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/explorations/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1/lessons|architecture/-P1Uw_wUmOc6GSA0XneF",
"value": {
"topic_path": "lessons/architecture",
"title": "Event Sourcing over CRUD for Financial Transaction Audit Trails",
"content": "Decision: Adopt Event Sourcing over CRUD for financial transaction audit trails.\n\nWhat was decided and why: Our current design uses standard CRUD in PostgreSQL, which overwrites previous states on every UPDATE. When compliance requested the history of transaction #8821, we could not provide who changed the status from pending to approved. Event Sourcing stores a sequence of immutable domain events (e.g., TransactionCreated, TransactionApproved, StatusUpdated) so the full change history is always available and auditable, satisfying compliance.\n\nImplementation plan: Use Kafka to store the immutable event log, and build a materialized view in Postgres for fast reads on the frontend.\n\nAlternatives considered and rejected:\n1. Continue with standard CRUD - rejected because updates overwrite previous states and cannot reconstruct the change history required for compliance audits.\n2. Add a history_logs table with database triggers - rejected because business context is lost. A trigger only sees row changes (e.g., status changed from 1 to 2) and does not know why the change happened or the user intent behind it.\n\nFiles/code involved: Event producers in src/services/transactionService.ts; consumer/store logic in src/events/eventStore.ts.\n\nReference: Martin Fowler's 'Event Sourcing Pattern' article, which we are following as the industry-standard reference architecture.",
"summary": "Adopt Event Sourcing over CRUD for financial transaction audit trails, using Kafka for the immutable event log and a Postgres materialized view for reads, to satisfy compliance requirements for full change history.",
"depth": 2,
"tags": "lesson_learned,event-sourcing,audit-trail,compliance,kafka,postgres,financial-transactions",
"price": null,
"gateway_url": null,
"content_hash": null,
"created_at": 1789389856543,
"updated_at": 1789389856543
}
},
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/index/by_topic/lessons|architecture/explorers/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1",
"value": 389
},
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/graph/nodes/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1_lessons|architecture_-P1Uw_wUmOc6GSA0XneF",
"value": {
"address": "0x0064be11Eeb5ecf0bff5076F642A44bA006994b1",
"topic_path": "lessons/architecture",
"entry_id": "-P1Uw_wUmOc6GSA0XneF",
"title": "Event Sourcing over CRUD for Financial Transaction Audit Trails",
"depth": 2,
"created_at": 1789389856543
}
}
]
}