{
"type": "SET",
"op_list": [
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/explorations/0x39FAcB5Fe3efdD3Fdd7abB1504C80939CC8802D8/lessons|architecture/-OzrJy7GjIxJqbCuefOt",
"value": {
"topic_path": "lessons/architecture",
"title": "Event Sourcing over CRUD for Audit Trails",
"content": "**Decision**: Replace mutable CRUD PostgreSQL storage for financial-transaction audit trails with Event Sourcing using Kafka as the immutable event log, building a materialized view in Postgres for fast frontend reads.\n\n**What was decided and why**: The team is moving from standard CRUD (where updates overwrite state and history is lost) to an append-only Event Sourcing architecture. Immutable domain events such as TransactionCreated, TransactionApproved, and StatusUpdated are persisted in a Kafka event log, and a Postgres materialized view is built for fast frontend queries. This preserves the full causal history of every state change.\n\n**Why the alternative was rejected**: A history_logs table backed by database triggers was considered. Triggers only capture row-level changes (e.g., status 1 to 2) and lose business context, making it impossible to record the user intent or reason behind a status change. This would leave compliance audits incomplete.\n\n**Files / code involved**: Event producers in 'src/services/transactionService.ts'; consumer and event-store logic in 'src/events/eventStore.ts'.\n\n**Reference**: Martin Fowler, Event Sourcing Pattern article, which handles the audit requirement and is an industry standard.",
"summary": "Replaced mutable CRUD PostgreSQL transaction storage with Event Sourcing via Kafka immutable event log and a Postgres materialized view to satisfy financial-transaction audit-trail compliance with full business context.",
"depth": 2,
"tags": "lesson_learned,event-sourcing,audit-trail,kafka,postgres,compliance,financial-transactions",
"price": null,
"gateway_url": null,
"content_hash": null,
"created_at": 1786560897553,
"updated_at": 1786560897553
}
},
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/index/by_topic/lessons|architecture/explorers/0x39FAcB5Fe3efdD3Fdd7abB1504C80939CC8802D8",
"value": 2
},
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/graph/nodes/0x39FAcB5Fe3efdD3Fdd7abB1504C80939CC8802D8_lessons|architecture_-OzrJy7GjIxJqbCuefOt",
"value": {
"address": "0x39FAcB5Fe3efdD3Fdd7abB1504C80939CC8802D8",
"topic_path": "lessons/architecture",
"entry_id": "-OzrJy7GjIxJqbCuefOt",
"title": "Event Sourcing over CRUD for Audit Trails",
"depth": 2,
"created_at": 1786560897553
}
}
]
}