Day 13: Timeouts, Circuit Breakers, Cascading Failures
Goal: One hanging component must not drag down the whole system. You make the database vanish without it reporting errors, watch link creation take redirects down with it, and build three layers of protection: timeouts in
kurz, a circuit breaker in front of the database, and timeouts with retries at the load balancer · Duration: approx. 90 min · Prerequisite: Day 12
Briefing
- A service that crashes is harmless: connections fail immediately, and the load balancer takes it out (Day 4). The dangerous one is a service that hangs: it accepts connections or simply lets packets vanish, but never answers. Every request waits until someone gives up.
- On Day 4, single requests hung for 26.8 seconds; on Day 8, an INSERT
hung until
curlgave up. Today you turn that into a pattern: waiting requests occupy slots, connections and memory. Once all of them are taken, even requests that don’t need the hanging component fail. That is a cascading failure. - The countermeasures: every wait gets a limit (timeout), shorter on the inside than on the outside. Whoever keeps failing stops asking for a while (circuit breaker). And whatever can be retried without risk gets retried on another server.
| Term | Meaning |
|---|---|
| black hole | packets vanish without an answer, here with
iptables … -j DROP |
| timeout budget | each layer waits a little longer than the layer behind it |
| circuit breaker | closed: everything passes; open: reject immediately; half-open: one probe |
| cascade | a failure in one place consumes resources that other paths need |
504 |
Gateway Timeout: the load balancer waited too long for the instance |
By the end of the day, kurz gives up after 2 seconds, a
circuit breaker protects link creation, the replica gets 300 ms, and
HAProxy retries hanging redirects on the other server.
Drill 1: A Black Hole
kurz writes via PgBouncer on s3, port 6432. A rule on s3
makes all packets to this port vanish. To kurz, the
database then doesn’t look broken, just silent:
# on s1
mkdir -p ~/sd/tag13 && cd ~/sd/tag13 && cp ~/sd/tag12/anlegen.js ~/sd/tag12/klick.js ~/sd/tag12/codes.txt .
time curl -s -o /dev/null -w "%{http_code}\n" -X POST localhost/api/links -d "{\"url\":\"https://example.org/tag13/vorher-$(date +%s)\"}"
ssh s3 "sudo iptables -I INPUT -p tcp --dport 6432 -j DROP"
time curl -s -o /dev/null -w "%{http_code}\n" -X POST localhost/api/links -d "{\"url\":\"https://example.org/tag13/schwarz-$(date +%s)\"}"
time curl -s -o /dev/null -w "%{http_code}\n" localhost/c170720
ssh s3 "sudo iptables -D INPUT -p tcp --dport 6432 -j DROP"Expected (shortened to the real
lines):
201
real 0m0.122s
504
real 0m30.039s
302
real 0m0.098s
Link creation waits exactly 30 seconds, then HAProxy gives up
(timeout server 30s from the base configuration) and
answers 504. kurz itself would have waited
forever: it has no limit of its own. The redirect works because
c170720 is in the cache and reads go through the replica on
s2 anyway. After the rule is deleted, the old connections keep working;
TCP simply resends the lost packets.
Save your progress? Sign up for free
Drill 2: The Cascade
What happens under load? 300 redirects and 30 creates per second; after 10 seconds the database vanishes for 20 seconds:
# on s1
k6 run -q -e RATE=300 -e DAUER=40s klick.js > klick.log 2>&1 &
k6 run -q -e RATE=30 -e DAUER=40s anlegen.js > anlegen.log 2>&1 &
sleep 10; ssh s3 "sudo iptables -I INPUT -p tcp --dport 6432 -j DROP"; echo "$(date +%T) s3:6432 schwarzes Loch"
sleep 20; ssh s3 "sudo iptables -D INPUT -p tcp --dport 6432 -j DROP"; echo "$(date +%T) wieder offen"
wait
echo "== Klicks"; grep -E 'checks_succeeded|http_req_duration\.' klick.log
echo "== Anlegen"; grep -E '^ +[✓✗] |↳|http_req_duration\.' anlegen.logExpected:
20:33:15 s3:6432 schwarzes Loch
20:33:37 wieder offen
== Klicks
checks_succeeded...: 35.30% 4237 out of 12000
http_req_duration..............: avg=16.62ms min=1.13ms med=21.37ms max=576.32ms p(90)=22.48ms p(95)=22.76ms
== Anlegen
✗ 201
↳ 32% — ✓ 394 / ✗ 807
✗ 429
↳ 0% — ✓ 0 / ✗ 1201
✗ 503
↳ 64% — ✓ 775 / ✗ 426
http_req_duration..............: avg=283.56ms min=4.17ms med=21.56ms max=10s p(90)=22.69ms p(95)=23.71ms
Only 35% of the redirects succeeded, although not a single one needs
the write database. The load shedding from Day 12 explains it: each
instance accepts 16 requests at a time. The hanging create requests
occupy these slots for 30 seconds each; after one second, all 32 are
full. Every further request, no matter which, waits 20 ms in HAProxy and
gets 503. The limit that protected the system yesterday
turns a write problem into a total outage today.
Save your progress? Sign up for free
Drill 3: Timeouts in kurz
The first layer: every request gets a maximum duration in its
context. All database and cache accesses take this context
along and abort when it expires. Default: 2 seconds.
# on s1
cd ~/kurz && cp main.go /tmp/main.go.alt
perl -0pi -e 's/(\tverzoegerung, _ = [^\n]*\n)/$1\t\/\/ Höchstdauer einer Anfrage: danach bricht kurz Datenbank- und Cache-Zugriffe ab\n\tanfrageTimeout, _ = time.ParseDuration(env("KURZ_TIMEOUT", "2s"))\n/' main.go
perl -0pi -e 's/\t\tw.Header\(\).Set\("X-Kurz-Instanz", instanz\)\n\t\tmux.ServeHTTP\(w, r\)\n/\t\tw.Header().Set("X-Kurz-Instanz", instanz)\n\t\tctx, cancel := context.WithTimeout(r.Context(), anfrageTimeout)\n\t\tdefer cancel()\n\t\tmux.ServeHTTP(w, r.WithContext(ctx))\n/' main.go
diff /tmp/main.go.alt main.go
go vet . && go build -o kurz . && echo gebautExpected:
27a28,29
> // Höchstdauer einer Anfrage: danach bricht kurz Datenbank- und Cache-Zugriffe ab
> anfrageTimeout, _ = time.ParseDuration(env("KURZ_TIMEOUT", "2s"))
101c103,105
< mux.ServeHTTP(w, r)
---
> ctx, cancel := context.WithTimeout(r.Context(), anfrageTimeout)
> defer cancel()
> mux.ServeHTTP(w, r.WithContext(ctx))
gebaut
Roll out with the loop from Day 11, then send one request into the black hole and run the load from Drill 2:
# on s1
cd ~/sd/tag13
ssh s3 "sudo iptables -I INPUT -p tcp --dport 6432 -j DROP"
time curl -s -w "%{http_code}\n" -X POST localhost/api/links -d "{\"url\":\"https://example.org/tag13/schwarz-$(date +%s)\"}"
ssh s3 "sudo iptables -D INPUT -p tcp --dport 6432 -j DROP"Expected (shortened):
Datenbankfehler
503
real 0m2.040s
Two seconds instead of 30, and the answer comes from
kurz itself, not from the load balancer. The same load as
in Drill 2 once more (commands from there):
20:35:01 s3:6432 schwarzes Loch
20:35:22 wieder offen
== Klicks
checks_succeeded...: 67.96% 8156 out of 12001
http_req_duration..............: avg=10.57ms min=1.03ms med=4.43ms max=73.07ms p(90)=22.17ms p(95)=22.5ms
== Anlegen
✗ 201
↳ 47% — ✓ 567 / ✗ 633
✗ 429
↳ 0% — ✓ 0 / ✗ 1200
✗ 503
↳ 52% — ✓ 633 / ✗ 567
http_req_duration..............: avg=584.73ms min=3.88ms med=21.41ms max=2.02s p(90)=2.01s p(95)=2.01s
Better, but not good: 68% instead of 35%. Little’s Law from Day 2 does the math: 30 creates per second, each holding its slot for 2 seconds, makes 60 occupied slots. There are only 32. A timeout limits the damage per request, but as long as every request tries first, every one pays the full wait.
Save your progress? Sign up for free
Drill 4: A Circuit Breaker
A circuit breaker remembers that the last attempts failed and stops asking. After 5 server errors in a row, it rejects every create immediately for 5 seconds. Then it lets exactly one request through as a probe: if it succeeds, the breaker is closed again.
# on s1
cd ~/kurz && cp main.go /tmp/main.go.alt
cat > sicherung.go <<'EOF'
package main
import (
"log"
"net/http"
"sync"
"time"
)
// sicherung ist ein einfacher Circuit Breaker: Nach `schwelle` Serverfehlern in Folge
// lehnt er `pause` lang alles sofort ab (offen). Danach lässt er eine einzige Probe
// durch (halb offen). Gelingt sie, ist er wieder geschlossen, sonst wieder offen.
type sicherung struct {
mu sync.Mutex
schwelle int
pause time.Duration
fehler int // Serverfehler in Folge
offenBis time.Time // bis dahin sofort ablehnen
probe bool // halb offen: eine Probe ist unterwegs
}
var schreiben = &sicherung{schwelle: 5, pause: 5 * time.Second}
func (s *sicherung) erlaubt() bool {
s.mu.Lock()
defer s.mu.Unlock()
if time.Now().Before(s.offenBis) {
return false
}
if s.fehler >= s.schwelle { // halb offen
if s.probe {
return false
}
s.probe = true
}
return true
}
func (s *sicherung) melde(serverfehler bool) {
s.mu.Lock()
defer s.mu.Unlock()
s.probe = false
if !serverfehler {
if s.fehler >= s.schwelle {
log.Printf("%s: Sicherung geschlossen", instanz)
}
s.fehler = 0
return
}
s.fehler++
if s.fehler >= s.schwelle {
s.offenBis = time.Now().Add(s.pause)
log.Printf("%s: Sicherung offen für %s (%d Fehler in Folge)",
instanz, s.pause, s.fehler)
}
}
// statusMerker merkt sich den Status, den ein Handler sendet.
type statusMerker struct {
http.ResponseWriter
status int
}
func (m *statusMerker) WriteHeader(status int) {
m.status = status
m.ResponseWriter.WriteHeader(status)
}
// gesichert: Ist die Sicherung offen, antwortet kurz sofort mit 503.
func gesichert(s *sicherung, next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if !s.erlaubt() {
w.Header().Set("Retry-After", "5")
http.Error(w, "Datenbank gestört", http.StatusServiceUnavailable)
return
}
m := &statusMerker{ResponseWriter: w, status: http.StatusOK}
next(m, r)
s.melde(m.status >= 500)
}
}
EOF
perl -pi -e 's/"POST \/api\/links", idempotent\(anlegen\)\)/"POST \/api\/links", gesichert(schreiben, idempotent(anlegen)))/' main.go
diff /tmp/main.go.alt main.go
go vet . && go build -o kurz . && echo gebautExpected:
95c95
< mux.HandleFunc("POST /api/links", idempotent(anlegen))
---
> mux.HandleFunc("POST /api/links", gesichert(schreiben, idempotent(anlegen)))
gebaut
The circuit breaker counts only server errors (5xx). A
400 for a broken URL says nothing about the database. Roll
out, then send eight creates directly to the instance on s1 so that all
of them hit the same breaker:
# on s1
cd ~/sd/tag13
ssh s3 "sudo iptables -I INPUT -p tcp --dport 6432 -j DROP"
for i in $(seq 8); do curl -s -o /dev/null -w "%{http_code} %{time_total}s %header{x-kurz-instanz}\n" -X POST http://s1:8080/api/links -d "{\"url\":\"https://example.org/tag13/s-$i-$(date +%s)\"}"; done
ssh s3 "sudo iptables -D INPUT -p tcp --dport 6432 -j DROP"
sleep 5
curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" -X POST http://s1:8080/api/links -d "{\"url\":\"https://example.org/tag13/probe-$(date +%s)\"}"
journalctl -u kurz --since "-1min" -o cat | grep SicherungExpected:
503 2.004577s s1
503 2.003899s s1
503 2.004873s s1
503 2.006558s s1
503 2.004673s s1
503 0.003836s s1
503 0.004349s s1
503 0.003715s s1
201 0.082140s
2026/11/23 20:36:38 s1: Sicherung offen für 5s (5 Fehler in Folge)
2026/11/23 20:36:45 s1: Sicherung geschlossen
Five times two seconds, then 4 milliseconds: the breaker has tripped and doesn’t ask the database at all anymore. After the pause, s3 was reachable again, the probe succeeded, and the breaker closed again. Each instance has its own circuit breaker; s2 tracks its errors itself. Now the load from Drill 2:
20:37:05 s3:6432 schwarzes Loch
20:37:27 wieder offen
== Klicks
checks_succeeded...: 97.34% 11683 out of 12002
http_req_duration..............: avg=3.19ms min=1.12ms med=2.28ms max=73.74ms p(90)=4.22ms p(95)=6.36ms
== Anlegen
✗ 201
↳ 41% — ✓ 498 / ✗ 703
✗ 429
↳ 0% — ✓ 0 / ✗ 1201
✗ 503
↳ 58% — ✓ 703 / ✗ 498
http_req_duration..............: avg=78.77ms min=803.93µs med=3.79ms max=2.01s p(90)=12.25ms p(95)=22.36ms
| Protection | Redirects succeeded | Longest create |
|---|---|---|
| none | 35.3% | 10 s (k6 gives up) |
| timeout 2 s | 68.0% | 2.02 s |
| timeout and circuit breaker | 97.3% | 2.01 s |
Link creation still fails during the outage; no pattern can change that. But it fails fast, and the redirects barely notice. The remaining 2.7% fall mainly into the seconds in which an instance is still collecting errors or a probe waits two seconds for s3.
Save your progress? Sign up for free
Drill 5: Timeouts at the Load Balancer
A timeout in kurz only helps as long as
kurz is running. If the process itself hangs, say through a
deadlock or a full disk while logging, only someone waiting from the
outside notices. kill -STOP freezes the process on s1: the
kernel still accepts connections, but nothing gets answered.
# on s1
k6 run -q -e RATE=300 -e DAUER=30s klick.js > klick.log 2>&1 &
sleep 5; sudo pkill -STOP -x kurz; echo "$(date +%T) kurz auf s1 eingefroren"
sleep 15; sudo pkill -CONT -x kurz; echo "$(date +%T) kurz auf s1 läuft weiter"
wait; grep -E 'checks_succeeded|http_req_duration\.' klick.logExpected:
20:39:11 kurz auf s1 eingefroren
20:39:26 kurz auf s1 läuft weiter
checks_succeeded...: 100.00% 9001 out of 9001
http_req_duration..............: avg=8ms min=1.27ms med=2.25ms max=15.09s p(90)=3.64ms p(95)=4.65ms
No errors, but some users waited 15 seconds: exactly as long as the process was stopped. Whatever was sitting on s1 hung until it resumed. The same pattern as the 26.8 seconds from Day 4: nobody between user and instance had a short limit.
The budget from the outside in: k6 waits 10 s, HAProxy should sit
just above kurz, so 3 s instead of 30 s. And HAProxy may
retry a redirect that runs into the timeout on the other server. Not a
create: Day 11 showed why.
# on s1
cd ~/sd/tag13
sudo cp /etc/haproxy/haproxy.cfg /tmp/haproxy.cfg.alt
sudo perl -0pi -e 's/ timeout server 30s\n/ timeout server 3s\n/; s/( timeout queue 20ms\n)/$1 # nach Timeout auf dem anderen Server wiederholen, aber nie ein POST\n retry-on conn-failure empty-response response-timeout\n http-request disable-l7-retry if METH_POST\n/' /etc/haproxy/haproxy.cfg
diff /tmp/haproxy.cfg.alt /etc/haproxy/haproxy.cfg
sudo haproxy -c -f /etc/haproxy/haproxy.cfg && sudo systemctl reload haproxy && echo neu geladen
k6 run -q -e RATE=300 -e DAUER=30s klick.js > klick.log 2>&1 &
k6 run -q -e RATE=20 -e DAUER=30s anlegen.js > anlegen.log 2>&1 &
sleep 5; sudo pkill -STOP -x kurz; echo "$(date +%T) kurz auf s1 eingefroren"
sleep 15; sudo pkill -CONT -x kurz; echo "$(date +%T) kurz auf s1 läuft weiter"
wait; echo "== Klicks"; grep -E 'checks_succeeded|http_req_duration\.' klick.log
echo "== Anlegen"; grep -E '^ +[✓✗] |↳|http_req_duration\.' anlegen.logExpected:
12c12
< timeout server 30s
---
> timeout server 3s
32a33,35
> # nach Timeout auf dem anderen Server wiederholen, aber nie ein POST
> retry-on conn-failure empty-response response-timeout
> http-request disable-l7-retry if METH_POST
neu geladen
20:39:57 kurz auf s1 eingefroren
20:40:12 kurz auf s1 läuft weiter
== Klicks
checks_succeeded...: 100.00% 9001 out of 9001
http_req_duration..............: avg=5.67ms min=1.1ms med=2.29ms max=3s p(90)=3.89ms p(95)=4.95ms
== Anlegen
✗ 201
↳ 99% — ✓ 597 / ✗ 4
✗ 429
↳ 0% — ✓ 0 / ✗ 601
✗ 503
↳ 0% — ✓ 0 / ✗ 601
http_req_duration..............: avg=27.62ms min=4.18ms med=7.19ms max=3s p(90)=10.85ms p(95)=12.71ms
No redirect took longer than 3 seconds, and all of them arrived:
HAProxy retried the hanging ones on s2. Four creates got
504 after 3 seconds and were not retried. Were they stored
anyway once s1 was running again? The times come from the output
above:
# on s1
psql -h s3 -U kurz -d kurz -tAc "select count(*), min(angelegt)::time(0), max(angelegt)::time(0) from links where url like 'https://example.org/tag12/anonym/%' and angelegt between '2026-11-23 20:39:50+00' and '2026-11-23 20:40:40+00'"Expected:
597|20:39:52|20:40:22
Exactly 597, as many as 201. When s1 thawed, the two
seconds of the four requests had long expired, and kurz no
longer executed them. So the timeout in kurz protects here
too. A client must not rely on that, though: anyone who wants to retry
safely after a 504 sends an idempotency key.
Save your progress? Sign up for free
Exercise: Speed drills
- Which timeouts are currently in effect, from HAProxy down to the replica? Target time: 1 min
- How many times has the circuit breaker on s1 tripped today? Target time: 30 s
- Is there a DROP rule left on s2 or s3? Target time: 30 s
Solution
# on s1
grep -E "timeout (connect|server|queue)" /etc/haproxy/haproxy.cfg
grep -h 'env("KURZ_TIMEOUT' ~/kurz/*.go
journalctl -u kurz --since today -o cat | grep -c "Sicherung offen"
for s in s2 s3; do ssh $s "sudo iptables -S INPUT"; doneExpected (your number will differ; the second line
with KURZ_TIMEOUT_LESEN comes from the Challenge):
timeout connect 2s
timeout server 3s
timeout queue 20ms
lesenTimeout, _ = time.ParseDuration(env("KURZ_TIMEOUT_LESEN", "300ms"))
anfrageTimeout, _ = time.ParseDuration(env("KURZ_TIMEOUT", "2s"))
19
-P INPUT ACCEPT
-P INPUT ACCEPT
The circuit breaker logs every opening. During a longer outage it opens again and again: the probe fails, open again. And requests that were already in flight before it opened extend the pause when they fail.
Save your progress? Sign up for free
Checkpoint
# on s1
curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost/api/links -d "{\"url\":\"https://example.org/tag13/kontrolle-$(date +%s)\"}"Expected: 201, the circuit breaker is
closed.
A freshly created URL is not in the cache yet. If the replica is silent, it must still redirect quickly:
# on s1
C=$(curl -s -X POST localhost/api/links -d "{\"url\":\"https://example.org/tag13/kontrolle-neu-$(date +%s)\"}" | jq -r .code)
ssh s2 "sudo iptables -I INPUT -p tcp --dport 5432 -j DROP"
curl -s -o /dev/null -w '%{http_code} %{time_total}s\n' localhost/$C
ssh s2 "sudo iptables -D INPUT -p tcp --dport 5432 -j DROP"Expected (after the Challenge): 302
after just over 0.3 seconds, for example 302 0.323813s.
# on s1
ssh s2 "sudo iptables -S INPUT"Expected: -P INPUT ACCEPT
Challenge
The replica on s2 goes silent. Cached links work, but a freshly
created link returns 503 after 2 seconds, although the
primary knows it and finde is supposed to fall back to it
according to Day 8. Why? Make sure a silent replica costs a redirect a
few hundred milliseconds at most.
Hint: How much time is left for the primary if the replica uses up the whole budget?
Solution
First the problem:
# on s1
cd ~/sd/tag13
C=$(curl -s -X POST localhost/api/links -d "{\"url\":\"https://example.org/tag13/frisch-$(date +%s)\"}" | jq -r .code); echo $C
ssh s2 "sudo iptables -I INPUT -p tcp --dport 5432 -j DROP"
curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" localhost/$C
curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" localhost/c170720
ssh s2 "sudo iptables -D INPUT -p tcp --dport 5432 -j DROP"
sleep 1
curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" localhost/$CExpected:
5VQMU96
503 2.004665s
302 0.004101s
302 0.011965s
The query to the replica gets the same context as the whole request.
So it waits the full 2 seconds, and when finde then wants
to ask the primary, the context has already expired. The fallback from
Day 8 never gets its turn. The fix: a separate, shorter budget just for
the replica.
# on s1
cd ~/kurz && cp cache.go /tmp/cache.go.alt
perl -0pi -e 's/(\tladen singleflight.Group[^\n]*\n)/$1\t\/\/ Höchstdauer für das Replikat, danach fragt finde den Primärserver\n\tlesenTimeout, _ = time.ParseDuration(env("KURZ_TIMEOUT_LESEN", "300ms"))\n/; s/\t\terr := lesen.QueryRow\(ctx, "SELECT url FROM links WHERE code = \$1", code\).Scan\(&ziel\)\n/\t\tlctx, cancel := context.WithTimeout(ctx, lesenTimeout)\n\t\terr := lesen.QueryRow(lctx, "SELECT url FROM links WHERE code = \$1", code).Scan(&ziel)\n\t\tcancel()\n/' cache.go
diff /tmp/cache.go.alt cache.go
go vet . && go build -o kurz . && echo gebautExpected:
20a21,22
> // Höchstdauer für das Replikat, danach fragt finde den Primärserver
> lesenTimeout, _ = time.ParseDuration(env("KURZ_TIMEOUT_LESEN", "300ms"))
61c63,65
< err := lesen.QueryRow(ctx, "SELECT url FROM links WHERE code = $1", code).Scan(&ziel)
---
> lctx, cancel := context.WithTimeout(ctx, lesenTimeout)
> err := lesen.QueryRow(lctx, "SELECT url FROM links WHERE code = $1", code).Scan(&ziel)
> cancel()
gebaut
Roll out with the loop from Day 11, then try again with a new link:
# on s1
cd ~/sd/tag13
C=$(curl -s -X POST localhost/api/links -d "{\"url\":\"https://example.org/tag13/frisch2-$(date +%s)\"}" | jq -r .code); echo $C
ssh s2 "sudo iptables -I INPUT -p tcp --dport 5432 -j DROP"
curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" localhost/$C
ssh s2 "sudo iptables -D INPUT -p tcp --dport 5432 -j DROP"Expected:
GNxEVis
302 0.315382s
300 ms for the replica, 15 ms for the primary. The rule behind it: if you have a fallback, don’t give the first path the whole budget. And the sum of all partial timeouts must fit into the budget of the whole request.
Save your progress? Sign up for free
Clean-up
Nothing to tear down. Timeouts, circuit breaker and the retry in
HAProxy stay; they are the new defaults of kurz. All that
matters is that no DROP rule is left (speed drill 3) and that
kurz on s1 is no longer frozen:
# on s1
ps -o stat= -C kurzExpected: Ssl, no T (for
“stopped”).
Interview note
- Timeouts everywhere, shorter on the inside than on the outside. Client > load balancer > service > database. A timeout without budget thinking leads to work still going on inside when the outside gave up long ago.
- Explain the circuit breaker with its three states
and the question of what “error” means (only
5xxand timeouts, never4xx). Add a fallback: cached data, a queue for later, or an honest, fast503. - Cascades arise through shared resources: threads, connection pools, slots in the load balancer. The remedy is called bulkhead: separate pools for separate paths, so that link creation can’t starve the redirects.
Enterprise note
- Service meshes (Istio, Linkerd) set timeouts, retries and outlier detection per route without the code knowing about them. But they only see HTTP: a budget for the replica as in the Challenge remains the application’s job.
- In HAProxy,
observe layer7witherror-limitandon-error mark-downtakes a server out of rotation if it returns too many errors, even when its health check is green. That is a circuit breaker at the load balancer level. - Libraries such as
sony/gobreaker(Go) or Resilience4j (Java) offer breakers with an error rate instead of a fixed threshold, and with metrics. The principle is the one from Drill 4, just with more knobs.