Sub topic 12
Design patterns for higher availability
This chapter assumes you know how series and parallel availability combine, what a failure domain is, and how to read short Python snippets. Earlier chapters showed that dependencies in series lower availability, and that redundancy in parallel raises it only when failures are independent. The patterns below put those two facts to work.
The working model
Every pattern does one of three things:
- It removes a component from the serial path.
- It adds an independent copy of a component.
- It shortens recovery, which raises availability through MTTR.
A pattern that does none of these adds complexity without adding nines.
Redundancy with load balancing
Run several identical instances behind a load balancer. A health check removes a failed instance from rotation, so users see no outage while at least one instance works. This is active-active redundancy.
Place the instances in different failure domains, such as separate availability zones. Two instances on one host share a failure domain, so the parallel formula overstates the gain.
The load balancer is now a serial component. If it is a single instance, it caps the availability of the whole tier. Use a managed or replicated load balancer.
Failover
In active-passive failover, a standby takes over when the primary fails. Failover is mostly a recovery-time pattern. The outage lasts as long as detection plus switchover.
def availability_with_failover(mtbf_hours, detect_hours, switch_hours):
mttr = detect_hours + switch_hours
return mtbf_hours / (mtbf_hours + mttr)
# Manual repair: about one hour
print(availability_with_failover(1000, 0.9, 0.1))
# Automatic failover: about 30 seconds
print(availability_with_failover(1000, 0.004, 0.0043))The first call gives about 0.999 and the second about 0.9999917. The failure rate is the same in both. Only recovery changed.
A common error is an untested standby. A failover path that has never run often fails the first time it is needed. Exercise it regularly.
Timeouts, retries, and circuit breakers
A slow dependency can be as damaging as a failed one, because requests pile up and exhaust threads or connections. Three controls limit the damage:
- Timeouts bound how long a call may wait.
- Retries with exponential backoff and jitter recover from brief errors. Retrying without backoff multiplies load on a struggling service and can turn a partial outage into a full one.
- Circuit breakers stop calls to a dependency that keeps failing, then probe it occasionally to see if it has recovered.
Graceful degradation
Turn a hard dependency into a soft one. If a recommendations service is down, show a generic list. If a cache is down, read from the database more slowly. The page still loads, so the request counts as successful and the recommendations service leaves the serial path for that request.
Decide in advance which features are essential. Everything else should be allowed to fail without failing the request.
Isolation and limiting blast radius
Split the system into cells, each serving a subset of users with its own copy of the stack. A failure or bad deployment affects one cell, not everyone. Similar ideas include separate thread pools per dependency, called bulkheads, and rate limits per client.
Deployments cause many outages, so reduce their risk with canary releases, gradual rollouts, and fast rollback. Rollback speed is an MTTR improvement.
Choosing a pattern
| Pattern | Main effect | Main cost |
|---|---|---|
| Active-active redundancy | Raises availability through parallel copies | More infrastructure, data consistency work |
| Automatic failover | Cuts MTTR | Detection tuning, risk of false failover |
| Circuit breakers and timeouts | Stops cascading failures | Extra configuration to tune |
| Graceful degradation | Removes soft dependencies from the serial path | Product decisions, extra code paths |
| Cells and canaries | Limits blast radius | Operational complexity |
Exercise
A service has two application instances behind a single load balancer instance. Each part has 99.9% availability and failures are independent. Assuming the instances are in parallel and the load balancer is in series with them, what is the approximate availability, and which change helps most?
Show answer
The instances give 1 - (0.001 × 0.001) = 0.999999. In series with the load balancer: 0.999999 × 0.999 ≈ 0.999, or about 99.9%. The single load balancer dominates, so replicating it helps most. Adding more app instances would barely change the result.