# No disks: why Cairnflow keeps everything in a bucket

> Cairnflow is a durable runtime for agents and workflows whose only state is an S3-compatible bucket. This post explains the bet, how it works, and what it costs.

Author: Phuong Pham | Date: 2026-12-04 | Source: https://cairnflow.dev/blog/no-disks

An agent run is mostly waiting. It waits for a model, then for a tool, then for a person to
approve a refund, then for a timer. A run that lasts an hour may use a few seconds of CPU.
Somewhere in that hour, the process that started it will be redeployed, scaled away or killed.

Durable execution is the known answer. Record every step in a journal; when the code has to run
again, replay it. Steps that are already in the journal return their recorded result, and the
code carries on from the first step that is not. Temporal, Restate and DBOS work this way, and so
does Cairnflow.

Where they differ is where the journal lives. Temporal keeps it in a database you run: Cassandra,
PostgreSQL or MySQL. Restate keeps it in its own replicated log and RocksDB partitions on local
disks, with snapshots to object storage. DBOS keeps it in PostgreSQL. These are sound designs.
Each of them also leaves you with a stateful system to size, replicate, upgrade and back up, and
that system has to be healthy before any agent can take a step.

Cairnflow makes a different bet: **the bucket is the database.** Journals, state, timers, queues
and the record of which node owns what all live in one S3-compatible bucket. The nodes keep
nothing on local disk.

## What you operate

```text
   your code (an SDK, any HTTP host)                    clients / your app
              ▲  turns: replay journal, run next step          │
              │                                                ▼
   ┌──────────┴──────────────────────────────────────────────────────┐
   │ cairnflow nodes — stateless; each range of keys has one leader  │
   │   engine per range · per-node shared WAL · leases by CAS        │
   └──────────────────────────────┬──────────────────────────────────┘
                                  │ conditional PUT / GET / LIST
                                  ▼
             S3-compatible object store — the only source of truth
```

You run `cairnflow` processes and you have a bucket. That is the whole list. Several nodes
pointed at the same bucket form a cluster, and one node is a cluster of one. There is no separate
consensus service: no Raft, no etcd, no PostgreSQL. Kill a node with `kill -9`, start another one
anywhere with the same bucket URI, and every run continues from its last recorded step.

## See it

This is a handler that reads state, waits, charges a card and writes state back:

```ts
import { type Context, serve, service } from "@cairnflow/sdk";

const orders = service(
  "OrderService",
  {
    async submit(ctx: Context, input: { amount: number }) {
      const soFar = (await ctx.get<number>("total")) ?? 0;
      await ctx.sleep(1_000, "await confirmation"); // a durable timer
      const receipt = await ctx.run("charge", () => chargeCard(input.amount)); // recorded once
      ctx.set("total", soFar + input.amount);
      return { receipt, total: soFar + input.amount, order: ctx.key };
    },
  },
  { type: "VIRTUAL_OBJECT" },
);

await serve({ services: [orders], port: 9080 });
```

Start a call without waiting for it, kill the node during the one-second sleep, and start the
node again:

```sh
curl -s -X POST 'http://127.0.0.1:8080/invoke/OrderService/submit/send?key=order-43' \
  -H 'content-type: application/json' -d '{"amount": 7}' && pkill -9 cairnflow   # prints JSON with the invocation id
cairnflow --no-auth                       # back up, from the same directory (Docker: docker start cairnflow)
sleep 2 && cairn status <id>              # completed; the charge was recorded once
```

There is no recovery step to perform. The journal is in the store, and the process only reads it.
In this demo the store is a local directory. In production it is
`--main-store s3://my-bucket/prefix`, and the node you start again can be on another machine.

## Three ideas that make it work

### One writer per range, decided by compare-and-swap

The key space is cut into contiguous ranges. Each range has one leader node, one
[SlateDB](https://slatedb.io) database in the bucket, and one single-threaded engine that runs
every state change of that range.

Taking a range is a single conditional write on its owner record: of two nodes that try, exactly
one wins. A node shows it is alive by renewing a session record, also by compare-and-swap. When
it stops renewing, another node takes over its ranges after about one lease TTL, which is 10
seconds by default.

The dangerous node is not the dead one. It is the one that froze, lost its ranges, and then woke
up believing it still leads. Opening a range for writing raises an epoch in SlateDB that fences
the previous writer. The stale node can still buffer a write, but its wait for durability fails.
That is why nothing is acknowledged to anyone before that wait succeeds.

### One write-ahead log per node, acknowledged only when durable

SlateDB normally gives every database its own write-ahead log. With hundreds of ranges on a node,
that would mean hundreds of streams of small PUTs. Cairnflow instead multiplexes the log of every
range a node leads into a few streams (two by default), batches what arrives within a short
window into one object, and writes that object with a create-only PUT.

A step is acknowledged to the client, to your handler or to another range only after the object
that holds it is in the bucket. So log requests grow with the number of nodes, not with the
number of ranges or runs, and a busy node makes one write per batch instead of one per step.

### Ranges split and merge without copying data

Rows are ordered by partition key, so a range covers contiguous slices of the keyspace. A split
makes each child a clone of the source database, projected onto its half of the keys. No row is
rewritten.

The change is committed by a compare-and-swap on the range table, under an intent protocol in
which exactly one of two competing writes can win. A coordinator that dies at any step leaves
either the old ranges or the new ones — never both, and never neither.

### One more detail: the answer to a conditional write can be ambiguous

The S3 client retries a `5xx` response, even for a conditional PUT. So "precondition failed" may
be the answer to a retry of a write that already succeeded, and an error may have landed anyway.
A protocol that takes those answers at face value can conclude that it lost a write it actually
won, or the reverse.

Every conditional write in Cairnflow therefore resolves an unclear result by reading the object
back and comparing it with what it meant to write. The test suite has a mode that makes every
store operation ambiguous once, and the cluster tests have to pass under it.

## Why this shape fits agents

- **A waiting run is just bytes.** A run that waits for an approval, a timer or a webhook holds
  no process, no memory and no connection. It is its journal and state in the bucket until
  something wakes it, a minute or a month later.
- **Nodes are disposable.** Replace, restart or add a node without moving data. There is no
  volume to attach and no replica to rebuild, which suits traffic that is bursty or idle most of
  the day.
- **Long histories stay cheap to write.** Large state is stored as immutable segments. A turn
  writes the new tail and reuses the rest, so a chat history can grow far past the payload limit
  of a single request.
- **Your data is in one place you already know.** There is no second system holding the truth.
  Self-hosted, it is your bucket.

## What it costs

A design post that lists only benefits is an advertisement, so here is the other side.

**The store sets the latency floor.** Every committed step is at least one PUT to the object
store. That is tens of milliseconds on S3 Standard, and lower on object stores built for low
latency. Next to a model call that takes seconds, it is small. If you need single-digit
millisecond commits on every step, Cairnflow may not be the right engine. We have not published
benchmark numbers yet: the numbers we have were measured on shared development machines, so the
[benchmarks page](https://github.com/cairnflowdev/cairnflow/blob/main/docs/benchmarks.md) gives
the exact commands instead, and you can run them on your own hardware and store.

**The store has to keep its promises.** Everything above depends on conditional PUT and on
strong read-after-write consistency. "S3-compatible" does not guarantee either. One store we
tried, Garage v1.0.1, accepted a second create-only write and overwrote the object. A local
erasure-coded MinIO tore a lease object in two when a client was killed in the middle of an
update, and that range never got a leader again. So a node probes its store before it writes
anything and refuses to start on one that fails. The
[object stores page](/docs/self-hosting/storage) lists what has been verified and how.

**Durability and availability are the store's.** Cairnflow does not add durability on top of the
bucket. When the bucket is unreachable, ranges pause and step down. They do not serve stale or
unacknowledged data.

**`ctx.run` is not exactly-once for the outside world.** It records a result exactly once. If a
node dies after your function ran and before its result was durable, the function runs again.
Calls to external systems should carry an idempotency key.

**It is a beta built on a fork.** Cairnflow depends on a fork of SlateDB 0.18.0 with 23 patches
that are not upstream yet: the shared write-ahead log, projected clones and a few changes that
make idle databases cheap. Getting those upstream is a long-term goal.

## How we check it

"An acknowledged step is never lost and never applied twice" is an easy sentence to write. What
stands behind it today:

- four protocol models (leases, split and merge, the shared log, the invocation lifecycle) that
  explore every interleaving, and that must fail again when a past fix is removed;
- deterministic simulation of whole clusters under one seeded clock and network;
- 160 named failpoints, with tests that crash a node at every step of a split and of the shared
  log;
- chaos runs on a real S3-compatible store. In the longest one so far (24 hours, three nodes,
  5,231 `kill -9`s, one every 10 seconds), 701,034 acknowledged results were checked afterwards:
  none lost, none wrong.

[The next post](/blog/how-we-test) covers this in detail.

## Where it stands

Cairnflow is in **beta** (`v0.1.0-beta.0`). The on-bucket format is frozen and upgrades migrate
data in place, but APIs may still change between minor versions. Prebuilt binaries (Linux and
macOS), Docker images (`ghcr.io/cairnflowdev/cairnflow`), and three zero-dependency SDKs
(TypeScript, Python and Go) are available now.

It is **source-available**, not open source. The engine and the console are under the Business
Source License 1.1, and each version converts to Apache-2.0 four years after its release. The
SDKs and the conformance suite are Apache-2.0. You may read, modify and self-host Cairnflow,
including inside commercial products. You may not offer it to third parties as a competing hosted
service.

Two debts are worth naming. The storage engine underneath is [SlateDB](https://slatedb.io). The
programming model of services, virtual objects and workflows is close to
[Restate](https://restate.dev)'s, and the wire protocol definition is derived from Restate's
MIT-licensed service protocol. The two are not interchangeable.

If the bet sounds right to you, or wrong in an interesting way:

- the source and release binaries are at [github.com/cairnflowdev/cairnflow](https://github.com/cairnflowdev/cairnflow);
- [the architecture document](https://github.com/cairnflowdev/cairnflow/blob/main/docs/architecture.md)
  has every invariant and the test that proves it;
- the [quickstart](/docs/quickstart) takes about two minutes with a release binary or Docker;
- if you want managed clusters on object storage, [join the Cairnflow Cloud waitlist](/#pricing).

Bug reports and design feedback are welcome in the issue tracker.
