Cairnflow: a durable execution engine in Rust whose only state is an S3 bucket

2026-12-01来源 Rust Users ForumEnglish

Hi everyone,

I'd like to share Cairnflow, a durable execution engine written in Rust. Its one constraint shapes everything else: nodes hold no state. Every byte — journals, timers, queues, the range table itself — lives in an S3-compatible bucket, and the only coordination primitive is the store's conditional PUT. There is no Raft, no etcd, no Postgres to run beside it. Kill a node with kill -9, start another one anywhere with the same bucket URI, and every invocation continues from its last recorded step.

One thing up front: Cairnflow is source-available. The engine and the console are under the Business Source License 1.1 with an Additional Use Grant, which lets you read, modify, self-host and run it in production, including inside a commercial product; the one thing it does not allow is offering it to third parties as a competing hosted service. Each version converts to Apache-2.0 four years after its release. The SDKs are Apache-2.0. The wire protocol is MIT, derived from Restate's service protocol, and the programming model is close to Restate's; the two are not interchangeable.

This is the first public beta (v0.1.0-beta.0). The on-bucket format is frozen and upgrades migrate in place, but APIs may still change between minor versions.

What it does

You write a service with an SDK (TypeScript, Python or Go) and run it as an ordinary HTTP process. The engine drives a handler in turns: it replays the invocation's journal to the SDK and records each new step durably before telling anyone about it. ctx.run, ctx.sleep, ctx.call, signals, timers and streams are all journaled. Key ranges split and merge online, without copying data. The quickstart takes about two minutes with a prebuilt binary and no key to configure, and step 4 kills the node in the middle of a durable sleep.

The workspace is about 375k lines of Rust across 11 crates, about 160k of them under tests/ directories. Some parts that may interest people here:

Leadership by conditional PUT. The key space is cut into ranges, each with one leader and one single-threaded engine. Taking a range is one CAS on an owner record; opening its database bumps SlateDB's writer_epoch, which fences the previous writer even when it is a frozen process that has not noticed it lost leadership. And because the object_store client retries 5xx responses even for conditional PUTs, a Precondition may be our own earlier success, so every conditional write is resolved by reading back and comparing.

One WAL per node, not per range. SlateDB gives every database its own WAL; with hundreds of ranges per node, that is hundreds of PUT streams. A fork of SlateDB (23 patches on 0.18.0, not yet upstream) adds a WAL trait, and the frames of every range a node leads are multiplexed into two log streams per node by default. An entry is acknowledged only after the PUT carrying it has succeeded, in stream order.

Rules the compiler holds. This is where Rust earns its place for me: a rule a type checker can keep is better kept there than by a reviewer. Network functions take a &Released token that only Lease::released can create, and that exists only while the engine lock is released:

// lease.rs pub struct Released { _not_send: PhantomData<*const ()>, } // invoker.rs pub async fn send(&self, msgs: &[Message], _released: &Released) -> Result<(), InvokeError> 

The argument is never read; it is there so that a network call made with the engine held does not compile. Likewise the writer of a range is neither Clone nor Send, replying to a client needs a Committed ticket issued only once the WAL PUT has made the write durable, and a function that deletes customer data needs a DeleteProof for exactly that subject, built from reads made just before the delete. When a check fails or a read is ambiguous, GC keeps the object: a leak costs space, a wrong delete loses data.

Determinism enforced by lint. A three-node cluster runs on one thread, on a current_thread tokio runtime with paused time, with seeded clocks, randomness, network and store; a failing seed shrinks to a ready-to-paste test. Clippy holds this, not convention: wall-clock time, std::time::Instant, std::collections::HashMap, getrandom and direct HTTP clients are disallowed outside the seeded wrappers. The protocols also have stateright models — two of them run the production decision code — and each bug fixed there is a flag that must turn its model red.

Where it stands

  • I have not published benchmark results yet; the harnesses are in the repo. Every committed step costs at least one PUT on the WAL tier, so the store sets the floor: tens of milliseconds per step on S3 Standard.
  • ctx.run records a closure's result exactly once. An external effect can still happen twice if the node dies after the closure ran and before its result was durable, so external effects should carry an idempotency key.

Feedback welcome

I would especially like to hear about:

  • the conditional-PUT lease: if you run a store whose conditional requests behave oddly (a stale 304, a retried PUT that lands), there is a store contract test you can point at a bucket;
  • the SlateDB fork: is upstreaming the shared WAL and the projected clone worth attempting, or too specific to this design?
  • what you would need before pointing a real workload at it: benchmarks on a named store, a Kubernetes operator, something else?

Questions and design feedback go to GitHub Discussions, bugs to GitHub Issues. Pull requests are welcome under a contributor agreement, signed with one comment on your first PR.

Thanks for reading.

1 post - 1 participant

Read full topic

原文:https://www.a8q9.cn/en/article/cairnflow-a-durable-execution-engine-in-rust-whose-only-state-is-an-s3-bucket-46db89.html

相关文章