# Topic config: cleanup.policy=compact# Same key keeps only latest value → materialize current state
kafka-configs.sh --alter --entity-type topics --entity-name user-profiles \
--add-config cleanup.policy=compact,min.cleanable.dirty.ratio=0.1
Hash-chained audit log
importhashlib,jsondefappend(prev_hash:str,event:dict)->tuple[str,dict]:record={"prev":prev_hash,"event":event,"ts":time.time()}h=hashlib.sha256(json.dumps(record,sort_keys=True).encode()).hexdigest()returnh,{**record,"hash":h}# Tamper-evident: any modification breaks chain
Postgres logical replication slot
SELECTpg_create_logical_replication_slot('app_slot','pgoutput');-- Stream WAL changes to consumer (CDC)
SELECT*FROMpg_logical_slot_get_changes('app_slot',NULL,NULL);
언제: 매 audit/replay 요구, 매 multiple consumer/projection, 매 temporal queries, 매 reliable event publishing.
언제 X: 매 simple CRUD without history, 매 strong consistency snapshot only, 매 storage cost-sensitive (logs grow).
❌ 안티패턴
Mutating past events: 매 invariant violation. 매 compensating event 의 emit.
Unbounded retention without compaction: 매 storage explosion.
Synchronous replay on every read: 매 latency. 매 snapshot + tail.
Single-partition Kafka topic: 매 throughput cap. 매 partition by key.
🧪 검증 / 중복
Verified (Jay Kreps "The Log" 2013, Kafka docs, Postgres WAL docs, Greg Young event sourcing).
신뢰도 A.
🕓 Changelog
날짜
변경
2026-05-08
Phase 1
2026-05-10
Manual cleanup — full content (Kafka, event sourcing, WAL, outbox)