| 1 | # Testing |
| 2 | |
| 3 | celld makes three promises: |
| 4 | |
| 5 | - An acknowledged write is durable. |
| 6 | - A cell has one writer at a time. |
| 7 | - Code written for Cloudflare Workers and Durable Objects operates the |
| 8 | same on celld. |
| 9 | |
| 10 | We try to break each promise at the layer where a failure shows most |
| 11 | clearly. We test the API contract with differential execution against the |
| 12 | Cloudflare runtime. We check the coordination protocol against an |
| 13 | exhaustively model-checked specification, and we test it with |
| 14 | deterministic simulation. We test the full system with fault injection |
| 15 | on live fleets. |
| 16 | |
| 17 | ## Conformance: two runtimes, one output |
| 18 | |
| 19 | We run the same Workers and Durable Objects program on both workerd, |
| 20 | Cloudflare's production runtime, and celld. The two outputs must match, |
| 21 | so each test checks celld against the Cloudflare runtime. |
| 22 | The reference output comes from workerd, so the expected behavior does |
| 23 | not depend on the celld implementation. |
| 24 | |
| 25 | We expand the corpus with fixtures for each new API, and each fixture must |
| 26 | give the same output on both engines. We also port test suites from workerd: |
| 27 | the Durable Objects contract, the web-platform globals, and the upstream |
| 28 | Web Platform Tests. Before a release, we replay storage, SQL, alarm, |
| 29 | stream, WebSocket, and lifecycle scenarios through the full `celld` binary |
| 30 | in each deployment mode. |
| 31 | |
| 32 | ## Specification: exhaustive at small size |
| 33 | |
| 34 | The coordination protocol is also specified in TLA+. Heyang Zhou wrote |
| 35 | the specifications against celld v0.1.0, and his model checking found |
| 36 | four bugs and a split-brain that lost an acknowledged write. All are |
| 37 | fixed. None had surfaced in our own review or testing. |
| 38 | |
| 39 | Where simulation samples schedules, the checker enumerates them: at a |
| 40 | small configuration it visits every reachable state. The model grants |
| 41 | the implementation a linearizable object store and perfect shared |
| 42 | clocks, so a violation it finds needs no clock skew and no storage |
| 43 | anomaly to occur. The invariants are the first two promises at the top |
| 44 | of this page: one writer for each epoch, and no acknowledged write |
| 45 | lost. The checker also verifies that the epoch in the key prevents a stale |
| 46 | owner's late writes from causing the loss of an acknowledged write. |
| 47 | |
| 48 | Every configuration carries a pinned expected verdict, and most of the |
| 49 | verdicts are failures: each failing configuration models a bug the |
| 50 | protocol once had, or a deliberately broken checker, and the model |
| 51 | must produce the counterexample. If a configuration stops producing its |
| 52 | expected failure, we investigate and repair the check. |
| 53 | |
| 54 | Some specifications model a proposed protocol before it is built. When |
| 55 | the fence on write acknowledgments was redesigned, the design-stage |
| 56 | check produced an eight-state counterexample against the version it |
| 57 | replaced: a dormant cell resumes at its old epoch while its release is |
| 58 | in flight, acknowledges a write, and the takeover that follows |
| 59 | restores without it. The fix shipped; the counterexample stays as a |
| 60 | pinned failure. |
| 61 | |
| 62 | The checker has also removed code: celld once sealed a cell's durable |
| 63 | history at restore, and the verdicts showed the seal defended only the |
| 64 | return of an unacknowledged write, which celld does not promise to prevent. |
| 65 | The seal could also turn a recoverable ordering error into permanent data |
| 66 | loss, so celld no longer uses it. |
| 67 | |
| 68 | We update the specifications manually alongside the protocol changes. |
| 69 | They do not run in continuous integration, because an outdated model can |
| 70 | give false confidence. A separate record tracks what the model does not |
| 71 | yet describe, including guarantees weaker than those in the code. |
| 72 | Simulation checks each commit, and model checking adds exhaustive coverage |
| 73 | of small configurations. |
| 74 | |
| 75 | ## Simulation: the protocol under adversarial schedules |
| 76 | |
| 77 | The dangerous bugs live in the coordination: a crash during an ownership |
| 78 | handoff, a lease renewal that races a takeover, an alarm that fires |
| 79 | against a partially restored cell. These windows are nanoseconds wide and |
| 80 | open rarely, so a test cannot wait for them. |
| 81 | |
| 82 | Thus the coordination protocol is a |
| 83 | [pure decision core](https://github.com/denoland/celld/tree/main/crates/logic) |
| 84 | with no I/O of its own: the clock, the randomness, and the object store |
| 85 | are interfaces, and a simulator drives the core. The simulated store |
| 86 | injects latency, compare-and-swap races, and lost responses; the clocks |
| 87 | drift apart; a node can crash at each await point. Scripted adversaries |
| 88 | play the cells: a handler that never returns, a write stream that stops |
| 89 | halfway. V8 stays out of the simulation, because V8 is not deterministic. |
| 90 | |
| 91 | A seeded scheduler drives each run, so we can reproduce a failure exactly |
| 92 | and keep its seed until we fix the bug. We check safety properties for |
| 93 | two writers in one epoch, a lost acknowledged write, and an expired lease |
| 94 | that returns. We also check liveness: each armed alarm fires, and ownership |
| 95 | settles on one node after a crash. A property must survive tens of thousands |
| 96 | of seeds, and the core protocols have run through millions of different |
| 97 | schedules. |
| 98 | |
| 99 | We also run deliberately broken variants of the protocol to verify that |
| 100 | the checkers detect the faults. A checker that accepts a broken protocol |
| 101 | cannot protect the corresponding property. |
| 102 | |
| 103 | ## Live fleets: what simulation cannot see |
| 104 | |
| 105 | Simulation cannot see the real S3 tail latency, the real kernel and |
| 106 | filesystem behavior, or V8 under memory pressure. The third layer is |
| 107 | therefore a permanent fleet lab: standard VMs from standard providers, |
| 108 | and a real bucket. The workloads rotate: chat rooms under many WebSocket |
| 109 | connections, working sets that shift across tens of thousands of cells |
| 110 | (each cell has a unique checksum), deployment cutovers under load, and |
| 111 | runs that fill the nodes to the memory limit. The lab qualifies each |
| 112 | release and tests greater density and more faults between releases. We |
| 113 | archive each run's configuration, verification sweeps, node journals, |
| 114 | kernel logs, and phase timings. We preserve failed runs as well as |
| 115 | successful ones, because both provide evidence of the system's behavior. |
| 116 | |
| 117 | We inject the faults between verification passes. A pass fetches each |
| 118 | cell through different nodes and compares the durable state exactly: the |
| 119 | status, the body, and the full message ledger. Each run therefore records |
| 120 | the state before and after the fault. A cell can be unavailable for a short |
| 121 | time while its ownership moves, but its committed state must |
| 122 | stay complete, and a live node must serve that state again. |
| 123 | |
| 124 | The scenarios attack every seam that we know: |
| 125 | |
| 126 | - Stop a node with `SIGKILL` in the middle of a write stream and delete |
| 127 | its local database, so recovery can only come from the bucket. Every |
| 128 | acknowledged write comes back, because the output gate held each |
| 129 | response until the write was durable. |
| 130 | - Freeze an owner node, write to its cells through other nodes, and |
| 131 | unfreeze it. The node sees that its lease moved and refuses to serve |
| 132 | the old state, and each write from the other nodes lands exactly one |
| 133 | time: one epoch has at most one writer. |
| 134 | - Cut a node off from the bucket. It fences itself, because a node that |
| 135 | cannot replicate must not own cells. |
| 136 | - Throttle the bucket, so it answers each request with a 429. The engine |
| 137 | slows to the write rate of the store and does not amplify the |
| 138 | throttle, because a node that knows its replicated position does not |
| 139 | ask a slow store for extra listings. |
| 140 | - Stop a full host at the provider level in the middle of a workload. |
| 141 | Its cells move to the other nodes, and the returning host joins again |
| 142 | with no duplicate residency. |
| 143 | |
| 144 | Across every run of every scenario, no acknowledged write was lost and |
| 145 | no committed state was damaged; the verification sweeps show zero body |
| 146 | faults, zero status faults, and zero lost messages. |
| 147 | |
| 148 | ## A few numbers we trust |
| 149 | |
| 150 | Each number includes its measurement conditions, so you can assess whether |
| 151 | it applies to your workload. |
| 152 | |
| 153 | - **The epoch fence holds under contention.** Five hundred claimants |
| 154 | tried at the same time to own the same cells: 5,500 attempts, one |
| 155 | writer for each epoch, zero violations. |
| 156 | - **A warm resident request is local.** A request to a resident cell does |
| 157 | zero bucket operations and returns in p50 ~1.1 ms and p99 ~7 ms (a |
| 158 | fixed-host measurement). Only a cold activation touches object storage. |
| 159 | - **A durable write waits for a durability proof.** A single node proves |
| 160 | each write through the bucket, so one storage round trip is the minimum |
| 161 | latency for that write. A fleet of two or more nodes can prove a write |
| 162 | when each follower holds it on disk, and a follower fsync is much |
| 163 | faster than a storage round trip: a lab fleet measured about 600 ms for |
| 164 | a bucket proof and about 25 ms for a fleet proof. The bucket upload |
| 165 | races every fleet proof and either one proves the write, so a slow |
| 166 | follower cannot make a write slower than a bucket proof. Concurrent |
| 167 | writes to one cell join one shared upload, so the throughput of one |
| 168 | cell is not one round trip for each write. |
| 169 | - **A restore is normal work.** Placement handles the restore of an |
| 170 | inactive cell as ordinary work, and not as an emergency procedure. The |
| 171 | measured restore times come from the retired external replicator, so this |
| 172 | page gives no number until a fleet run measures `celld-ltx`. |
| 173 | - **Ten small nodes held real scale.** A fleet of ten nodes, each with 4 |
| 174 | vCPU and 8 GB, held 10,000 resident cells and 20,000 concurrent |
| 175 | WebSocket connections. We stopped two of the ten nodes, and the data of |
| 176 | every cell was available again on another node in ~11 s at the tail |
| 177 | (with reserve headroom). |
| 178 | |
| 179 | ## The failure edges we intend to find |
| 180 | |
| 181 | A fleet at its resident limit has no space for the cells of a lost node, |
| 182 | so the loss of multiple nodes degrades the service. We test recovery with |
| 183 | and without reserve capacity to measure this limit. |
| 184 | |
| 185 | Report a schedule that breaks a guarantee, a fault that we do not test, |
| 186 | or a measurement that you cannot reproduce in the |
| 187 | [issue tracker](https://github.com/denoland/celld/issues). |