CMD Guide
HomeSystem DesignAPI Gateway

Availability

An API gateway reaches high availability by running as a fleet of stateless, interchangeable replicas behind a health-checked load balancer — any replica can serve any request, a failed one is detected by active health checks and pulled from rotation before clients notice, and its share is redistributed to the survivors — while refusing to inherit the downtime of the synchronous dependencies (auth, rate-limit store, service discovery) it touches on every request.

That second clause is the part beginners miss. The gateway is a serial chokepoint: every request to every backend passes through it, so its availability multiplies with everything else on the path. If the gateway is down, healthy backends behind it are unreachable anyway. This makes the gateway the tier that must be the most available in the whole system — and it is uniquely easy to accidentally make it the least available, by hanging its request path off a dependency that is flakier than the gateway itself.

Why redundancy alone is not the whole story: the math

Two rules govern availability of a request path:

A single gateway instance at A = 99.5% is down ~3.6 h/month. Put 4 behind a load balancer and the chance that all four are down at once is (0.005)4 ≈ 6×10⁻¹⁰ — on paper >99.9999999%. Redundancy is cheap and powerful. But the serial rule is what actually caps you: the gateway plus its synchronous dependencies form a chain, and one flaky dependency on the hot path drags the whole gateway below the availability of any single box in it.

Translate targets into budgets before promising anything:

AvailabilityDowntime / yearDowntime / month
99% (two nines)3.65 days7.31 hours
99.9% (three nines)8.77 hours43.8 minutes
99.99% (four nines)52.6 minutes4.38 minutes
99.999% (five nines)5.26 minutes26 seconds
diagram
diagram

Worked example: designing a gateway tier to 99.95%

Target: the gateway tier (everything the client hits before the business logic runs) must sustain 99.95% — a budget of ~22 min/month. Walk the serial chain. Values below are typical published/measured figures for managed cloud components.

Path component (all in series)AvailabilityOn the hot path?
Anycast DNS99.999%yes
Managed L4 load balancer, multi-AZ99.99%yes
Gateway fleet (4 replicas / 2 AZ, N+2)99.99%yes
Downstream service99.95%yes
Auth check (JWT validation)99.9%depends on design
Rate-limit store (Redis)99.9%depends on design

Naive design — validate every token by calling the auth service synchronously, and reject requests (fail-closed) whenever Redis is unreachable. Now all six are in series:

0.99999 × 0.9999 × 0.9999 × 0.9995 × 0.999 × 0.999 ≈ 0.9973099.73%, about 119 min/month of downtime (calendar month of 730.5 h — the same convention as the nines table above). The gateway tier is now less available than the 99.9% Redis it leans on, and blows the 99.95% target — even though every individual box is healthier than that.

Decoupled design — validate tokens locally against a cached JWKS (public keys, refreshed in the background; no per-request network call), and fail-open on the rate limiter (if Redis is unreachable, allow the request rather than 500 it). The two flaky dependencies drop off the availability path entirely:

0.99999 × 0.9999 × 0.9999 × 0.9995 ≈ 0.9992999.93%, about 31 min/month. Add a small backend redundancy improvement and you clear 99.95%. Same hardware, same replicas — the ~88 min/month you bought came entirely from taking two dependencies off the critical path, not from adding more gateways.

diagram
diagram

The decoupling mechanism, concretely

Three techniques keep a dependency from lending its downtime to the gateway:

Capacity headroom (N+k). Redundancy only helps if the survivors can carry the load. Size the fleet so that losing an entire AZ still serves peak traffic — if 2 replicas handle peak, run 4 across 2 AZs, not 2 in one AZ. "We had a spare" is worthless if the spare then falls over under the redirected load.

Pitfalls

When to use it / when NOT to

The design decision is how to make the gateway redundant. Three options:

Decision rule: stateless gateway, high-availability target, cost-sensitive at scale → self-managed active-active across AZs. Small team or spiky/uncertain traffic and you value not being paged → managed gateway. Reach for active-passive only when statefulness forces your hand — and treat its failover time as real downtime in your math.

Takeaways


Re-authored and deepened for this guide. Sources: Google, Site Reliability Engineering (Beyer et al.) — availability targets, "nines," and embracing risk; Amazon Web Services Well-Architected Framework, Reliability Pillar — multi-AZ redundancy and static stability; Michael T. Nygard, Release It! — circuit breakers, fail-fast, and bulkheads; Martin Kleppmann, Designing Data-Intensive Applications — serial vs. parallel availability and correlated failures; Envoy and NGINX documentation — active health checking, connection draining, and active-active fronting.

🤖 Don't fully get this? Learn it with Claude

Stuck on Availability? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Availability** (System Design) and want to truly understand it. Explain Availability from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Availability** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Availability** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Availability** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes