I've written two posts about Traefik's newer middlewares this autumn, the tap middleware and service-level middlewares, and both times I set them up on a load balancer I'd never actually stress-tested at the one thing it exists to do: notice when a backend dies. So this time I skipped the new features and went back to basics. Two containers behind a Traefik service, one of them killed mid-traffic, and a stopwatch.
The short version: with the minimum config needed to route traffic at all, Traefik does not notice a dead backend on its own, ever. There are two different config blocks that fix this, they behave quite differently from each other, and the part that's supposed to tell you which state you're in doesn't update for either of them without a third option.
The setup
Two Python containers, each printing a random ID generated once at process start, behind a Traefik 3.8.0 service with round-robin load balancing:
http: services: my-service: loadBalancer: servers: - url: "http://dp-b1:8000" - url: "http://dp-b2:8000" No health check, no retry, nothing extra, just the two servers.
I ran a client that polled the service every 50ms, let it settle for five seconds, then ran docker stop -t 1 on one backend and kept polling for another ten seconds. I repeated this three times.
It never comes back
| Trial | Requests after kill | Failed | Failure rate | Still failing at end of test |
|---|---|---|---|---|
| 1 | 162 | 71 | 43.8% | yes, +10.05s |
| 2 | 200 | 90 | 45.0% | yes, +10.02s |
| 3 | 161 | 70 | 43.5% | yes, +9.97s |
In two of the three trials, the very last request of the run failed; in the third, the last failure landed 0.05 seconds, one poll interval, before the final request. Either way, the run ended with Traefik still happily alternating onto a server that had been dead for ten seconds. Once it settles into that failing pattern, it comes back as a 502 roughly every second request:
$ curl -s -w '\nHTTP_STATUS:%{http_code}\n' http://localhost:18080/ Bad Gateway HTTP_STATUS:502 $ curl -s -w '\nHTTP_STATUS:%{http_code}\n' http://localhost:18080/ instance=bb1c6afa HTTP_STATUS:200 My first look at the numbers bothered me: 44% isn't 50%, and a load balancer alternating between one dead and one live server should fail exactly half the time. I went back to the raw timestamps before trusting the rate, and found something more useful than a harness bug. For roughly a second after docker stop -t 1 ran, every single request still succeeded, 21 in a row in every trial, before the first failure appeared. I'd set -t 1 deliberately to keep the kill fast, but even that one second of SIGTERM grace is 21 requests at a 50ms polling rate, and the container keeps answering on its existing socket until it's actually gone, not the instant the stop command is issued. That's not Traefik recovering anything; it's the kill itself being slower than I'd assumed. Once that grace window passes, the rest of each run is a flat, perfectly alternating 502-every-other-request, exactly as expected; it's this roughly one-second head start, not Traefik doing anything differently, that pulls the overall rate down from 50% to 44%.
With ten clients hitting it concurrently instead of one, the pattern holds over the roughly 8.7 seconds of load the test actually generated after the kill: 941 requests, 370 of them failed, 39.3%, with the very last request of the run among the failures. Concurrency didn't make it worse and it didn't make it better, because nothing in this config is watching the backend at all.
A health check without a health check
Before reaching for an active check, I found a second option sitting in the same docs: passiveHealthCheck, which judges a server by real traffic instead of a separate probe. No extra path to serve, no extra interval of its own, just two settings:
http: services: my-service: loadBalancer: passiveHealthCheck: failureWindow: "10s" maxFailedAttempts: 1 servers: - url: "http://dp-b1:8000" - url: "http://dp-b2:8000" I expected this to behave like a less precise version of the active check: one failure, then quiet. It didn't.
| Trial | Failed requests | Failure 1 after kill | Failure 2 after kill |
|---|---|---|---|
| 1 | 2 | +1.08s | +13.10s |
| 2 | 2 | +1.08s | +11.11s |
| 3 | 2 | +1.09s | +13.12s |
Every trial failed exactly twice: once straight after the kill, as expected, then again roughly ten to twelve seconds later, which is the failureWindow I'd set. The docs explain why, once you read past the first sentence: "a server will be considered healthy again after the configured failure window has passed." Healthy again doesn't mean checked again first, it means put back in rotation and found out the hard way. A passiveHealthCheck server that's still down gets rediscovered by making a real request fail, on a clock, for as long as it stays down. An active healthCheck, which I tried next, probes on its own schedule and never needs a real request to notice anything.
Giving it a check that probes on its own
http: services: my-service: loadBalancer: healthCheck: path: /health interval: "2s" timeout: "1s" servers: - url: "http://dp-b1:8000" - url: "http://dp-b2:8000" | Trial | Failed requests | First failure after kill | Last failure after kill |
|---|---|---|---|
| 1 | 10 | +1.06s | +1.96s |
| 2 | 1 | +1.12s | +1.12s |
| 3 | 16 | +1.05s | +2.56s |
The bad window is bounded now, somewhere between one and three seconds, which lines up with a 2-second check interval plus a 1-second timeout. It also isn't fixed to a single number: trial 2 recovered after one failed request, trial 3 took sixteen. Both ran the same config. If you need a tighter guarantee than "within roughly one check interval, give or take," shorten the interval, but you'll be trading it against how often you're polling a server that's doing nothing wrong.
The part that's supposed to tell you is wrong
Traefik exposes a live API for its own state, which is the obvious place to watch this instead of guessing from client errors. I queried it on the config with no health check, five seconds after killing the backend, then made a real request straight after:
$ curl -s http://localhost:18081/api/http/services/my-service@file {"loadBalancer":{"servers":[{"url":"http://dp-b1:8000"},{"url":"http://dp-b2:8000"}], "strategy":"wrr","passHostHeader":true,"responseForwarding":{"flushInterval":"100ms"}}, "status":"enabled","usedBy":["my-router@file"],"name":"my-service@file", "provider":"file","type":"loadbalancer", "serverStatus":{"http://dp-b1:8000":"UP","http://dp-b2:8000":"UP"}} $ curl -s -w '\nHTTP_STATUS:%{http_code}\n' http://localhost:18080/ Bad Gateway HTTP_STATUS:502 Without an active health check, Traefik has no information about a server beyond whether a request to it succeeds, and it doesn't check that until a real request tries and fails. So its own status endpoint still said "UP" for a server that was, in the same breath, failing roughly every second request a real client sent it. I checked the same field under passiveHealthCheck too, after sending a real request that confirmed the failure and the recovery: one request hit the dead server and got a 502, the next three were correctly routed around it to the live one, and serverStatus still read "UP" for both servers throughout. With the active health check from the previous section back in place, the same endpoint read "DOWN" for that backend three seconds after I killed it, a point by which my timed trials above had already stopped seeing failures in every run. The dashboard, in other words, only tells the truth once you've given it a probe of its own; both of the traffic-driven mechanisms leave it saying "UP" regardless of what's actually happening.
Retry hides it from the client, mostly
Traefik also has a retry middleware, which resends a failed request to a different server:
middlewares: my-retry: retry: attempts: 2 Attached to the same no-health-check service, this nearly erased the client-visible failures: 1 out of 161, 1 out of 161, and 0 out of 200 requests failed across three trials, against roughly 44% without it. Latency barely moved, from a mean of 2.5-2.7ms before the kill to 3.4-4.6ms after, with the worst single request at 23.9ms. The server that's gone still costs you almost nothing, because the connection fails fast and Traefik just tries the other one.
What I got wrong on the way
I assumed this protection didn't extend to POST requests, because the retry middleware has a retryNonIdempotentMethod option, documented as defaulting to false, specifically to stop it retrying POST, PATCH and LOCK. I built a second test expecting to see POST failures land at roughly the same 44% as the no-retry case, proving the default was doing its job.
It wasn't. Across three trials, POST requests failed at 0.62% after the kill, the same near-total masking I measured for GET. So I went back and read the option more carefully instead of trusting the name. retryNonIdempotentMethod only gates retries triggered by the status list, and that list is empty by default, so there's nothing for it to gate in a default config. A fully unreachable backend isn't a status code at all, it's a connection error, and that's handled by a different setting entirely, disableRetryOnNetworkError, which also defaults to false. Connection-error retries are on by default, for every method, full stop. The non-idempotent flag only starts doing anything once you've separately opted into retrying specific HTTP status codes. So no, the default setup does not stop a POST from being replayed against a second server when the first one is simply unreachable.
I can't say whether this causes a real double-write, because my dead backend never got far enough to process anything before the connection was refused. What I can say is that the request was sent twice and the second one succeeded, which is the precondition for a duplicate side effect on an endpoint that isn't safe to call twice.
Run it yourself
cat > backend.py << 'EOF' import http.server, socketserver, uuid iid = str(uuid.uuid4())[:8] class H(http.server.BaseHTTPRequestHandler): def do_GET(self): self.send_response(200); self.end_headers() self.wfile.write(f"instance={iid}\n".encode()) with socketserver.ThreadingTCPServer(("0.0.0.0", 8000), H) as s: s.serve_forever() EOF mkdir -p dynamic cat > traefik.yml << 'EOF' entryPoints: web: address: ":80" providers: file: directory: /etc/traefik/dynamic api: insecure: true EOF cat > dynamic/dynamic.yml << 'EOF' http: routers: my-router: rule: "PathPrefix(`/`)" service: my-service services: my-service: loadBalancer: servers: - url: "http://b1:8000" - url: "http://b2:8000" EOF docker network create dp-net docker run -d --name b1 --network dp-net -v "$PWD/backend.py:/backend.py:ro" python:3.12-slim python3 /backend.py docker run -d --name b2 --network dp-net -v "$PWD/backend.py:/backend.py:ro" python:3.12-slim python3 /backend.py docker run -d --name tr --network dp-net -p 18080:80 -p 18081:8080 \ -v "$PWD/traefik.yml:/etc/traefik/traefik.yml:ro" \ -v "$PWD/dynamic:/etc/traefik/dynamic:ro" \ traefik:3.8.0 curl -s http://localhost:18080/ docker stop -t 1 b1 curl -s -w '\nHTTP_STATUS:%{http_code}\n' http://localhost:18080/ curl -s http://localhost:18081/api/http/services/my-service@file Where I landed
An active health check is going on anything I front with Traefik from now on, as a default rather than something I bother with later, because the two alternatives both leave a real client eating failures, either the open-ended 44% of doing nothing or one bad request every ten-second window with passiveHealthCheck, while Traefik's own API sits there saying "UP" regardless. passiveHealthCheck earns its place over nothing if a health endpoint genuinely isn't available, but given the choice I'm not reaching for it.
The retry middleware's non-idempotent flag is the one I'd warn a colleague about specifically, because its name promises more than the default setting delivers. A write endpoint that can't safely run twice needs that guarantee built into the endpoint, not assumed from a flag that only blocks retries triggered by status codes you've listed, which by default is none of them.
Beyond that, it's worth pulling up serverStatus on anything already running behind Traefik and checking it against a real request, once, by hand. On 3.8.0 it only reflects an active health check. Everything else leaves it reading "UP" no matter what's actually happening underneath.

