Home › Distributed systems

Distributed systems

Consensus, replication, time, partitioning and membership.

Consensus

Agreeing on one value or log among replicas.

Replication

Keeping copies in sync.

Chain replication

Replicas in a line: writes enter at the head and commit at the tail, reads hit the tail; f+1 nodes tolerate f failures.

write n hops; read 1 hop (tail) or any node with CRAQ; f+1 replicas tolerate f crashes

Quorum replication

Leaderless replication: write to W of N replicas, read from R; overlap (R + W > N) makes reads see the latest completed write.

read and write 1 round trip to the fastest R or W of N replicas

CRDTs

Data types whose replicas accept writes independently and always converge by merging, with no coordination: counters, sets, maps, registers, text.

merge O(state) for state-based, O(1) per op for op-based; metadata O(replicas) per object

Primary-backup replication

One node orders all writes and ships them to standbys; the acknowledgement rule (none, one, all) sets what a crash loses, and an external arbiter decides who takes over.

write 0 (async) or 1 (semi-sync, sync) round trip to backups; f+1 nodes tolerate f crashes given an external arbiter

Anti-entropy repair

Replicas compare hash trees of a key range, descend only into differing subtrees and stream just those ranges, healing silent divergence in the background.

tree build O(n) scan; diff O(d log n) hash comparisons for d differing leaves

Hinted handoff

Park a write meant for a down replica as a tagged hint on a healthy node, replay it when the replica returns, and count it toward the write quorum only if availability matters more than consistency.

hinted write O(1) append; replay O(missed writes), versus O(range size) to find them by comparison

set reconciliation

Planned.

Time & ordering

Ordering events without a global clock.

Partitioning

Deciding which node owns which key.

Consistent hashing

Hash nodes and keys onto a ring; each key belongs to the next node clockwise, so membership changes move only about 1/n of keys.

lookup O(log(n·v)) binary search; add/remove node moves ~1/n of keys; memory O(n·v)

Rendezvous hashing

Score every node with hash(key, node) and pick the highest: minimal key movement and exact weights without a ring, at O(n) per lookup.

lookup O(n) hashes (O(log n) with a skeleton hierarchy); top-k O(n); memory O(n)

Jump consistent hash

Five lines, zero memory, near-perfect balance: maps a 64-bit key to one of n numbered buckets, moving only 1/(n+1) of keys when n grows.

O(ln n) expected iterations; O(1) memory

Range partitioning

Cut the sorted key space into contiguous half-open ranges kept in a boundary map; split hot or big ranges, merge small ones, move ranges between nodes.

lookup O(log R) for R ranges; range scan O(log R + k) for k overlapping ranges; split and merge O(log R)

Online resharding

Split or move a shard while it serves traffic by copying a snapshot, replaying changes until the lag is tiny, then flipping a versioned routing table.

copy O(data) at disk/network speed; catch-up converges when replay rate exceeds write rate; write freeze O(final lag), milliseconds

crush placement

Planned.

shuffle sharding

Planned.

Scatter-gather query

Send a query only to shards that can match, merge their small partial results, and bound the wait for stragglers.

latency = slowest contacted shard + merge; merge O(n·k log k); requests O(n)

cell based architecture

Planned.

Membership & failure detection

Knowing who is alive.

Coordination

Cross-node transactions and ownership.

Two-phase commit

Atomic commit across shards: participants durably vote yes, then the coordinator logs and broadcasts one decision; blocks if the coordinator is lost.

2 round trips (client reply after 1 RTT + 2 sequential forced log writes); 3-4n messages for n participants

Leases

A lock that expires on its own: bounded-time ownership that survives crashes and partitions, given bounded clock drift and fencing tokens on writes.

O(1) per grant/renew; one round trip to acquire; renew every ~1/3 of the term

Fencing tokens

A number that grows with every lock grant and is checked by the protected resource, so a paused ex-holder's late write is rejected.

O(1) per grant and per checked write; one u64 of state at the resource

conditional writes

Planned.

Saga pattern

Split a cross-service operation into local transactions, each paired with an undo; on failure run the undos in reverse, or retry forward.

success: n local commits, n+2 log records, 2n messages; failure at step k: k forward + k undo commands; no locks held across services

Transactional outbox

Write the event as a row in the same local transaction as the state change; a relay publishes it later at-least-once, so state and events never diverge.

one extra row per event in the business commit; relay O(batch) per poll, or no polling with log tailing; at-least-once

percolator transactions

Planned.

causal consistency tokens

Planned.

Config distribution

A control plane pushes versioned resource changes over long-lived streams; each node validates, ACKs or NACKs and keeps its last good copy, so a bad change stops at a canary.

O(changed resources) bytes per node per update; O(nodes) messages per rollout; O(1) per-node state

Desired-state reconciliation

Declare the target in a store; controllers repeatedly diff actual against desired from full state and apply idempotent fixes, so missed events only delay convergence.

O(1) queue add/get; reconcile O(children of one key); reads from a watch cache

Watch notifications

A store numbers every write; clients list at revision R, then watch from R+1 and receive an ordered change stream with no gap, no duplicate, and a resume point.

O(log H + matches) to open or resume a watch on history H; O(len(key) log W) to find the watchers of one event

Logs, queues & fan-out

Durable logs and queues, delivery guarantees and fan-out to many consumers.

Partitioned commit log

A topic split into replicated append-only partitions: key hash keeps per-key order, offsets give position, and a high watermark limits readers to fully replicated records.

produce O(1) amortized per record; throughput scales with partitions; order only within one partition

Segmented log

Split an append-only log into files named by their first offset, write only the newest, and find any record by binary search plus a sparse index.

append O(1); read O(log segments + log index entries + records per index gap); retention O(deleted files)

Consumer offsets

Each consumer group stores one integer per partition, the next position to read, so a restarted consumer resumes where it left off with at-least-once delivery.

O(1) per commit and per lookup; state = one integer per (group, partition); log compacted to that size

consumer group rebalancing

Planned.

log compaction

Planned.

Durable job queue

Persisted tasks that workers lease for a visibility timeout, ack on success and retry with backoff; at-least-once execution that survives worker and queue crashes.

enqueue O(log n) + one log append; claim O(log n); one fsync per commit batch, not per job

Dead-letter queue

A side queue for messages that keep failing: after N delivery attempts or a permanent error, park them with the reason so the main queue keeps moving.

O(log n) per receive/settle with a timer heap; O(1) to dead-letter; redrive O(k) for k messages

exactly once processing

Planned.

Event deduplication window

Keep the ids of recently accepted events for a time window and drop repeats; memory stays bounded by rotating time buckets instead of per-entry timers.

O(1) expected per event; memory O(rate x window) ids, about 22 bytes per id for a hash set, about 1.2 bytes in a Bloom filter at 1% false positives

Pub/sub fan-out

Deliver one published message to every subscriber of a topic by sharing one encoded payload and giving each connection a bounded queue with an explicit slow-consumer policy.

publish O(N) in matching subscribers (N pointer pushes, 0 payload copies); memory bounded by N x per-connection byte cap

Fan-out on write

Append each new item id to every follower's precomputed, capped list so a read is one fetch; pull the few huge authors at read time instead.

post O(followers) list appends; read O(1) fetch (push) or O(followees) merge (pull); hybrid read O(1 + pulled followees)

Message sequence numbers

A per-stream counter on every message lets the receiver detect loss, duplicates and reordering, ack cheaply and resume after reconnect with "send from N".

O(1) per in-order message; O(log k) per out-of-order one with k buffered; 4-8 bytes per message or per batch

Stream & batch processing

Windowed streams, shuffles, workflows and recovering lost work.

Client sync & collaboration

Keeping clients, devices and collaborators in sync over unreliable links.

Testing & replay

Reproducing distributed bugs deterministically.

HPC communication & scheduling

Message passing and job scheduling on supercomputers.

Other