Amazon’s CTO, Werner Vogels, likes to say: “Everything fails all the time.”
He doesn’t mean bad code. He means normal life in a data centre. Networks drop packets. Disks die. Servers reboot without warning. A database suddenly goes read-only. A service you depend on gets slow. Traffic spikes. And someone pushes a bad config on a Friday evening.
So an architect asks a different question from a beginner:
“Not “what if this fails?” but “when this fails, what happens?””
A developer writes the happy path, where everything works. An architect also designs the unhappy path, where something is broken and the system still has to behave.
This article opens the Reliability & fault tolerance thread. We’ll cover the mindset and the four basic tools: failing fast, removing single points of failure, failover and graceful degradation.
What one slow service can do
Picture a simple chain: a user calls Service A, which calls Service B, which talks to a database. Now Service B goes down, but not cleanly. It just stops answering.
Without any failure design, this happens:
- Service A sends a request to B and waits. And waits.
- More users arrive. Each request grabs a thread in A and waits too.
- A runs out of threads (or database connections). It can’t serve anything, not even pages that never needed B.
- The load balancer marks A as unhealthy and sends its traffic to the other A servers.
- They fill up the same way. Now the whole of Service A is down.
One broken service took down a healthy one. This is called a cascading failure, and it’s how small problems become big outages.
With failure design, the same outage looks very different. A gives up on B after 2 seconds, shows a fallback (say, cached data or a “try again soon” message), and keeps serving everything else. Only one feature is affected.
Principle 1: Fail fast
A fast “no” is better than a slow “maybe”. If B is down, you want to find out in 2 seconds, not 30. Every second you wait, a thread is stuck and a user is staring at a spinner.
The simplest tool is a timeout on every call to something outside your process: other services, databases, caches, outside APIs.
// Java 21 · never wait forever on another service
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(1)) // give up connecting after 1 s
.build();
HttpRequest request = HttpRequest.newBuilder(URI.create(inventoryUrl + "/stock/" + productId))
.timeout(Duration.ofSeconds(2)) // give up waiting for an answer after 2 s
.build();
try {
return client.send(request, BodyHandlers.ofString()).body();
} catch (HttpTimeoutException e) {
log.warn("Inventory is slow, using fallback for {}", productId);
return StockStatus.UNKNOWN; // degrade, don't hang
}
Many HTTP clients and database drivers have no timeout by default, or one that is far too long. Check every one.
Principle 2: Contain the blast radius
The blast radius is how much of the system is hurt when one part breaks. Your goal is to keep it small.
Ships do this with bulkheads: walls that split the hull into sealed sections. A hole floods one section, and the ship stays afloat. In software, the same idea means giving each dependency its own pool of threads or connections. If calls to B use their own pool of 20 threads, a stuck B can use up those 20, but never the threads that serve the rest of the app.
Timeouts, bulkheads, circuit breakers and retries are the everyday tools here. We’ll look at each in detail in the next article on resilience patterns. For now, remember the goal: one failure, one feature, not the whole site.
Find and remove single points of failure
A single point of failure (SPOF) is any part whose failure takes down the whole system. If there’s only one of something on the critical path, it’s a SPOF.
The usual suspects:
- one load balancer
- one database, with no replica
- one message queue broker
- one DNS provider
- one login or auth service
- everything in one data centre or availability zone
The fix is redundancy: run at least two of everything that matters, and spread them out. Put app servers in three availability zones (separate data centres in one region). If one zone goes dark, you lose a third of your capacity, not all of it. That’s why you size each zone to take extra load when another one fails.
Redundancy isn’t free. Two of everything costs more, and keeping copies in step adds work. Spend it on the critical path first: the parts a user can’t do without.
Failover: switching to the backup
Having a spare is only half the job. Failover is the act of moving traffic to the spare when the main one fails, ideally automatically. There are two common styles.
| Active-passive | Active-active | |
|---|---|---|
| How it works | One node takes traffic. A standby waits and takes over if it fails | All nodes take traffic all the time |
| Switch-over time | Seconds to a minute or so, while the standby is promoted | Almost none: the others just take more load |
| Wasted capacity | The standby sits idle | None |
| Complexity | Simpler, and consistency is easier | Harder: data must be kept in sync across nodes |
| Typical use | Primary database with a standby replica | Stateless app servers behind a load balancer |
A common setup uses both: active-active app servers (easy, because they hold no data) in front of an active-passive database (harder to run with many writers).
Failover has two classic traps:
- Split brain. The network between the primary and the standby breaks. Each thinks the other is dead, so the standby promotes itself, and now two primaries accept writes. When the network heals, you have two versions of the truth. The fix is to promote only with a majority vote (a quorum, which tools like etcd, ZooKeeper and Raft provide) and to use fencing, so the old primary is blocked from writing.
- Lost writes. Replicas usually lag the primary by a little. If the primary crashes before a write reaches the replica, and the replica is promoted, that write is gone. For data you can’t lose, like payments, wait for at least one replica to confirm a write before saying “done” (synchronous or semi-synchronous replication). It’s slower, and that’s the trade-off: consistency vs speed and availability, the CAP theorem in action.
Graceful degradation: do less, but keep going
When a part fails, the system shouldn’t go all-or-nothing. Graceful degradation means turning off the less important features so the important ones keep working.
To do this, you first sort every feature on a page into three groups:
- Critical: without it, the request has failed. At checkout, that’s taking payment.
- Important, but can wait: stock check, confirmation email. If they fail, carry on and fix it up later.
- Nice to have: recommendations, analytics. If they fail, quietly skip them.
// Java · checkout that degrades instead of failing
public CheckoutResult checkout(CheckoutRequest req) {
PaymentResult payment = payments.charge(req); // critical: if this fails, checkout fails
List<Product> recs;
try {
recs = recommendations.forUser(req.userId(), Duration.ofSeconds(1));
} catch (Exception e) {
recs = List.of(); // nice to have: skip quietly
}
emailQueue.send(new OrderConfirmation(req)); // can wait: queued, retried later
return new CheckoutResult(payment, recs);
}
A fallback is what you serve instead when something fails. Good fallbacks are planned per feature:
| If this fails… | …fall back to | …then to |
|---|---|---|
| Live database read | Cached copy | A clear “temporarily unavailable” message |
| Real-time price from an outside API | Last known price, marked as old | Hide the price, block checkout for that item |
| Personalised feed | Trending items | A generic popular list |
| User preferences | Last saved preferences | Sensible defaults |
Big products do this all the time. When Gmail struggles, it can drop extras like autocomplete and fall back to a basic view where you can still read and send mail.
Test it, or it doesn’t work
A failover you’ve never tried is a hope, not a plan. Backups that were never restored, standbys that were never promoted and alerts that were never fired often fail on the one day you need them.
Netflix made this famous with Chaos Monkey, a tool that randomly shuts down servers in production during working hours. Because servers die every week, the teams build systems that don’t care when one does. The idea is called chaos engineering: break things on purpose, in small, controlled ways, so big failures don’t surprise you.
You don’t need Netflix’s scale to start. Run a game day: in a test environment, kill a server, block the database, slow down a dependency, and watch what happens. Write down the steps to recover (a runbook) while you’re at it.
What breaks, and how to fix it
| What breaks | What you see | The fix |
|---|---|---|
| A slow dependency | Threads pile up, the caller stops answering, and the failure spreads (cascade) | A timeout on every outside call, separate pools per dependency (bulkheads), and a fallback |
| A single point of failure dies | The whole site is down because one box failed | Run at least two, across availability zones, and test the switch-over |
| Split brain during failover | Two primaries accept writes; data conflicts when the network heals | Promote only with a majority vote, and fence off the old primary |
| Writes lost in failover | A confirmed order is missing after the replica takes over | For critical data, wait for a replica to confirm the write before replying |
| Retries make an outage worse | A struggling service gets three times the traffic and falls over | Retry only a few times, with growing waits and random jitter (more in the next article) |
Puzzle 1: the fallback that hid an outage
Three things went wrong at once:
- The data was stale. A price dropped from ₹1,000 to ₹800 in the morning, but the cache still had ₹1,000, so customers were charged the old price.
- The fallback was silent. No alert fired, because nothing looked broken. The outage ran for two hours instead of ten minutes.
- Users saw different things. Servers with a warm cache showed products; servers with an empty cache showed errors.
The fix: a fallback must be visible, time-limited and loud. Mark fallback data as possibly out of date, refuse to use it past a set age (say, 10 minutes), never use it for things like prices at checkout, and fire an alert the moment you start using it.
Puzzle 2: three zones, still down
Redundancy protects you from hardware failures, not from your own mistakes. A few ways all three zones fail together:
- A bad deploy. Version 2 has a crash bug. You roll it to zone A, then B, then C. All down.
- A bad config. Someone sets a timeout to 50 ms instead of 5,000 ms. Every zone times out.
- A shared dependency. All three zones use the same single database. It’s a SPOF in disguise.
- Overload that moves. Zone A gets slow, the load balancer moves traffic to B, B gets overloaded, then C.
The fix: defence in depth. Roll out code to a small slice first (canary deploys), validate config before it ships, remove shared SPOFs, and limit how much traffic any one zone can be handed.
Key takeaways
- Assume everything fails. Ask “when this fails, what happens?” for every part.
- Fail fast. A 2-second timeout beats a 30-second hang. Put a timeout on every outside call.
- Contain the blast radius. One failure should hurt one feature, not the whole site.
- Remove single points of failure on the critical path, and spread copies across zones.
- Choose your failover: active-active for stateless servers, active-passive for most databases. Guard against split brain and lost writes.
- Degrade gracefully. Know what’s critical, what can wait and what can be skipped, and make fallbacks visible.
- Test your failures with game days or chaos engineering. An untested backup is a hope.
This opens the Reliability & fault tolerance thread. Next, we’ll look closely at the resilience patterns that make all this work in code: circuit breakers, bulkheads, and retries with backoff and jitter.
Comments