Free preview

Cheat Sheet

Key takeaway

Distributed systems are hard for exactly one reason: partial failure. Some parts work, some don't, and the working parts can't tell which. RPC hides the network, consistency models specify what a read may return, and failure models specify how a node may break — every mechanism below exists to stay correct while "did it work?" is unanswered.

Key terms

TermOne line
AbstractionHiding detail to reason about the goal, not the mechanism
Leaky abstractionOne whose hidden details reassert themselves under load or failure
End-to-end argumentGuarantees you truly need must be re-established at the endpoints
MarshalingConverting parameters to a standard wire format (unmarshaling = the reverse)
StubLocal proxy that makes a remote call look like a local one
IDLSchema both sides compile stubs from (.proto, .thrift)
IdempotentDoing it N times equals doing it once
DeadlineAbsolute "give up at" instant, propagated down the call chain
Partial failureSome components failed, and healthy ones can't tell which
Split brainTwo nodes simultaneously believe they own the same data
Fencing tokenMonotonic epoch that lets storage reject a stale leader's writes
Gray failureSystem reports healthy; users experience broken
QuorumOverlapping read/write sets — r + w > n

The eight fallacies

#FallacyDesign force
1The network is reliableTimeouts, retries, idempotency, breakers
2Latency is zeroBatch, colocate, cache, go async
3Bandwidth is infiniteCompress, paginate, binary encodings
4The network is secureTLS everywhere, authn/authz per hop
5Topology doesn't changeService discovery, no hardcoded IPs
6There is one administratorVersioned APIs, backward compatibility
7Transport cost is zeroEfficient codecs, locality-aware routing
8The network is homogeneousIDLs, schemas, explicit contracts

Latency numbers worth knowing

OperationRough time
L1 cache reference~1 ns
Main memory reference~100 ns
SSD random read~100 us
Round trip, same datacenter~500 us
Disk seek (spinning)~10 ms
Round trip, cross-continent~150 ms

RPC in one picture

Runtime owns transmission, retransmission, acknowledgment, encryption. That retransmission is why delivery semantics are your problem.

Delivery semantics

SemanticImplementationUse for
At-most-onceSend once, never retryMetrics, telemetry, cache warming
At-least-onceRetry until ackedAlmost everything — needs idempotency
Exactly-once (effective)At-least-once + server dedupPayments, orders, inventory

Exactly-once delivery does not exist. Exactly-once processing does.

Idempotency key rules: client generates it · claim + effect in one transaction · store the response, not a flag.

Communication styles

StyleSync/AsyncReach for it when
gRPCSyncInternal service-to-service at volume; typed contract, streaming
RESTSyncPublic APIs, browsers, partners, cacheable reads
GraphQLSyncMany diverse clients over one rich graph
MessagingAsyncFan-out, background work, spike absorption, replay

Each synchronous dependency multiplies into your availability: 4 × 99.9% = 99.6%.

Consistency spectrum

WEAKEST                                                    STRONGEST
Eventual  →  Causal  →  Sequential  →  Strict (linearizable)
ModelGuaranteesExample
EventualConverges once writes stop; stale reads allowedDNS, Cassandra, view counts
CausalDependent operations ordered; unrelated ones aren'tComment threads (reply after parent)
SequentialEach client's program order, one global interleaving; no real-timeSocial feed per friend
Strict / linearizableRead returns the latest write, immediatelyPassword change, account balance

ACID C = the database's own invariants. CAP C = replicas agree. Unrelated.

Linearizable = recency, single objects. Serializable = isolation, transactions. Strict serializable = both.

Session guarantees (per client — cheap)

GuaranteePrevents
Read-your-writes"My edit didn't save"
Monotonic readsContent disappearing on refresh
Monotonic writesRename landing before create
Writes-follow-readsReply visible before its parent

Implement with a version watermark: returned on write, echoed on read, keyed to the user not the connection.

CAP and PACELC

if (Partition)  then Availability or Consistency
Else            then Latency      or Consistency
  • P is not optional. The real choice during a partition is CP or AP.
  • CP when a wrong answer beats no answer being false: ledgers, credentials, inventory, blocks.
  • AP when uptime wins: feeds, carts, DNS, catalogs, metrics.
  • The ELSE branch governs your p99 every single day — a strong read costs a quorum round trip.
  • r + w > n is what makes read and write sets intersect. Latency = the slowest node in the quorum.

Failure models

EASY ────────────────────────────────────────────── HARD
Fail-stop → Crash → Omission → Temporal → Byzantine
ModelNode behaviorMitigation
Fail-stopHalts, detectablyRemove from pool
CrashHalts silentlyHeartbeats + timeouts
OmissionDrops some messagesAcks, retries, per-node success rates
TemporalCorrect but too lateDeadlines, hedging, load shedding
ByzantineArbitrary / wrong / lyingChecksums, signatures, 3f+1 quorums

Replicas to tolerate f failures: 2f + 1 crash, 3f + 1 Byzantine.

Quick decision cues

  • Caller needs the answer to respond → synchronous; otherwise → queue it
  • Internal and high-volume → gRPC; browser or partner-facing → REST
  • Retrying a write → it needs an idempotency key
  • Multi-hop call chain → propagated deadlines, not per-hop timeouts
  • Dependency is down, not slow → circuit breaker, fail fast
  • "User can't see their own change" → read-your-writes, not strong consistency
  • Stale read is merely cosmetic → eventual
  • Stale read is a safety or money bug → linearizable
  • Node is slow, not dead → shed and fence, don't evict
  • Dashboards green, users angry → gray failure; measure client-side

Work the Interview Walkthrough section for these ideas applied end to end, and the Concept Drills for the rapid-fire versions.

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue