Delos: virtual consensus, or how to swap consensus protocols live

How Meta’s Delos seals a log, swaps a pointer and moves to a new consensus protocol with no downtime, so its Loglets need no leader election or reconfiguration.

Published 11 min read

Raft puts leader election, log replication and membership changes into one protocol. Aurora fences off old configurations with epochs. FoundationDB recovers by stopping its old log servers and starting a new generation of the transaction system. Calvin runs everything off one ordered input log. Delos, Facebook’s control-plane database, goes further than any of them: it lets you replace the consensus protocol itself while the database keeps serving traffic.

The design is described in Virtual Consensus in Delos by Mahesh Balakrishnan, Jason Flinn and colleagues at Facebook (OSDI ’20), which USENIX lists as “Awarded Best Paper.” It’s cited here as [Delos], and section numbers refer to it. Extra context comes from the authors’ 2019 post Delos: Simple, flexible storage for the Facebook control plane ([FBEng19]), which calls Loglets by their earlier name, SimpleLogs. Paragraphs marked My take are my own analysis.

The problem: consensus systems are monoliths

The paper’s complaint is that “systems that use consensus to replicate state are monolithic, complex, and difficult to evolve” (§1). ZooKeeper “still runs a decade-old protocol,” and new ideas reach production only when someone builds a whole new system around them.

A shared log API (append, check the tail, read) already hides the protocol from the application. That still leaves two problems (§1). First, nothing lets a running service migrate to a different log implementation without downtime. Second, a consensus protocol has a data plane (ordering and storing commands) and a control plane (changing “leadership, roles, parameters, and membership”), and “existing protocols such as Raft aggressively combine both planes into a single protocol.” If you want a new ordering mechanism, you end up rewriting the control plane too.

Facebook hit this in 2017. It needed “a table store for its core control plane services with strong guarantees on durability, consistency, and availability,” and the system “had to reach production within 6-9 months” and then get faster over time (§2). Its four existing stores (ZooKeeper, a LogDevice-based shared log, ZippyDB and replicated MySQL) didn’t fit: ZooKeeper has no table API, and MySQL “provided inadequate availability.” Building on LogDevice would have been quick, “but also tie us for perpetuity to the fault-tolerance and performance properties of that consensus implementation” (§2).

The result is “a fully replicated ACID database providing strict serializability,” filling the role that Chubby, etcd and ZooKeeper fill elsewhere (§4). It had been in production for over 18 months, handled “over 1.8 billion transactions per day,” and each deployment ran on 5 to 9 machines (§1).

The idea: a virtual shared log

Delos puts a VirtualLog between the database and the actual logs. The VirtualLog has the usual shared log API, but internally it’s a chain of underlying logs called Loglets, each serving one segment of a single virtual address space. The paper’s example chain maps [0, 100) to Loglet A, [100, 150) to Loglet B and [150, ∞) to Loglet C. An append that C reports at its position 10 becomes virtual position 160 (§3.1). Only the last Loglet, the active segment, accepts appends. The earlier ones are sealed and reject them.

Both layers share one interface (Figure 2). It has append, checkTail (“the first unwritten position”), readNext and prefixTrim, plus two additions: seal, “which ensures that any new appends fail,” and a checkTail that also returns a sealed bit. The VirtualLog adds reconfigExtend, reconfigModify and reconfigTruncate.

The key split, in the paper’s words: “consensus in the VirtualLog is simple and fault-tolerant (but not necessarily fast, since it is invoked only on reconfigurations), while consensus in the Loglet is simple and fast (but not necessarily fault-tolerant)” (§3).

Reconfiguration: seal, install, fetch

The VirtualLog has two parts: a client-side library that routes operations using a cached, “potentially stale” copy of the chain, and a MetaStore that durably holds the chain. The MetaStore is “a single versioned register supporting a conditional write” (§3.2). Any client can start a reconfiguration, or finish one someone else started:

  1. Seal the active Loglet, then call checkTail on it. That tail is where the new segment starts. Seals are idempotent, so several clients can seal at once.
  2. Conditionally write chain i+1 to the MetaStore, only if the stored chain is still i. Of the racing clients, “at most one [is] guaranteed to win.”
  3. Fetch the chain if your write lost.

Three rules make this safe (§3.2):

  • Stale appends fail loudly. A client still on the old chain gets “an error code indicating that the Loglet is sealed,” fetches the new chain and retries.
  • Stale tails are flagged. A checkTail that hits a sealed Loglet tells the client it’s on a stale chain, so it refetches. Without that, a read could linearize at an old position.
  • Half-finished reconfigurations roll forward. If the reconfiguring client dies after sealing, another client waits for a timeout and installs “a default new chain by cloning the configuration of the previous active segment.”

Seals aren’t always needed. A seal is only required when the new chain “remaps some unwritten virtual address to a different Loglet.” Rebuilding servers in a sealed segment, remapping a sealed segment, or truncating the first one can all run alongside appends at the tail (§3.2).

My take: this is compare-and-swap on a pointer, with sealing as fencing. The seal stops the old segment from growing, the CAS picks exactly one successor, and the sealed bit lets stale readers notice they’re stale. Take any one of the three away and you can lose or reorder acknowledged writes.

Why the MetaStore is separate

Raft and similar protocols store the next configuration inside the log itself (§3.3). Delos can’t, because writing to the current Loglet to reconfigure it would require that Loglet to be “highly available for writes (i.e., implement fault-tolerant consensus).” Keeping the chain in a separate MetaStore removes that requirement, so the MetaStore is “a necessary and sufficient source of fault-tolerant consensus” (§3.3).

The MetaStore started as “a single key/value pair” on ZooKeeper. To remove that dependency, it became an embedded MetaStore built from Lamport’s original sequence of single-slot Paxos instances. It’s deliberately “simple, unoptimized,” with “two round-trips to a quorum for both writes and reads,” no pipelining and no multi-slot leader election. That would be far too slow for ordering commands, but “it is more than sufficient for a control plane protocol that is invoked only for reconfigurations” (§4.1). A reconfiguration costs a seal, a checkTail and one MetaStore write, which takes “10s of ms” within a data center (§3.3, §5.2).

Loglets only have to seal

A Loglet needs to provide “totally ordered, durable storage.” It can run in a fixed configuration, with no membership changes and no leader election, so “it is not required to provide high availability for append calls.” What it must provide is a highly available seal (§3.4). A seal bit is weaker than consensus: it can be built from a fault-tolerant atomic register, which is “not subject to the FLP impossibility result” (§3.4).

The contract is deliberately loose. Tail and seal status don’t have to be read atomically, and unacknowledged “zombie” appends can still turn up on a sealed Loglet after the seal. They don’t matter, because the chain fixes each segment’s length, and positions past the end never become visible (§3.4).

NativeLoglet: a log with no leader election

NativeLoglet is the Loglet Delos runs in production (§4.2.1). Every Delos server runs a LogServer with a local log and a seal bit, and one server also runs a sequencer.

  • append: the sequencer assigns a position and sends the command to every LogServer. Acks from a majority of unsealed LogServers commit it. The sequencer retries idempotently until the append succeeds or the Loglet is sealed. Slow LogServers can skip entries that are already globally committed, so they don’t hold up appends.
  • seal: set the bit on a majority.
  • checkTail: ask everyone and wait for a majority. If none are sealed, wait until your known tail reaches the highest reported tail. If some are sealed, seal and retry. If all are sealed, repair any LogServers that are behind up to the highest tail and return it. Repair is safe because “the single sequencer ensures that there can never be different entries for the same position.”
  • readNext: read from any copy. Reads only cover positions already known to be committed, so no quorum is needed.

There’s no leader election. If the sequencer dies, appends stop. Failure detection (in-band checks, a gossip-based detector and container-manager signals) then asks the VirtualLog to seal this NativeLoglet and switch to a new one, and NativeLoglet chooses the new instance’s LogServers and sequencer. The team says “it took just under 4 months to implement and deploy a production-quality NativeLoglet” (§4.2.1).

Loglets also compose. StripedLoglet is “around 300 lines of code” that stripes positions round-robin across several Loglets and acknowledges an append only once every earlier position is filled, which keeps it linearizable (§4.2.2). With the same LogServers but different sequencers, it eases the sequencer bottleneck. With disjoint stripes, it scales like sharded acceptors.

The numbers

From §5 (p99 latencies, against a 15 ms p99 SLA):

  • Live protocol swap in production (2 April 2019): moving from ZKLoglet to NativeLoglet improved p99 by 10× for multi-gets and indexed queries and 5× for multi-puts, with no downtime (indexed-query p99 spiked during the switch). The paper credits most of this to an “unoptimized” ZKLoglet that wrote “a new sequential ZooKeeper key on each append.”
  • Disaggregation: on production hardware, converged NativeLoglet starts slowing at 15K ops/s, and a LogDevice Loglet on 5 extra machines reaches 150K ops/s, 10× more. That’s partly from twice the hardware and better disks. On benchmark hardware the gain is 33% (139K vs 190K ops/s).
  • Live switch under a load spike: going from 100 to 2,500 puts/s pushed converged p99 over a second. Switching to the disaggregated log at about 530 s brought it back under 15 ms.
  • StripedLoglet: 25% faster than a 9-node NativeLoglet when rotating sequencers, and over a million 1 KB appends/s across 30 stripes (90 LogServers) in a log-only test.
  • Cost of virtualization: 100–150 µs added to p99 for append and checkTail, 6 µs for readNext. Reconfigurations take tens of ms. One cluster reconfigured 98 times in a month, mostly because of deployments and machine preemptions.
  • Against ZooKeeper: ZooKeeper does over 30K puts/s under the SLA, Delos about 26K. The main reason is that ZooKeeper keeps its state in memory; an in-memory Delos prototype reached 40K.

What production taught them

The Discussion section (§6) is the best part of the paper:

  • “Fate-sharing… but only when my fate is good.” The database layer is more fragile than the log, because it changes often, but it needs less redundancy: one learner can survive where a log needs a quorum. When two of five converged replicas crashed, “which was not uncommon,” operators temporarily moved the log to a disaggregated Loglet, repaired the database and moved the log back.
  • A fallback that stays available. When they “discovered latent bugs in the NativeLoglet; we reconfigured to ZKLoglet, rolled out hotfixes, and then reconfigured back.”
  • “Consensus is forever… until it’s not.” Because the address space is just metadata, you can delete an entry by editing the chain. That helped when “a ‘poison’ entry caused hangs on all learners processing the log.”

Limits the paper admits to: planned leader changes are slower than in a protocol with built-in handover, only totally ordered logs fit the API, a StripedLoglet must be sealed as a whole, and Delos is limited by log playback, not by log throughput (§1, §4.2.2, §5.1).

Delos vs the systems before it

  • Raft: reconfiguration lives inside the protocol, as special entries in the replicated log. Delos moves it to a separate layer that works with any Loglet.
  • Aurora: membership epochs need a write quorum to increment, and requests at stale epochs are rejected (SIGMOD ’18). It’s the same fencing idea, applied to storage quorums.
  • FoundationDB: on recovery, the new Sequencer “stops these LogServers from accepting transactions,” recruits new ones and records the new generation in Paxos-backed Coordinators (FDB). That’s close to seal plus MetaStore, but used only within FDB.
  • Calvin: its ordered input log can be replicated with Paxos through ZooKeeper, which “handles the necessary throughput to replicate Calvin’s transactional inputs” (Calvin). That kind of single-log system could put a VirtualLog underneath and swap the log out later.

My take: FoundationDB is the closest relative. Delos turns “stop the old logs, record the new generation” into a general API and lets the next generation run a different protocol, codebase or deployment model. In interviews, don’t quote the 10× as “NativeLoglet beats ZooKeeper”; on equal hardware ZooKeeper was faster on puts. The point is that you can ship on something slow and replace it later without downtime.

Patterns worth stealing

  • Split control and data planes, even inside consensus. Make the rarely used path fault-tolerant and the hot path fast. Neither has to do both.
  • Seal, then CAS a pointer. Replace an append-only resource live by fencing it, reading where it ended and conditionally updating the metadata. Anyone can roll a half-done swap forward.
  • Return a staleness bit with reads. (tail, sealed) lets clients find out their metadata is old.
  • Ask for the weakest primitive that works. A highly available seal instead of highly available appends makes each new log easier to build.
  • Ship on what exists, and design it to be replaced.

A design question for you

You’re designing the replicated metadata store behind a cluster scheduler’s machine-reservation ledger. It needs strictly serializable transactions with secondary indexes, runs on 5 machines per deployment, serves about 500 reads and 150 writes a second with maintenance bursts to 2,500 writes a second, and must keep p99 under 15 ms with no runtime dependency on other services. Today it replicates through ZooKeeper. Within six months you must move it to an in-house replication protocol with zero downtime, and operators want point-in-time restore and a way to skip one bad entry that crashes every replica on replay.

How do you switch log implementations while clients are still appending to the old one? Does your new log need leader election? And what changes if the store later spans regions, where a seal plus a metadata write is no longer tens of milliseconds?

Sources

Primary source:

  • Mahesh Balakrishnan, Jason Flinn, Chen Shen, Mihir Dharamshi, Ahmed Jafri, Xiao Shi, Santosh Ghosh, Hazem Hassan, Aaryaman Sagar, Rhed Shi, Jingming Liu, Filip Gruszczynski, Xianan Zhang, Huy Hoang, Ahmed Yossef, Francois Richard and Yee Jiun Song, Virtual Consensus in Delos, OSDI ’20 (USENIX page).

Background and later work:

For the comparisons: