How Distributed Systems Fail: A Field Guide to the Bugs You Cannot Test For
Real production failures from Google, Amazon, Facebook, and Cloudflare — and the engineering principles that prevent the bugs you only discover when your system is already breaking.
On October 4, 2021, Facebook went offline for approximately six hours. It was not a partial outage or degraded performance. The entire property, including Instagram, WhatsApp, and the internal tools Facebook engineers use to diagnose and fix outages, became unreachable simultaneously. The initiating event was a routine BGP configuration change that accidentally withdrew the BGP routes advertising Facebook’s network to the rest of the internet. Routers worldwide stopped knowing how to reach Facebook’s servers. DNS resolution failed. The cascading effect was that Facebook’s internal systems, which relied on the same infrastructure, also became unreachable, which meant the engineers responding to the incident could not use their normal tools to fix it. Some of them had to drive to a data center and physically access servers because remote access was down.
The configuration change that triggered this was reviewed. It passed automated checks. It was deployed by a qualified engineer following a standard process. None of that was sufficient to prevent a six-hour global outage because the failure mode it triggered, a cascading infrastructure collapse caused by a single authoritative routing withdrawal, was not something the deployment process was designed to test for.
That is the class of bug this article is about. Not the ones that fail loudly and immediately, which are easy to find and fix, but the ones that corrupt state silently, pass all your tests, and only surface under conditions that staging environments are not designed to reproduce.
Clock skew and the illusion of time
Every distributed system implicitly assumes that clocks agree. When service A records a timestamp of 14:32:07.823 and service B records 14:32:07.819 for events that happened in sequence, the ordering looks backwards. If your system uses timestamps to determine causality, you now have a bug that presents as data corruption but is actually a time synchronisation issue.
NTP keeps clocks synchronised to within a few milliseconds on a well-configured network. That sounds precise until you consider that a database transaction, a cache invalidation, or a message queue acknowledgement can execute in under a millisecond. NTP’s margin of error is not a rounding error. It is the same order of magnitude as the operations themselves.
The 2012 leap second incident demonstrated this at scale. When the IANA added a leap second to UTC, systems that had not handled the edge case correctly experienced CPU spikes, crashes, and incorrect time calculations simultaneously across the internet. Reddit, LinkedIn, and Mozilla all experienced outages. The bug was not in any single service. It was in the implicit assumption that wall clock time would increase monotonically.
The practical consequence: never use wall clock time to establish causality between events in a distributed system. Logical clocks exist precisely because physical clocks cannot be trusted to establish ordering across machines.
Lamport timestamps are the simpler of the two main logical clock schemes. Every process maintains a counter. Each time a process performs an event it increments its counter. Each time it receives a message it updates its counter to be greater than both its own counter and the sender’s counter. This gives you a partial ordering of events consistent with causality: if event A happened before event B, then A’s timestamp is less than B’s. The inverse is not guaranteed. Two events with the same Lamport timestamp may or may not be causally related. Vector clocks address this by maintaining a counter per process rather than a single counter per message. With vector clocks, you can determine whether any two events are causally related, concurrent, or ordered.
Google’s TrueTime API, used in Spanner, takes a different approach: it acknowledges uncertainty explicitly. Instead of returning a single timestamp, it returns an interval [earliest, latest] representing the range within which the true time falls. Spanner waits out the uncertainty interval before committing a transaction, which gives it external consistency at the cost of commit latency. This is not a hack. It is the correct engineering response to the fact that clocks lie: bound the uncertainty explicitly and design around it.
Network partitions and split brain
The CAP theorem says a distributed system can guarantee at most two of consistency, availability, and partition tolerance simultaneously. Since network partitions are not optional, you are always choosing between consistency and availability during a partition. Most systems make this choice implicitly, which means they have a bug waiting for the next network event to expose it.
The split brain scenario is the most dangerous consequence of this implicit choice. Two nodes each believe they are the primary. Both accept writes. When the partition heals, they have diverging state and no clear resolution rule. The 2011 Amazon EC2 US-East outage involved a network event that triggered a cascade of EBS volume failures, partly because the system’s internal state became inconsistent in ways that the recovery procedures were not designed to handle.
The mechanism that prevents split brain is a quorum: a majority of nodes must agree before any node can act as primary. Raft and Paxos both enforce this. A Raft cluster with five nodes requires three to agree on a leader. If a partition isolates two nodes from three, the two-node partition cannot elect a leader and goes into read-only mode. The three-node partition continues operating normally. When the partition heals, the two-node partition rejoins as a follower. There is no negotiation, no case where both partitions have continued accepting writes.
The Zookeeper implementation exposes a subtler failure mode. A client connected to a minority partition can read stale data because its node stopped receiving updates, but the connection remains open. The client has no way to know from the connection itself that it is in a degraded state. This is why Zookeeper provides watch notifications for state changes rather than expecting clients to poll, and why applications built on Zookeeper need to handle the case where a watch fires because the session expired during a partition rather than because the watched data changed.
Stale reads and temporal correctness
The standard cache invalidation problem is well understood: cache a value, update the source, serve the stale cached version until the TTL expires. The window of incorrectness is the TTL. Engineers accept this trade-off explicitly, set TTLs to something that feels appropriate, and move on.
The temporal authorization correctness problem is the same mechanism applied to security decisions, where the consequences of serving stale data are not a user seeing an outdated count but a suspended user continuing to access a system they no longer have permission to reach.
Consider a system where users can be suspended. The suspension takes effect immediately in the user database. The user holds a JWT issued before the suspension with a one-hour expiry. For the duration of the token’s remaining lifetime, the user can continue making authorised API requests. The token is not stolen, not forged, not replayed. It is simply stale. Standard JWT validation accepts it because standard JWT validation checks the signature and the expiry, not the current state of the authorisation decision.
This generalises beyond user suspension. A permission is downgraded. A group membership is removed. A role is deleted. An access policy is tightened. Any change to the authorisation model that occurs after token issuance creates a window during which the token represents a permission that no longer exists. The OAuth specification addresses token forgery, theft, and replay. It does not address this.
Token introspection endpoints allow the resource server to check token validity with the authorisation server on each request, at the cost of a round trip. Revocation lists allow the resource server to check revocation without a round trip, at the cost of propagation latency. Short-lived tokens reduce the window. None of these is a complete solution. They all trade off the size of the incorrectness window against the cost of reducing it.
The Auth Invariant Tester, published as a preprint on IEEE TechRxiv, introduces executable invariants that test temporal correctness directly: assertions that a token representing a permission should fail after that permission has been revoked, that a zombie token from a suspended user should not authenticate, that a policy change should propagate to all enforcement points within a defined time bound. These invariants do not test whether the authorisation system is correctly implemented at a point in time. They test whether it maintains correctness as the system evolves.
Zombie processes and the fencing problem
When a distributed lock manager grants a lock to process A, process A goes into a long garbage collection pause, and the lock expires, the lock manager grants the lock to process B. Process B acquires the lock and begins writing. Process A resumes from its GC pause still believing it holds the lock and also begins writing. Both processes are writing to the same resource simultaneously. The lock failed because it could not account for the fact that process A would stop responding mid-execution.
This is not theoretical. The JVM’s garbage collector can pause for hundreds of milliseconds on large heaps. A distributed lock with a TTL shorter than the GC pause will expire before the holder resumes. This scenario has caused real data corruption in production systems.
Fencing tokens solve this. When the lock manager grants a lock, it issues a monotonically increasing fencing token alongside it. Every write operation must include the current fencing token. The storage system rejects writes with a token lower than the highest token it has seen. When process A resumes and attempts to write with its stale token, the storage system rejects the write because process B has already written with a higher token. The zombie process’s writes are rejected without the storage system needing to know anything about lock expiry or process state.
Martin Kleppmann’s analysis of the Redlock algorithm argued that even carefully designed distributed lock implementations are vulnerable to this class of failure without fencing tokens. Redlock, a distributed locking algorithm for Redis, was proposed by the Redis team. Kleppmann argued it does not provide the safety guarantees it claims under scenarios involving clock skew and process pauses. Antirez, the Redis creator, provided a detailed counter-argument. The debate remains unresolved in the community. What is not in dispute: any system that requires strict mutual exclusion and operates in an environment with GC pauses or process suspensions needs fencing tokens, regardless of which lock implementation it uses.
Message ordering and exactly-once delivery
Message queues promise delivery guarantees: at-most-once, at-least-once, or exactly-once. Exactly-once is the one every engineer wants. Apache Kafka’s documentation for many years described its exactly-once semantics as “in beta,” which is an unusually honest acknowledgement of how difficult the guarantee actually is to implement.
The fundamental tension: to guarantee at-least-once delivery, a queue must be willing to redeliver a message if it does not receive an acknowledgement. Retries mean that a consumer might process the same message twice if the consumer processed the message and then crashed before sending the acknowledgement. Exactly-once delivery requires either that consumers are idempotent or that the queue and consumer participate in a distributed transaction.
Idempotency keys are the practical solution for most scenarios. Stripe pioneered their use in payment APIs: every API request includes a client-generated idempotency key, and the server stores the result of the first request with that key. Subsequent requests with the same key return the cached result without reprocessing. The guarantee is not that the request is only sent once, but that it is only processed once. Payment APIs require this because charging a customer twice for the same transaction is worse than failing to charge them at all.
Kafka’s transactions API provides genuine exactly-once semantics for producers within a single Kafka cluster by combining idempotent producers, where each message has a sequence number so duplicates can be detected, with transactional producers, where multiple writes to different partitions are committed atomically or not at all. This is a real implementation of exactly-once semantics, not a marketing approximation. It is also why Kafka’s transactional producer has higher latency: the protocol involves multiple round trips to ensure atomicity.
Cascading failures and the thundering herd
The most expensive production incidents are rarely caused by a single failure. They are caused by a single failure that triggers a recovery behaviour that makes the situation worse, which triggers more recovery behaviour, which makes the situation worse still.
The Facebook BGP incident from the opening of this article is a clear example. The BGP withdrawal made DNS resolution fail. Clients that could not resolve DNS began retrying. The retry traffic created load on infrastructure that was already degraded. When Facebook began restoring routes, the flood of reconnecting clients created a surge that exceeded the capacity of their load balancers. The recovery itself became a source of load.
Circuit breakers exist to interrupt this pattern. When the failure rate of calls to a dependency exceeds a threshold, a circuit breaker opens and begins returning errors immediately without attempting the call. The purpose is to give the failing dependency time to recover without being overwhelmed by retry traffic, and to give the calling service’s thread pool time to recover by not waiting for connections that will time out anyway.
The Netflix Hystrix library popularised circuit breakers in the microservices ecosystem. Its implementation uses three states: closed (normal operation), open (failing fast), and half-open (testing whether the dependency has recovered by allowing a small number of requests through). The transition from half-open back to closed requires a success threshold, not just a single success, to prevent flapping.
Bulkheads extend the same principle from single dependencies to groups of dependencies. A service that calls three downstream services and uses a shared thread pool will exhaust the thread pool if one downstream service is slow, starving the other two. Bulkheads partition the thread pool so each downstream dependency gets its own allocation. The name comes from ship design: watertight compartments prevent a single breach from sinking the entire vessel.
Distributed tracing and the observability gap
The bugs described in this article share a common property: they are invisible in logs from any single service. A stale authorisation token produces a successful HTTP 200 response. A fencing token rejection might surface as a generic write error. A clock skew causality inversion looks like a data consistency issue. A cascading failure looks like high latency until it looks like a timeout until it looks like an outage. Understanding what actually happened requires correlating events across multiple services.
Distributed tracing solves this by propagating a trace context through every service call. Each incoming request receives a trace ID. Every outbound call includes that trace ID in a header, typically traceparent in the W3C trace context standard. Every span within a trace records its start time, end time, service name, and relationship to its parent span. When an incident occurs, querying by trace ID shows the complete journey of the request across every service, with timing.
The 2019 Cloudflare outage that took approximately 20% of internet traffic offline for 27 minutes was diagnosed in part through distributed tracing. A badly written regular expression in their WAF rules introduced catastrophic backtracking, consuming CPU across all edge nodes simultaneously. The tracing data showed which rule was responsible and in which order the degradation spread.
OpenTelemetry has become the standard instrumentation API for distributed tracing. It provides a vendor-neutral layer for instrumenting applications, exporting trace data to any compatible backend. Jaeger and Zipkin are examples of backends that accept OpenTelemetry data, Jaeger and Zipkin have not been replaced by OpenTelemetry. OpenTelemetry is the instrumentation standard; Jaeger and Zipkin are the storage and query backends. An application instrumented with OpenTelemetry can export to either without changing its instrumentation code.
Sampling is a practical necessity: tracing every request at full fidelity is expensive. Head-based sampling makes the sampling decision at the start of a trace, which means it cannot selectively sample interesting traces. Tail-based sampling makes the decision after the trace completes, allowing every trace that resulted in an error or exceeded a latency threshold to be retained. The trade-off is that tail-based sampling requires buffering complete traces before making the sampling decision, which adds memory pressure and introduces a delay.
The bugs in this article are not edge cases. Clock skew affects every distributed system that uses timestamps for ordering. Split brain is the default failure mode of any distributed system that does not enforce quorum. Stale authorisation tokens exist in every system that uses JWTs with non-trivial lifetimes. Zombie processes affect any system that uses distributed locks in an environment with garbage collection. Message redelivery affects every system that requires at-least-once delivery without idempotency. Cascading failures affect any service with synchronous dependencies and no circuit breakers.
The common thread is that all of them pass unit tests, most of them pass integration tests, and none of them surface under normal operating conditions. They surface under the specific combination of load, timing, and failure that your testing environment was not designed to reproduce. The only defences are understanding the failure modes before they occur, instrumenting your system well enough to detect them when they do, and designing the recovery path to avoid making the situation worse.
Research for this article draws on published postmortems from Facebook, Amazon, Cloudflare, and GitHub, the Raft and Paxos consensus papers, Martin Kleppmann’s analysis of Redlock, and original research on temporal authorization correctness published as a preprint on IEEE TechRxiv.
If you want to go deeper on how Rust’s type system eliminates specific categories of these bugs at compile time: Zero to Rust: A Systems Programmer’s Field Guide — $7 · Free 20-page sample
Many distributed systems failures originate inside the components that power them: queues, caches, indexes, trees, graphs, and concurrent data structures.
Ownership vs. Reference: Data Structures and Algorithms in Rust and Java builds these foundations from scratch in both languages.
For DSA in Java and Rust; companion repository


