본문 바로가기
C.W.K.
Stream
Lesson 04 of 04 · published

Writer 하나, View 둘

~11 min · 단일-writer, JSONL, SQLite, projection

Level 0차가운 용기
0 XP0/37 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Writer 하나, View 둘

engine 하나가 lifecycle mutation 전부를 소유하면 concurrency 를 다룰 만해져. CLI 와 UI 는 intention 을 제출하지 event file 을 append 하거나 database row 를 직접 고치지 않아. writer 가 current state 하나에 맞서 claim, stage, review, pipeline, landing transition 을 serialize 해.

append-only record 와 SQLite 는 다른 일을 해. event stream 은 무슨 일이 어떤 순서로 있었는지 ground truth 야. SQLite 는 빠른 query 용으로 current row 와 relationship 을 project 하고. 둘을 independent writer 로 취급하면 workshop 안에서 audit 할 수 없는 reconciliation 문제가 생겨.

mirror 는 rebuild 가능해야 해. 빈 database 에서 시작해 canonical event 와 durable declaration 을 replay 하고 같은 current state 를 복구해. 이 시험이 event 나 canonical source 없이 ad hoc SQL update 로 들어온 hidden state 를 드러내.

운영 중 mirror 가 lag 하거나 repair 가 필요할 수 있어. health 는 그 상태를 명시적으로 보고해야 해. 안전한 반응은 truth 에서 rebuild 또는 reconcile 하는 거지, 원래 history 가 달랐던 척하는 compensating event 를 쓰는 게 아니야.

빠르게 query 하고 영원히 설명해

queue screen, count, join 에는 SQLite 를 쓰고 왜 state 가 생겼는지 답할 때 event stream 을 써. projection 은 read 를 최적화하면서 두 번째 authority 가 되지 않아.

periodic rebuild test 는 disaster recovery 이상이야. 의미 있는 mutation 마다 canonical representation 하나가 있다는 architecture test 야.

authoritative writer 하나로도 readable projection 은 여러 개 만들 수 있어. state change 는 engine 과 database transaction 을 통해 commit 하고, inspection, diff, backup 용 append-only view 를 내보내. projection 은 늦거나 다시 만들 수 있어도 돼. 다만 몰래 write 를 받는 두 번째 authority 가 되면 안 돼.

Code

Rebuild a current-state mirror from events·python
events = [
    {"kind": "queued", "key": "a"},
    {"kind": "taken", "key": "a", "session": "s1"},
    {"kind": "landed", "key": "a", "summary": "done"},
]
mirror = {}
for event in events:
    row = mirror.setdefault(event["key"], {})
    row.update(event)
assert mirror["a"]["kind"] == "landed"
assert mirror["a"]["summary"] == "done"
print(mirror)

External links

Exercise

작은 event stream 으로 빈 SQLite mirror 를 rebuild 해. current field 를 전부 비교하고 derive 못 하는 field 를 찾아.
Hint
derive 안 되는 field 는 hidden state 이거나 빠진 canonical input 이야.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고
💛 by 피파warm

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.