Sub topic 3
Redundancy: spare capacity that removes single points of failure
This chapter assumes you know basic client-server architecture, what a load balancer does, and how timeouts and health checks work at a high level. It builds on the previous chapter's idea of a single point of failure (SPOF): a component whose failure takes down the whole service.
What redundancy is
Redundancy means running more capacity than the service needs at a given moment, so that when one component fails, another can take over its work. The extra capacity can be an idle standby, a second server that also handles traffic, or a replicated copy of data.
Redundancy does not prevent failures. Components still fail. Redundancy changes what a failure costs: instead of an outage, you get a loss of spare capacity, which you can repair while users keep working.
A system gains nothing from a spare that cannot actually take over. A standby with stale configuration, a backup that has never received traffic, or a second server that shares the first server's power supply all count as redundancy on paper only.
Why it works: the arithmetic
Availability is the fraction of time a component works. When components are chained so that all of them must work, you multiply their availabilities (series). When any one of them is enough, you multiply their failure probabilities and subtract from one (parallel).
def series(*availabilities):
result = 1.0
for a in availabilities:
result *= a
return result
def parallel(*availabilities):
all_down = 1.0
for a in availabilities:
all_down *= (1.0 - a)
return 1.0 - all_down
print(series(0.99, 0.99)) # about 0.9801
print(parallel(0.99, 0.99)) # about 0.9999Two 99% components in series give about 98.01%, which is worse than either one alone. Two in parallel give about 99.99%. The parallel result holds only if the components fail independently. If both share a cause of failure, the real figure is much lower. The next chapter covers how to keep copies independent.
Redundancy at every layer
Parallel redundancy only helps at the layer where you add it. A service is a chain of layers, and the chain is as weak as its least redundant link.
| Layer | Typical SPOF | Redundant form |
|---|---|---|
| Application | One server process | Several instances behind a load balancer |
| Load balancer | One proxy | A pair sharing a virtual IP, or a managed balancer |
| Database | One primary | Primary with replicas |
| Network | One switch or uplink | Two switches, two uplinks |
| Power | One feed | Two independent feeds |
| DNS | One name server | Several name servers |
| People and process | One engineer who knows the system | Documented runbooks, shared on-call |
A common mistake is to run ten application servers behind a single load balancer. The ten servers are redundant. The balancer is not, so the system's availability is capped by the balancer's availability.
In this diagram, the application tier can lose two servers and keep running. Losing the load balancer or the database ends the service. Removing a SPOF means finding the next one, not stopping.
Forms of redundancy
Redundancy appears in several forms. Which one you choose depends on what the component holds.
- Stateless replicas. Identical instances that keep no unique data. Any instance can serve any request, so adding a copy is simple. Web and API servers usually fit here.
- Stateful replicas. Copies that hold data, such as a database primary and its replicas. Adding a copy requires keeping the data in sync, which introduces the consistency and loss trade-offs covered in later chapters.
- Hardware redundancy. Mirrored disks (RAID 1), dual power supplies, bonded network interfaces. These protect against one device failing inside a single machine.
- Information redundancy. Extra data that lets you rebuild lost data, such as parity or erasure codes in storage systems.
- Time redundancy. Repeating an operation after it fails, for example a client retry. This helps with transient faults but not with a dead component.
Stateless is easier than stateful
Making a stateless tier redundant mostly means running more copies and routing around the dead ones. Making a stateful tier redundant means deciding which copy is correct, how fast data reaches the other copies, and what happens if copies disagree. Teams often push state out of the application tier into a database or cache so that the application tier becomes easy to replicate. This does not remove the state problem. It concentrates it in fewer places where you can treat it carefully.
How much spare capacity is enough
Redundancy has a cost, and the useful question is how much spare capacity covers the failures you expect.
Suppose a service needs 4 servers to handle peak load. If you run exactly 4, losing one leaves 3, which is overloaded. Overload often makes the survivors fail too, because they receive the failed server's share of traffic on top of their own.
The rule of thumb is N+1, where N is the number of units needed for the load, plus one spare. With 5 servers, losing one leaves 4, which is enough. N+2 tolerates two simultaneous failures or one failure during maintenance.
A quick check you can run on any pool:
import math
def survives(servers, failures, peak_load, capacity_per_server):
remaining = servers - failures
return remaining * capacity_per_server >= peak_load
# 5 servers, each handling 100 requests per second, peak load 400
print(survives(5, 1, 400, 100)) # True
print(survives(5, 2, 400, 100)) # False
print(math.ceil(400 / 100) + 1) # 5, the N+1 sizeCapacity is measured at peak, not average. A pool sized for average traffic has no spare at the moment you need it.
The cost of N+1 shrinks as the pool grows. One spare for a pool of two is 50% extra capacity. One spare for a pool of ten is 10%. This is one reason larger pools of smaller units are cheaper to protect than a few large machines.
Common errors
These mistakes show up repeatedly in production reviews.
- Hidden shared dependencies. Two servers that both read the same configuration service, certificate, license server, or DNS provider are not independent. List the dependencies of each copy and look for overlap.
- Redundancy that is never exercised. A standby that has never taken traffic often fails the first time it is needed, because of missing credentials, stale code, or closed firewall rules. Chapter 15 covers testing.
- Spares that drift. Manual changes made to the primary and not to the standby leave the spare unable to do the same work. Build all copies from the same automation.
- Redundancy that adds new SPOFs. The mechanism that switches between copies, such as a failover controller or a monitoring system, is itself a component. If it fails or makes a wrong decision, it can cause the outage it was meant to prevent.
- More complexity, more failure. Each redundant component adds configuration, monitoring, and failure modes. Redundancy is worth it where the cost of an outage exceeds the cost of the added complexity. For a low-impact internal tool, one instance with fast recovery may be the better design.
Redundancy is not backup
Backups and redundancy solve different problems. A replica copies every change, including a mistaken DELETE or a corrupted record, within moments. Redundancy protects against hardware and process failure. Backups protect against bad data and human error, because they preserve a point in time you can restore. A serious design needs both.
Finding SPOFs in a design
A practical procedure for reviewing a system:
- Draw the path of one request, from the client to the data store and back.
- For each box on the path, ask: if this stops, does the request still succeed?
- For each box that answers "no", note whether a second copy exists and whether the switch to it is automatic.
- Repeat for supporting systems: authentication, configuration, DNS, certificates, monitoring, and deployment tooling.
- Rank the remaining SPOFs by how likely they are to fail and how much damage they cause. Fix the worst first.
Not every SPOF needs removing. Sometimes the right decision is to accept one, document it, and plan a fast manual recovery. The point is that the decision is made on purpose.
Exercise
A service needs 6 servers to handle peak load, each server is 99% available, and failures are independent. The team runs exactly 6 servers behind one load balancer that is 99.9% available. Name two weaknesses in this design, and state the smallest change that addresses the capacity weakness.
Show answer
First, there is no spare capacity: if any one server fails, 5 servers cannot carry a peak load sized for 6, so users see overload or errors at peak. Second, the single load balancer is a SPOF, so the whole service is capped at 99.9% availability before any server failures are counted. The smallest capacity change is to move to N+1 by running 7 servers, so that one failure still leaves 6. The balancer weakness needs a separate fix, such as a second balancer or a managed balancer.
Exercise
Two components are each 99.5% available. Calculate the availability when they are chained in series, and when they are in parallel with independent failures. Then explain why the parallel number could be wrong in practice.
Show answer
Series: 0.995 x 0.995 = 0.990025, about 99.0%. Parallel: 1 - (0.005 x 0.005) = 1 - 0.000025 = 0.999975, about 99.9975%. The parallel figure assumes independent failures. If both components share a power feed, network switch, software bug, or configuration source, one event can take both down, and the real availability is lower than the calculation.