Skip to content
C.W.K.
Stream
Lesson 04 of 04 · published

One Writer, Two Views

~11 min · single-writer, jsonl, sqlite, projection

Level 0Cold Vessel
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

One Writer, Two Views

Concurrency becomes tractable when one engine owns all lifecycle mutations. CLIs and UIs submit intentions; they do not append event files or edit database rows directly. The writer serializes claim, stage, review, pipeline, and landing transitions against one current state.

Append-only records and SQLite serve different jobs. The event stream is ground truth about what happened and in what order. SQLite projects current rows and relationships for fast queries. Treating both as independent writers creates reconciliation problems the workshop cannot audit from inside itself.

A mirror must be rebuildable. Start from an empty database, replay canonical events and durable declarations, and recover the same current state. This test exposes hidden state that slipped into ad hoc SQL updates without an event or canonical source.

Operationally, the mirror may lag or need repair. Health should report that condition explicitly. The safe response is rebuild or reconcile from truth, not write a compensating event that pretends the original history was different.

Query Fast, Explain Forever

Use SQLite for queue screens, counts, and joins; use the event stream when answering why a state exists. The projection optimizes reading without becoming a second authority.

A periodic rebuild test is more than disaster recovery. It is an architecture test that every meaningful mutation has one canonical representation.

One authoritative writer can support many readable projections. Commit state changes through the engine and database transaction, then emit append-only views for inspection, diffing, or backup. A projection may lag or be rebuilt; it must never become a second place that silently accepts writes.

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

Take a small event stream and rebuild an empty SQLite mirror. Compare every current field, then identify any field that cannot be derived.
Hint
A non-derivable field is hidden state or missing canonical input.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.