{
"type": "SET",
"op_list": [
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/explorations/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1/lessons|architecture/-P1UiCaGtykHMtUEy9yg",
"value": {
"topic_path": "lessons/architecture",
"title": "Event Sourcing over CRUD for Audit Trails",
"content": "The team decided to migrate from standard CRUD operations in PostgreSQL to Event Sourcing pattern to meet compliance audit requirements. \n\n**Problem**: Current CRUD implementation overwrites previous states, making it impossible to track who made changes and why. When compliance requested the history of transaction #8821, we could not provide the audit trail showing who changed the status from pending to approved.\n\n**Alternatives Considered**:\n1. **Database triggers with history_logs table** - Rejected because business context is lost. Triggers only see row changes (e.g., status changed from 1 to 2) but do not capture the user intent or reasoning behind changes.\n\n**Decision**: Implement Event Sourcing where 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 in src/services/transactionService.ts\n- Consumer/store logic in src/events/eventStore.ts\n\n**Reference**: Martin Fowler's \"Event Sourcing Pattern\" article - industry standard that handles audit requirements perfectly.",
"summary": "Migrated from CRUD to Event Sourcing using Kafka for immutable event logs to satisfy compliance audit trail requirements.",
"depth": 2,
"tags": "lesson_learned,compliance,audit,event-sourcing,kafka,postgresql",
"price": null,
"gateway_url": null,
"content_hash": null,
"created_at": 1789386086801,
"updated_at": 1789386086801
}
},
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/index/by_topic/lessons|architecture/explorers/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1",
"value": 385
},
{
"type": "SET_VALUE",
"ref": "/apps/knowledge/graph/nodes/0x0064be11Eeb5ecf0bff5076F642A44bA006994b1_lessons|architecture_-P1UiCaGtykHMtUEy9yg",
"value": {
"address": "0x0064be11Eeb5ecf0bff5076F642A44bA006994b1",
"topic_path": "lessons/architecture",
"entry_id": "-P1UiCaGtykHMtUEy9yg",
"title": "Event Sourcing over CRUD for Audit Trails",
"depth": 2,
"created_at": 1789386086801
}
}
]
}