docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
---
|
||||
id: wiki-2026-0508-event-sourcing-pattern
|
||||
title: Event Sourcing Pattern
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [event sourcing, ES, append-only, event store, projection, snapshot]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [architecture, event-sourcing, cqrs, domain-driven-design, audit, kafka]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: TypeScript / Java
|
||||
framework: EventStoreDB / Kafka / Axon
|
||||
---
|
||||
|
||||
# Event Sourcing
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 state 의 store 의 X — 매 event 의 sequence 의 store"**. 매 current state = 매 replay 의 result. 매 audit + 매 temporal query + 매 CQRS 의 partner. 매 modern: 매 Kafka, EventStoreDB, Axon.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 vs CRUD
|
||||
- **CRUD**: 매 row 의 update.
|
||||
- **ES**: 매 immutable event 의 append.
|
||||
- **Projection**: 매 event → 매 read model.
|
||||
|
||||
### 매 component
|
||||
- **Event store**: 매 append-only.
|
||||
- **Aggregate**: 매 command → events.
|
||||
- **Projection / read model**: 매 query.
|
||||
- **Snapshot**: 매 replay 최적화.
|
||||
- **Outbox**: 매 publish reliability.
|
||||
|
||||
### 매 응용
|
||||
1. **Banking**: 매 audit.
|
||||
2. **E-commerce**: 매 order lifecycle.
|
||||
3. **Compliance**: 매 immutable history.
|
||||
4. **Collaboration**: 매 Figma.
|
||||
5. **Game state**: 매 replay.
|
||||
|
||||
### 매 trade-off
|
||||
- ✅ Audit, replay, temporal query, decouple.
|
||||
- ❌ Complexity, eventual consistency, schema evolution.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Event store (TypeScript)
|
||||
```typescript
|
||||
type DomainEvent = { aggregateId: string; type: string; payload: object; version: number; timestamp: Date };
|
||||
|
||||
class EventStore {
|
||||
private events: DomainEvent[] = [];
|
||||
|
||||
append(event: DomainEvent) {
|
||||
const last = this.events.filter(e => e.aggregateId === event.aggregateId).pop();
|
||||
const expectedVersion = (last?.version ?? 0) + 1;
|
||||
if (event.version !== expectedVersion) throw new Error('Concurrency conflict');
|
||||
this.events.push(event);
|
||||
}
|
||||
|
||||
load(aggregateId: string): DomainEvent[] {
|
||||
return this.events.filter(e => e.aggregateId === aggregateId);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Aggregate (replay)
|
||||
```typescript
|
||||
class Order {
|
||||
state = { id: '', status: 'NEW', items: [] as any[], version: 0 };
|
||||
|
||||
static fromHistory(events: DomainEvent[]): Order {
|
||||
const o = new Order();
|
||||
events.forEach(e => o.apply(e));
|
||||
return o;
|
||||
}
|
||||
|
||||
apply(event: DomainEvent) {
|
||||
switch (event.type) {
|
||||
case 'OrderCreated': this.state.id = event.payload.id; break;
|
||||
case 'ItemAdded': this.state.items.push(event.payload); break;
|
||||
case 'OrderPlaced': this.state.status = 'PLACED'; break;
|
||||
}
|
||||
this.state.version = event.version;
|
||||
}
|
||||
|
||||
addItem(item: any): DomainEvent {
|
||||
if (this.state.status !== 'NEW') throw new Error('Cannot modify');
|
||||
const event = { aggregateId: this.state.id, type: 'ItemAdded', payload: item, version: this.state.version + 1, timestamp: new Date() };
|
||||
this.apply(event);
|
||||
return event;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Projection
|
||||
```typescript
|
||||
class OrderListProjection {
|
||||
private orders = new Map<string, any>();
|
||||
|
||||
handle(event: DomainEvent) {
|
||||
switch (event.type) {
|
||||
case 'OrderCreated':
|
||||
this.orders.set(event.aggregateId, { id: event.aggregateId, status: 'NEW', total: 0 });
|
||||
break;
|
||||
case 'ItemAdded':
|
||||
const o = this.orders.get(event.aggregateId);
|
||||
if (o) o.total += event.payload.price;
|
||||
break;
|
||||
case 'OrderPlaced':
|
||||
this.orders.get(event.aggregateId).status = 'PLACED';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
query() { return Array.from(this.orders.values()); }
|
||||
}
|
||||
```
|
||||
|
||||
### Snapshot
|
||||
```typescript
|
||||
class SnapshotStore {
|
||||
async save(agg: any, version: number) {
|
||||
await db.snapshots.put({ aggregateId: agg.id, snapshot: agg.state, version });
|
||||
}
|
||||
|
||||
async loadOrReplay(aggId: string, eventStore: EventStore): Promise<Order> {
|
||||
const snap = await db.snapshots.get(aggId);
|
||||
const o = new Order();
|
||||
if (snap) o.state = snap.snapshot;
|
||||
const events = eventStore.load(aggId).filter(e => e.version > (snap?.version ?? 0));
|
||||
events.forEach(e => o.apply(e));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Kafka publish (outbox)
|
||||
```typescript
|
||||
async function placeOrder(orderId: string) {
|
||||
await db.transaction(async tx => {
|
||||
const events = order.place();
|
||||
await tx.events.append(events);
|
||||
await tx.outbox.insert(events.map(e => ({ topic: 'orders', payload: e })));
|
||||
});
|
||||
}
|
||||
// 매 outbox poller → Kafka
|
||||
```
|
||||
|
||||
### Schema evolution
|
||||
```typescript
|
||||
function upgradeEvent(e: any) {
|
||||
if (e.type === 'OrderPlacedV1') {
|
||||
return { ...e, type: 'OrderPlaced', payload: { ...e.payload, currency: 'USD' } };
|
||||
}
|
||||
return e;
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Audit-critical | ES + projection |
|
||||
| CRUD simple | Stay CRUD |
|
||||
| Temporal query | ES |
|
||||
| Collaboration | ES + CRDT |
|
||||
| Distributed system | ES + Kafka outbox |
|
||||
| Compliance | ES + immutable store |
|
||||
|
||||
**기본값**: 매 high-stakes domain = ES + CQRS + outbox + snapshot. 매 simple = CRUD.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Architecture]] · [[Domain-Driven-Design]]
|
||||
- 변형: [[CQRS]]
|
||||
- 응용: [[Kafka]]
|
||||
- Adjacent: [[Event-Driven-Architecture]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 audit. 매 temporal. 매 collaboration.
|
||||
**언제 X**: 매 simple CRUD.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No snapshot**: 매 replay slow.
|
||||
- **No version check**: 매 concurrency conflict.
|
||||
- **Mutate event**: 매 ES violation.
|
||||
- **No upgrade path**: 매 schema break.
|
||||
- **Synchronous projection**: 매 latency.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Fowler ES, Greg Young, Vernon DDD).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-04-20 | Auto-reinforced |
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — ES + 매 store / aggregate / projection / snapshot / outbox code |
|
||||
Reference in New Issue
Block a user