What it is
A distributed system is a set of programs on different machines that cooperate by sending messages over a network. That sounds like an implementation detail, but it removes three guarantees a single process quietly gives you:
- All-or-nothing failure. One process either runs or has crashed. A distributed system can be half working: some nodes up, some down, some slow.
- Reliable communication. A function call returns or throws. A message can be lost, delayed for an unbounded time, duplicated or reordered, and the sender often cannot tell which.
- A shared clock. One machine has one notion of “now”. Different machines have different clocks that drift apart, get corrected in jumps and stop advancing for a process that is paused.
Almost every technique in this module (consensus, quorums, leader election, logical clocks, consistency models) exists to cope with one of these three.
Why it exists
Nobody distributes a system for fun. You do it because one machine is not enough: not enough capacity, not enough availability (one machine is one failure away from an outage), or too far from users on another continent. The moment the work spans machines, the network and independent failures come with it. The well-known “fallacies of distributed computing” (the network is reliable, latency is zero, bandwidth is infinite, the topology doesn’t change, and so on) are a list of assumptions that silently break.
How it works
Partial failure. Each component fails independently: a crashed process, a full disk, a bad network card, a misconfigured firewall rule, a zone losing power. With hundreds of components, something is broken most of the time. The system has to keep serving with that part missing, and every caller has to treat every remote call as something that can fail.
An unreliable network. In the model most distributed algorithms assume (the asynchronous model), messages can be lost or delayed arbitrarily long, and there is no bound on how long a node takes to answer. A caller that hears nothing cannot distinguish:
- the request was lost (nothing happened),
- the request arrived and the work was done, but the response was lost,
- the remote node crashed before or after doing the work,
- the remote node is just slow (a long garbage-collection pause, a saturated disk, a queue).
So a retry after silence may execute the operation a second time. The standard answer is to make operations idempotent: “set email to x” instead of “append”, or an idempotency key that the receiver stores so it can recognise a duplicate request and return the original result. TCP does not solve this: it retransmits and de-duplicates within one connection, but cannot tell you whether the application on the other side processed your request before the connection broke.
Timeouts as failure detectors. Since there is no reliable signal for “dead”, systems use timeouts: no answer within T, treat the call as failed. A timeout is a trade-off, not a measurement. A short one detects real failures quickly but also declares healthy-but-slow calls dead (wasting their work, and with retries, adding load at the worst moment). A long one avoids false alarms but holds threads, connections and users while a dead node never answers. Health checks, heartbeats and leader leases are all timeouts with thresholds on top.
Unreliable clocks. Quartz clocks drift (tens of parts per million is common, i.e. a few seconds a day uncorrected). NTP keeps machines within milliseconds of each other on a good network, more on a bad one, and corrects them by slewing or by stepping, which can make a clock jump backwards. A virtual machine can be paused and resumed; a process can stall in a stop-the-world GC pause and wake up with stale beliefs (for example, that it still holds a lease). Consequences:
- Comparing timestamps from different machines can order events wrongly. Last-write-wins conflict resolution then silently discards the genuinely newer write.
- Measuring durations should use a monotonic clock, never the wall clock.
- Anything that depends on “I still hold this lease” must account for pauses (fencing tokens).
Some systems bound clock uncertainty explicitly (Google Spanner’s TrueTime waits out the uncertainty interval before committing); most avoid relying on wall time for ordering and use logical clocks, version numbers or a single leader instead.
When to use it
These are not techniques to apply but assumptions to design under. Make them explicit whenever a request crosses a process boundary: microservices, database replicas, caches, message brokers, third-party APIs. A useful habit is to ask of every remote call: what happens if it fails, if it is slow, and if it succeeds but the answer is lost?
When not to
Don’t distribute what one machine can do. A single well-provisioned database server with a hot standby avoids most of this module’s problems and serves a surprising amount of traffic. Many teams adopt microservices or multi-region designs and inherit partial failure, retries and consistency problems they did not need.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Short timeout | Fast detection, threads freed quickly | False alarms on healthy-but-slow calls; wasted work |
| Long timeout | Few false alarms | Callers stuck on dead nodes; resources held |
| Retrying failed calls | Hides transient faults | Duplicate execution unless idempotent; extra load during overload |
| Aggressive health checks | Faster ejection | Flapping, probe load, ejecting nodes that are merely busy |
| Wall-clock timestamps | Simple ordering, human-readable | Silent misordering across machines |
Alternatives
There is no alternative to the underlying problems, only different ways to contain them:
- Fewer machines. Scale up before scaling out where it suffices.
- Avoid synchronous chains. Asynchronous messaging with durable queues turns “the dependency is down” into “the work waits”.
- Stronger primitives. Consensus systems (etcd, ZooKeeper, Raft-based databases) give you agreement despite failures so each service does not reinvent it.
- Synchronous networks with bounded delays exist (some industrial and telecom systems), but general-purpose data-centre networks and the internet are not.
Failure modes
- Retry storms. Every layer retries a failing call three times; a slow dependency receives 27× its normal traffic.
- Gray failure. A node is slow or fails only some requests; it passes health checks, so nobody routes around it.
- Double execution. A timed-out payment request was processed; the retry charges again.
- Split brain. Two nodes each believe the other is dead and both act as leader.
- Clock-based data loss. Last-write-wins with skewed clocks drops the newer write without any error.
- Zombie processes. A process paused past its lease expiry wakes up and writes as if it still owned the resource.
In production
Set a timeout on every remote call, derived from measured latency percentiles, and budget them so the caller’s deadline is not exceeded by its callees’ timeouts plus retries (propagate deadlines). Retry only idempotent operations, with exponential backoff and jitter, and cap retries per request. Use health checks plus passive outlier detection so slow instances get ejected too. Make writes idempotent with request ids. Run NTP or PTP and alert on clock offset, but never rely on cross-machine timestamps for correctness. Test failure deliberately (fault injection, chaos experiments) because these paths are rarely exercised otherwise.
Common misconceptions
- “TCP makes the network reliable.” It makes one connection reliable while it lasts. It cannot tell you whether the far application processed your request before the connection died.
- “If it timed out, it didn’t happen.” It may have happened completely.
- “Our clocks are synced by NTP, so timestamps are safe to compare.” NTP narrows the skew; it does not remove it, and it can step a clock backwards.
- “A node is either up or down.” Slow, overloaded and partially failing nodes are the hard cases.
- “Exactly-once delivery solves it.” Systems that advertise it achieve exactly-once effects by combining at-least-once delivery with idempotence or transactions.
Interview angle
Interviewers listen for whether you treat remote calls as unreliable without being prompted: timeouts on every call, retries with backoff only for idempotent operations, idempotency keys for payments and orders, and health checks for routing. Be ready to explain why a timeout cannot distinguish slow from dead, the two generals problem in one sentence (no protocol over a lossy channel can guarantee both sides agree they agree), and why you would not use wall-clock timestamps to order writes across nodes.
Model assumptions
The simulated steps use a simplified model, not a benchmark. Orders sends 40 calls per second (Poisson arrivals) through a round-robin load balancer to three Inventory instances, each with 4 workers, a 50 ms mean service time (lognormal, cv 0.5) and room for 20 waiting calls. Network hops take a fixed 2–10 ms; the model never loses packets. “10× slower” multiplies the service time; “crashed” refuses connections immediately. Health checks probe every 250 ms and eject after 2 failures. The lost-message and clock-skew steps are scripted illustrations: the packets and annotations are drawn to explain the idea, not produced by the simulation, which models neither packet loss nor clocks. The “Network” node is scenery. Numbers show behaviour and orders of magnitude only.