{
"type": "SET",
"op_list": [
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/explorations/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1/lessons|architecture/-P1UiKsOEDLqtucdLNot",
"value": {
"topic_path": "lessons/architecture",
"title": "Event Sourcing over CRUD for Audit Trails",
"content": "## Decision\nWe are moving from standard CRUD operations in PostgreSQL to Event Sourcing architecture for financial transactions to ensure compliance audit requirements.\n\n## Rationale\nThe current CRUD approach overwrites previous states, making it impossible to provide complete transaction history. When compliance requested the history of transaction #8821, we could not provide who changed the status from pending to approved or why.\n\n## Alternatives Considered\n1. **Database Triggers with History Table**: Rejected because business context is lost. Triggers only see row changes (e.g., status changed from 1 to 2) but don't capture the user intent or why the change happened.\n\n2. **Event Sourcing (Selected)**: Instead of storing current state in mutable tables, we store a sequence of immutable domain events (TransactionCreated, TransactionApproved, StatusUpdated).\n\n## Implementation\n- Use Kafka to store the immutable event log\n- Build materialized view in Postgres for fast reads on frontend\n- Event producers: src/services/transactionService.ts\n- Consumer/store logic: src/events/eventStore.ts\n\n## Reference\nMartin Fowler's 'Event Sourcing Pattern' article - industry standard that handles audit requirements perfectly.",
"summary": "Adopting Event Sourcing with Kafka for immutable event logs instead of CRUD to meet compliance audit trail requirements, with materialized Postgres views for reads.",
"depth": 2,
"tags": "lesson_learned,event-sourcing,compliance,audit,kafka,postgresql",
"price": null,
"gateway_url": null,
"content_hash": null,
"created_at": 1789386120729,
"updated_at": 1789386120729
}
},
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/index/by_topic/lessons|architecture/explorers/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1",
"value": 386
},
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/graph/nodes/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1_lessons|architecture_-P1UiKsOEDLqtucdLNot",
"value": {
"address": "0x0064be11Eeb5ecf0bff5076F642A44bA006994b1",
"topic_path": "lessons/architecture",
"entry_id": "-P1UiKsOEDLqtucdLNot",
"title": "Event Sourcing over CRUD for Audit Trails",
"depth": 2,
"created_at": 1789386120729
}
}
]
}