Published on

The atproto object store architecture

Authors

A bit ago, Jaz mentioned that she's a big believer in building around object stores (the "zero disk architecture" [1, 2, 3]). The topic first came up when we were looking at the trend of Kafka-likes adopting S3: WarpStream, Bufstream, Kafka diskless. I didn't think much of it at the time, but then she built vlpds and got me thinking...

Systems need to survive machine turnover, and building new durable systems is quite hard. The S3s can have higher write latencies†, but they provide distributed storage that's operationally simple, adequately featured, and widely available.

† The write latency problem can be overstated. Foundation and Scylla achieve 1-5ms writes [4, 5], while Seaweed, Minio, and S3 Express write within 10ms [6]. Standard S3 and R2 are 50-200ms, and that likely drives this perception to be worse than it actually is.

We run our own hardware at Bluesky, so things that people take for granted in the cloud have to be specifically designed with each system we build. We know how difficult it can be to manage machines that are bound to their storage, but also each new cluster is a drain on our ops and engineering.

Ideally we'd reuse a few core primitives like SeaweedFS. For building applications we need a more featureful database than the S3 API provides though; something like vlpds. With atproto spaces launching, could vlpds host more than user accounts? Could it also be a reusable internal datastore?

Adding atproto to S3

For those unfamiliar, an "atproto PDS" hosts JSON document stores, which we call repositories. Repos provide atomic batch commits, compare-and-swap preconditions, globally addressed & linkable objects, and signed replication logs which sync across the internet. Historically it has only handled public data, but the new spaces protocol means we can use it for non-public data.

flowchart TD
    subgraph vlpds[vlpds]
        subgraph Atproto[atproto]
            C[Linked JSON]
            B[Atomic batches]
            D[Replication logs]
        end
        subgraph S3[S3]
            A[Durability]
            E[Simple ops]
        end
    end

vlpds puts both the replication log and the PDS state in an S3 bucket. Repos are grouped into shards, each owned by one node. Any node can accept a request and forward it to the owner; memory and local disk serve as caches. [7].

On a write, a repo worker updates the Merkle search tree and signs the commit. A node-wide log writer batches commits from all of its shards into segments in the bucket. It can prepare later commits while earlier uploads are in flight, but it doesn't acknowledge a write until its segment and every earlier segment are durable. This spreads the cost of each object-store request over many commits. [8].

createRecordany nodeRepo workerMST path · sign commitLog writergroup commitlog/…/{ordinal}.segIf-None-Match PUTSlateDB memtableapply for readsHTTP 200cid · revFirehosemerged across nodesdurable, then applysealed segments
Write path adapted from the vlpds docs.

Each shard also has a SlateDB database for reading records and repo state. vlpds applies durable log entries to SlateDB's in-memory table before returning HTTP 200, so a read after the write sees the new state. SlateDB later flushes that state into sorted tables (SSTs) in the bucket. Its own write-ahead log is disabled because vlpds's log already provides the durable copy. [9].

The same log feeds the atproto firehose. If a node fails, a replacement takes over its shards after fencing off the old node's log, then recovers their state by replaying entries after the last checkpoint. That's the part I find appealing: the bucket holds the durable state, and we can replace the machines that serve it. [7].

Performance

The benchmarks give a useful sense of the scale a single node can handle. (In practice you use multiple nodes.) These runs used local MinIO, with a 25ms median delay injected into log-segment PUTs for the write tests. Write throughput saturated at 50k/s, which is notable because the public firehose currently averages 500-1k write events for the entire network.

vlpds on local MinIO: at 25k, 50k and 75k offered commits per second, completed throughput was 25.2k, 49.6k and 58.8k, with median write latencies of 66.3, 105.9 and 289.3ms and p99 latencies of 121.9, 476.7 and 705ms. A separate getRecord test reached 85.2k reads per second, with 0.75ms median and 1.26ms p99 latency.

Results · Test hardware

SeaweedFS published a test that measured 4.36ms median PUTs and 2.79ms GETs for small JSON objects on a shared two-vCPU VM at concurrency one. That's a storage measurement, not a vlpds result. [12]. I'd expect that lower storage latency to improve vlpds' write acks and cache-miss reads, but we'll need a matching vlpds benchmark to put numbers on the difference.

S3 Express One Zone offers single-digit millisecond access within one availability zone, but its directory buckets lack the ordered listing and StartAfter behavior vlpds currently requires. Using it would need compatibility work as well as a new benchmark. [13, 14, 15].

Ingestion pipeline

Atproto leans heavily on asynchronous processing because it's an internet protocol. It expects independent indexing processes across the world which don't know about each other. This ingestion pipeline extends the querying capability beyond the relatively dumb PDS APIs.

flowchart LR
    subgraph Public[Public]
        D[User repos]
    end
    subgraph Internal[Internal space]
        A[Org repos]
    end
    A --> J
    D --> J[Internal Jetstream]
    J --> V1[(ScyllaDB)]
    J --> V2[(Clickhouse)]
    J --> V3[(Elastic)]

We sync repos into a variety of engines: Clickhouse, Elastic Search, ScyllaDB, etc. Each view comes at a low marginal cost because they're produced outside of the write path, so we can scale them horizontally without a lot of trouble. Durability is only a performance and availability question, so we don't persist to S3 here; we can use the local disk here.

We combine datasets from multiple repositories in the derived views, so we have to account for eventual consistency. Updates for each repository arrive in independent orders. Content-hash links help us track dependencies between repos. When strict consistency is needed to enforce invariants, we put all of the relevant data into the same repository. For example, a users table that needs to enforce unique usernames would need to place the full table into one repo.

The other important dynamic to watch is freshness. Replication is asynchronous and will update each receiving view on its own time. If you're aiming to read-your-own-writes on the derived view, you'll want a way to poll the view for ingestion state. Essentially you hold until putRecord returns and until view.hasProcessed(record) returns true. If you do that, be sure to bound your wait, and treat the view update as a secondary concern. Once putRecord has 200ed, the update has successfully committed.

Forward evaluation

You can look at vlpds as adding S3's durability to atproto, but the reverse is also true: vlpds adds atproto to S3. Putting org-internal data into spaces would let us fold their data into the same indexing infrastructure that we've already built to handle public atproto data.

Using space repos for internal data may come down to the write APIs we need. We may want more transactional tools than the space repo API exposes. A custom implementation could add a richer write API alongside the standard endpoints, while preserving the repository format and sync protocol. This would be a relatively minor affordance to add.

We haven't yet adopted vlpds internally because we've been wrapped up with launching spaces, but its design is a leading candidate for a long-overdue fleet upgrade. Once it's done, I'll be eager to explore internal spaces. For a company running its own internal cloud, solving durable, compute-independent storage would be a great win.