Architecture
Storage: RocksDB per vnode
Each object's data lives in an embedded RocksDB instance — in-process, no network hop.
All keys for one object share a prefix — rehydration is a single prefix scan, not a scatter-gather.
| Operation | Mechanism | Latency |
|---|---|---|
| Read (hot) | In-memory map | ~0 ns |
| Read (cold) | RocksDB bloom filter + memtable | ~10 µs |
| Write | Memtable + WAL append | ~50 µs |
| Rehydrate (snapshot) | Single key read | ~10 µs |
| Log replay | Sequential prefix scan | ~1 µs/entry |
DurableObject Worker lifecycle
The Worker serialises all writes — no per-slot locking needed. RocksDB data persists on the vnode regardless of Worker state.
Write path
Every write, Chat token streaming included, goes through this one transaction path. The state snapshot is rewritten only when a commit crosses a multiple of 32 log ids; on crash + rehydrate, the snapshot plus the log entries after it rebuild the state exactly.
Distribution: riak_core_lite ring
Routing: partition = SHA-160(app_id <> "/" <> type <> "/" <> key) % 256 — pure arithmetic, ~500ns, no network call.
Handoff: when nodes join/leave, the vnode's RocksDB key range streams to the new owner. Object state migrates with the partition.
Cold reads: served directly by the vnode from RocksDB — no Worker started, memory proportional to active objects only.
Replication quorum
The replication factor adapts to the number of active cluster nodes:
| Active nodes | N | R | W |
|---|---|---|---|
| 1 | 1 | 1 | 1 |
| 2 | 2 | 2 | 2 |
| 3 or more | 3 | 2 | 2 |
A write coordinator takes a cluster-wide advisory lock, does a quorum read to
pick the canonical snapshot (highest log_id present on ≥R replicas,
read-repairing stale ones), evaluates the operation once, then writes to W
replicas with a per-replica version check. The W=2 intersection plus the
version check are what stop two conflicting writes both succeeding during a
partition — the advisory lock is best-effort, not consensus.
Real-time subscribe flow
Supervision tree
Workers are :temporary — not restarted on crash. Next access rehydrates from RocksDB. A crashed Worker is equivalent to an evicted one.