Ömer Faruk YILDIRIM
tutorials

Node.js Production Failure Lab · part 13

When the Check Meant to Keep the Site Up Takes It Down: Readiness and Correlated Failure

A few times an hour, every page on the site returns 503 for ten seconds, then recovers on its own. The API logs no errors and no instance restarts. The culprit is a readiness check written 'to be more robust': because it asks about a shared dependency, it pulls both instances out of rotation at the same moment. We walk through what belongs in readiness and what doesn't, why you have to measure at the edge, and what fail-open does for you.

26 min read60 min hands-oncode(opens in a new tab)

Node.js Production Failure Lab · Part 13 · Difficulty ★★☆ · Reading ~20 min · Lab ~45–60 min

The Builders’ Library, where Amazon collects its engineering articles, has a long piece on health checks (Implementing health checks). One of the traps it warns about goes like this: it is tempting to have a server’s health check ask about its dependencies too, because “let’s not send traffic to a server that can’t reach the database” sounds sensible. But if every server shares the same dependency, then when that dependency stumbles every server at once reports “I’m unhealthy”. In the author’s words, in that situation “a dependency can cause a cascading failure throughout a system”. The article also explains that this is why some load balancers fail open: if every target looks unhealthy, they send traffic to all of them anyway.

In this part we are going to fall into exactly that trap. In Part 12 we used /ready to make deploys safe: the instance that was shutting down returned 503 on /ready, the proxy took it out of rotation, and errors dropped to zero. The next day a teammate wanted to make the same mechanism “more robust”: /ready now checks every dependency. The result: a few times an hour, every page on the site returns 503 Service Unavailable for ten seconds. No instance crashes, and the API doesn’t log a single error line.

What you’ll learn

  • The different jobs of liveness, readiness and startup checks; readiness as “send me traffic”
  • Correlated failure: why redundancy stops helping once a shared dependency goes into readiness
  • Finding the 503s the proxy generates itself: the difference between edge metrics and service metrics
  • Reading the proxy’s decision about an instance from its log
  • Why short bursts (flapping) slip past 2-minute alert windows
  • The fix: readiness looks only at what the instance itself needs; a dependency’s problem is the problem of the request that uses it
  • Fail-open load balancers (Envoy panic threshold, AWS ALB) and their limits

Prerequisites

You can read this article without the lab. These help:

TopicWhySource
Liveness, readiness, startup probesThe separate jobs of the three checks; a pod failing readiness gets no traffic through the ServiceKubernetes, Configure Liveness, Readiness and Startup Probes
Health checks in a load balancerThe lab’s proxy is Traefik; unhealthy servers leave rotationTraefik, load balancing service
/ready and drainingThis part’s starting point: /ready → 503 during shutdownPart 12
TaxRate failovers, checkout’s dependency on TaxRateThe incident’s trigger; checkout’s timeout and retry budgetPart 11
Health check designLocal and dependency checks, fail-openAWS Builders’ Library, Implementing health checks

1. The concept: readiness is not “is the world OK?”

The load balancer in front of a service decides which of the instances behind it gets a request by using a health check. Kubernetes splits that question in three, and the split is useful:

CheckThe question it asksIf it fails
Liveness“Is this process stuck?”The container is restarted
Readiness“Can I send requests to this instance right now?”The instance leaves rotation; the process keeps running
Startup“Is it still starting up?”The other two checks are put on hold

The readiness question is about this instance: has startup finished, has shutdown begun (Part 12’s drain), is the instance unable to serve any request at all? The load balancer uses the answer to choose between individual instances. If one instance is sick, it takes it out and sends traffic to the healthy ones. That rests on the assumption that instances get sick independently of one another.

So what happens if readiness asks about something every instance shares (an external service, a common database)?

TaxRate  ─── healthy ───┬── degraded (10 s) ──┬── healthy ────►
                        │                     │
api-1 /ready   200 200  │ 503 503 503 503 503 │ 200 200
api-2 /ready   200 200  │ 503 503 503 503 503 │ 200 200
                        ▼                     ▼
proxy          [api-1, api-2]   [ ]  → 503 for everyone   [api-1, api-2]

Both instances give the same answer at the same time, because they ask the same thing. With no instances left, the proxy answers every request itself with a 503: product pages that never touch TaxRate included. The point of running two instances was that a single failure shouldn’t take the site down; readiness made the two instances’ failures correlated by design. A partial problem (checkout slow for 10 seconds) turned into a full outage.

See it yourself: a 60-line experiment

Before going into the lab, you can build the same mechanism in a single file: a “dependency”, two instances, a small proxy polling /ready every 2 seconds, and a client sending ~50 requests a second. The page the instances serve never touches the dependency; the only thing that changes is what /ready looks at.

// ready.mjs: two instances, a shared dependency, a small proxy that polls readiness.
// Usage: node ready.mjs all   (readiness also checks the dependency)
//        node ready.mjs own   (readiness checks only the instance itself)
import http from 'node:http';

const MODE = process.argv[2] ?? 'all';
let depDegradedUntil = 0; // the shared dependency (playing TaxRate)

// Dependency: /health returns 503 while degraded.
http.createServer((req, res) => {
  res.statusCode = Date.now() < depDegradedUntil ? 503 : 200;
  res.end();
}).listen(4100);

// Two instances. /ready: asks the dependency if MODE=all; /page never touches it.
for (const port of [4001, 4002]) {
  http.createServer(async (req, res) => {
    if (req.url === '/ready') {
      let ok = true;
      if (MODE === 'all') ok = (await fetch('http://127.0.0.1:4100/health')).ok;
      res.statusCode = ok ? 200 : 503;
      return res.end();
    }
    res.end('product page'); // a page that only needs the "database"
  }).listen(port);
}

// Proxy: polls each instance's /ready every 2 s, sends requests only to those that pass.
const healthy = new Set([4001, 4002]);
setInterval(async () => {
  for (const port of [4001, 4002]) {
    const ok = await fetch(`http://127.0.0.1:${port}/ready`).then((r) => r.ok, () => false);
    ok ? healthy.add(port) : healthy.delete(port);
  }
}, 2000);
let next = 0;
http.createServer((req, res) => {
  const pool = [...healthy];
  if (pool.length === 0) { res.statusCode = 503; return res.end('no available server'); }
  const port = pool[next++ % pool.length];
  http.get(`http://127.0.0.1:${port}${req.url}`, (up) => { res.statusCode = up.statusCode; up.pipe(res); });
}).listen(4000);

// 50 requests a second for 30 s; at second 10 the dependency degrades for 10 s.
const start = Date.now();
const perSecond = {};
setTimeout(() => (depDegradedUntil = Date.now() + 10_000), 10_000);
const timer = setInterval(async () => {
  const sec = Math.floor((Date.now() - start) / 1000);
  const status = await fetch('http://127.0.0.1:4000/page').then((r) => r.status, () => 0);
  perSecond[sec] ??= { ok: 0, err: 0 };
  status === 200 ? perSecond[sec].ok++ : perSecond[sec].err++;
}, 20);
setTimeout(() => {
  clearInterval(timer);
  const errSecs = Object.entries(perSecond).filter(([, v]) => v.err > 0).map(([s]) => Number(s));
  const total = Object.values(perSecond).reduce((a, v) => a + v.ok + v.err, 0);
  const errors = Object.values(perSecond).reduce((a, v) => a + v.err, 0);
  console.log(`mode=${MODE}  requests=${total}  503=${errors}` +
    (errSecs.length ? `  seconds with 503s: ${errSecs[0]}–${errSecs.at(-1)}` : ''));
  process.exit(0);
}, 30_000);
node ready.mjs all
node ready.mjs own

On my machine (Node.js 22.18):

mode=all  requests=1378  503=460  seconds with 503s: 10–20
mode=own  requests=1380  503=0

Same page, same dependency failure. In all mode a third of the requests (460/1378) got a 503; for the duration of the failure, all of them did. In own mode, none. The page never used the dependency; what took it down wasn’t the dependency itself, but readiness asking about it. None of those 460 requests reached an instance: the proxy answered them itself.


2. The incident: Friday, and the uptime monitor can’t make up its mind

🔁 [FLAPPING] Uptime monitor: the site answered 503, then recovered 12 s later (4 times in the last hour)

Friday, December 18. A message from support: “Every now and then the site goes down for a few seconds, then comes back.” The uptime monitor flips to red and back to green a few times an hour. What you know:

  • A few times an hour every page returns 503 for about ten seconds: listings, product pages, order history, checkout. Then everything recovers.
  • The API logs no errors at those moments, and neither of the two instances restarts.
  • The error-rate alert doesn’t fire: the burst is over before the alert’s 2-minute window notices.
  • The API has run as two instances since Wednesday; the proxy (Traefik) polls each instance’s GET /ready every 2 seconds and only sends requests to the ones that pass.
  • In this lab, TaxRate’s database fails over every 5 minutes (as in Part 11).

Recent changes:

VersionWhenChange
2.26.0yesterdayfeat(ops): /ready checks every dependency (database, TaxRate, PayFlow, Recommendations, MailWave)
2.25.22 days agofix(server): /ready fails on SIGTERM, keeps serving for 5 s before shutting down (Part 12’s fix)

If you’ve set up the lab, start the incident:

git clone https://github.com/FARUK-YILDIRIM/nodejs-production-failure-lab.git
cd nodejs-production-failure-lab
./lab start 013

💡 Want to try it yourself first? Stop here, open Grafana (http://localhost:3000), wait for the first burst (~1 minute after traffic starts, then every 5 minutes) and investigate on your own for 30 minutes. The results of each step below are in collapsed boxes; open them when you get stuck. For the lab’s own hints: ./lab hint 013.


3. Investigation, step by step

Step 1: See the burst, and notice who is counting

The dashboard’s Requests per second by status panel counts traffic at the edge, at the proxy’s entry point. The Requests per second by route panel next to it shows the requests the API measures itself. Put the two side by side over the same time range.

What do we see?

Four bursts in 18 minutes: 04:34, 04:39, 04:44, 04:49. Exactly 5 minutes apart, ~10 seconds each.

  • At the edge, successful requests collapse in every burst and a dark green 503 slice takes their place.
  • In the API’s own graph, all routes drop to the floor together at the same moments. But there is no 503 anywhere in the API’s graph: the requests aren’t failing, they aren’t arriving at all.

Grafana: on the left, requests per second at the edge by status; at 04:34, 04:39, 04:44 and 04:49 successful requests drop to ~25 and dark green 503 slices appear; on the right, the API's requests by route drop to the floor across every route at the same moments

Left: what the edge sees. Right: what the API sees. In all four bursts every API route empties at once; the panel’s rate window smooths the 10-second dips and draws them at half depth.

The dashboard window smooths the burst. In Explore, plot three series on top of each other with a 10-second window: 503s at the edge, 2xx at the edge, and all requests the API sees.

sum(rate(traefik_entrypoint_requests_total{entrypoint="web",code="503"}[10s]))   # 503 at the edge
sum(rate(traefik_entrypoint_requests_total{entrypoint="web",code=~"2.."}[10s]))  # 2xx at the edge
sum(rate(http_server_request_duration_seconds_count{job="api"}[10s]))            # seen by the API

Grafana Explore, 04:33–04:50:30: 2xx at the edge (yellow) and requests seen by the API (blue) drop to 0 in every burst while 503 at the edge (green) rises to 70–83 at the same moment; in between, 503 is at zero

Blue (seen by the API) and yellow (2xx at the edge) fall to zero in every burst, while green (503 at the edge) replaces all the traffic at the same moment. Between bursts, 503 is exactly zero.

The counters make the difference plain:

503 at the edge503 counted by the API
04:34 burst8290
04:39 burst8330
04:44 burst7320
04:49 burst7250
Total over 18 minutes3,1190

Between 04:34:14 and 04:34:27 the edge counted 581 requests and the API 174: the ~400 in between never reached the API.

Lesson: A service’s metrics only see the requests that reach the service. The edge tells you what the customer experienced.

Step 2: Who is returning the 503?

If the API isn’t counting them, the 503s come from something in front of it. In Jaeger, open one of the proxy’s (traefik service) traces from during a burst.

The trace of a single 503

Jaeger: traefik GET trace, 04:34:25.161; a single span, 21 microseconds, http.status_code = 503, url.path = /api/products/5638; Services 1, Total Spans 1

A product page request: one span, 21 microseconds, 503. No ReverseProxy span, no API span. The proxy answered without forwarding the request to any instance.

In Part 12 the 502 traces had a ReverseProxy span and the address of the target instance: the proxy had forwarded the request to an instance and the instance had refused the connection. Here even that span is missing. A 503 that comes back in 21 microseconds means “there’s nobody to send it to”.

Step 3: Read the proxy’s decision

The proxy writes to its log why it took an instance out of rotation: ./lab logs traefik. Look at the moment of a burst, and put TaxRate’s own log (./lab logs taxrate) and the API’s logs (./lab logs) next to it.

The timeline

Timeline: 04:34:15.120 taxrate database failover begins; at 15.172 and 15.181 traefik reports Health check failed 503 for both instances; 15.187 first 503 at the edge; api-1's /ready says taxrate: answered 503, the other dependencies ok; every 2 seconds the check fails for both instances; 04:34:15.4–26.1 no logs at all from the API; 25.121 failover ends; 25.161 last 503

52 ms after TaxRate’s failover starts, the proxy takes out both instances; 6 ms later, the first 503. When the failover ends (25.121), the last 503 comes within 40 ms. In between, neither API instance writes a single log line.

The chain is now clear:

  1. 04:34:15.120 TaxRate’s database fails over; TaxRate’s /health starts returning 503 (degraded).
  2. 15.172 / 15.181 On the proxy’s next check, both instances’ /ready return 503: Health check failed … received error status code: 503, first api-2, then api-1 9 ms later.
  3. 15.187 The proxy has no instances left; it answers every request with a 503 itself.
  4. The same two warnings every 2 seconds. Meanwhile the API is idle: it gets no requests and writes no errors.
  5. 25.121 TaxRate recovers, the next check passes, 25.161 the last 503.

When I queried one instance’s /ready from the inside during a burst (via docker exec), this is what I got:

{"status":"degraded","dependencies":{"database":"ok","taxrate":"answered 503","payments":"ok","recommendations":"ok","mailwave":"ok"}}

The database is ok. Everything that product pages, listings and order history need is in place. The instance says “I’m not ready” because TaxRate, a service only checkout uses, has declared itself degraded.

Step 4: Rule out the red herrings

Did the instances crash? The database? TaxRate itself?
  • “The instances are crashing.” No: in 18 minutes process_start_time_seconds never changed (API restarts on the dashboard is 0), and there are no startup lines in the logs. The instances are up throughout the burst; they just don’t get any requests.
  • “The database.” /ready’s own report says database: ok; query times between bursts are normal.
  • “TaxRate is taking the site down.” Only checkout uses TaxRate. Look at the instances’ calls to TaxRate: during a burst, TaxRate calls don’t rise; all outbound service calls collapse together. Because no requests reach the API.

Grafana: on the left, the API's calls per second to external services; recommendations 200 collapses from ~33/s to ~10 in every burst, taxrate and mailwave drop to the floor at the same moments; on the right, p95 of external service calls, with taxrate jumping to 1.25 s and 1.75 s at 04:39 and 04:49

During the bursts every outbound call drops at once: the API isn’t getting traffic. TaxRate’s p95 spikes are the waiting time of the handful of checkouts that coincided with the failover.

  • “The proxy is flaky.” The proxy does exactly what it’s told: no ready instances, no traffic.

TaxRate’s failover is the trigger. It happened before, too, and slowed checkout down for 10 seconds; that was all. The root cause is readiness asking about a shared dependency.

Step 5: The latest code

// platform/health.routes.ts (2.26.0)
/** Every service the API calls. An instance that can't reach one of them shouldn't get traffic. */
const DEPENDENCIES: Record<string, () => Promise<unknown>> = {
  database: () => pool.query('SELECT 1'),
  taxrate: () => ping(new URL('/health', config.taxrateUrl).href),
  payments: () => ping(`${config.paymentsUrl}/health`),
  recommendations: () => ping(`${config.recommendationsUrl}/health`),
  mailwave: () => ping(`${config.mailwaveUrl}/health`),
};

healthRouter.get('/ready', async (_req, res) => {
  if (isDraining()) {
    res.status(503).json({ status: 'draining' });
    return;
  }
  const dependencies = await checkDependencies();
  const ready = Object.values(dependencies).every((result) => result === 'ok');
  res.status(ready ? 200 : 503).json({ status: ready ? 'ready' : 'degraded', dependencies });
});

The comment states the intent honestly: “an instance that can’t reach one of its dependencies shouldn’t get traffic”. For a single instance, that makes sense. The missing question is: what happens if this check fails on every instance at the same time? Four of the five dependencies (TaxRate, PayFlow, Recommendations, MailWave) are external services shared by every instance. The moment any one of their /health endpoints says 503, the whole site goes dark. Recommendations was treated as an optional service in Part 9; a MailWave problem shouldn’t even stop orders. 2.26.0 made every one of them mandatory for the entire site.

The lab’s diagnosis questions and answers (./lab submit 013)
QuestionAnswer
Who is returning the 503s?The edge proxy, because no instance passes its readiness check
Why do both instances fail the readiness check at the same time?Their readiness depends on TaxRate, which they share: when TaxRate is degraded, both fail it together
What should an instance’s readiness depend on?Only on what it needs to serve requests at all: a dependency’s trouble should fail the requests that use it

4. Mitigation: stop the bleeding first

  • Roll back 2.26.0. The previous /ready only looked at the database. Rolling back is a complete and fast fix.
  • If you can’t roll back: pointing the proxy’s check at /health (liveness) instead of /ready stops the bursts. But Part 12’s drain goes with it and 502s come back during deploys. A stopgap only.
  • Don’t: add more instances. Ten instances will ask the same TaxRate and fall over at the same moment.

5. The fix: readiness is about the instance, not the world

// platform/health.routes.ts
/**
 * Readiness: the proxy may send requests here. Not while shutting down. It only
 * checks what every request needs, the database: the other dependencies are shared
 * by all instances, so failing readiness over one of them would take every
 * instance out at once, and with them every page, even those that don't use it.
 * Requests that need a failing dependency fail on their own.
 */
healthRouter.get('/ready', async (_req, res) => {
  if (isDraining()) {
    res.status(503).json({ status: 'draining' });
    return;
  }
  await pool.query('SELECT 1');
  res.json({ status: 'ready' });
});

/** The state of every dependency: for dashboards and humans, never for the proxy. */
healthRouter.get('/health/dependencies', async (_req, res) => {
  const dependencies = await checkDependencies();
  const healthy = Object.values(dependencies).every((result) => result === 'ok');
  res.json({ status: healthy ? 'ok' : 'degraded', dependencies });
});

Three decisions:

  1. /ready looks at what every request needs: the instance isn’t shutting down and can reach the database. An instance that can’t reach the database can’t serve anything, so taking it out of rotation is right. If the database is down for everyone, the site is down anyway; readiness doesn’t make that worse.
  2. TaxRate, PayFlow, Recommendations and MailWave are not in readiness. When one of them has trouble, the requests that use it fail on their own or cope on their own: with the timeouts, fallbacks and retry budgets from earlier parts. The rest of the site keeps working.
  3. The dependency report doesn’t disappear, it moves: GET /health/dependencies, for dashboards and humans. The proxy never reads it. This endpoint doesn’t even return 503; the state is in the body.

A subtle point: if await pool.query('SELECT 1') fails, Express’s error handler returns 500; the proxy treats anything outside 2xx–3xx as a failure, so the behavior is correct. If you prefer to be explicit, return 503 from a try/catch.

6. Verification

I deployed the fix at 04:53:08 (it finished at 04:53:32). Thanks to Part 12’s drain, there wasn’t a single 503 at the edge during the deploy. A minute later, at 04:54:15, TaxRate failed over again:

After the fix, the failover at 04:54:15: /ready keeps returning 200 ready, /health/dependencies reports taxrate: answered 503, traefik takes no instance out; no 503s, 170 × 500 and 40 × 499 on POST /api/orders; over 90 seconds the category page never answered with anything but 200

The same failover, with the fix: /health/dependencies reports that TaxRate is degraded, /ready keeps saying 200. The proxy takes no instance out. Errors appear only in checkout, which needs TaxRate. The same at the 04:59:15 failover: no 503s, 80 × 500 and 30 × 499 in checkout.

Checkout still has errors, and it should: TaxRate can’t give quotes for 10 seconds, and orders can’t complete without a tax calculation. The difference is that the error now belongs to the request that uses it; a customer looking at a product page notices nothing.

The dashboards say the same thing:

Before and after the fix: requests per second at the edge by status; 503 dips at 04:34, 04:39, 04:44 and 04:49, then after the deploy line at 04:53 no dips at the 04:54 and 04:59 failovers; between 04:54 and 04:55 traffic rises to ~130 req/s; on the right, the API's requests by route have no dips after the deploy

The orange dashed line is the deploy (04:53). In the two failovers after it (04:54:15, 04:59:15) there are no dips at the edge, and the API’s routes are uninterrupted. The bump between 04:53:48 and 04:55:18 is mine: the polling loop above called the category page, /ready and /health/dependencies ~21 times a second (the last two don’t show up in the API’s route graph).

Grafana Explore, 04:33–05:00: four 503 bursts before the fix; after the fix, 503 stays at zero at 04:54 and 04:59, 2xx and requests seen by the API have no dips, only small ~10/s bumps of 500 (checkout)

Explore doesn’t draw the deploy line; the deploy ran 04:53:08–04:53:32 (the short dip in blue is the instances restarting one by one; no errors at the edge). In the two later failovers green (503) stays at zero; the only visible trace is the orange 500 bump of checkouts that waited for TaxRate and gave up. The rise at 04:54–04:55 is my polling loop.

./lab verify 013

verify puts TaxRate into a 10-second failover at second 10 of the measurement, under ~66 req/s of traffic:

MetricTargetBeforeAfter
Server errors while browsing (5xx; listings, product pages, order history)= 06000
Error rate on catalog requests16.7% (300 of 1,801)0%
Error rate on account (order history) requests16.6% (60 of 361)0%
Checkouts the app gave up on after all retries11.3% (20 of 177)14.6% (27 of 185)
CPU0.26 cores0.30 cores
Event loop delay (max)126 ms163 ms

10 seconds out of a 60-second measurement, ~17% of catalog and account requests: everyone browsing while TaxRate was degraded got an error. With the fix, zero.

The small increase on the checkout side is expected: previously, when TaxRate degraded, checkouts got an instant 503 from the proxy; now they reach the API and wait for TaxRate, and some still fail. Making checkout resilient to TaxRate failovers is a separate job: a cached tax rate per country, or queueing the order. This fix’s job is to keep checkout’s problem from spreading to the rest of the site.

There’s no meaningful difference in CPU or the event loop; this incident was never about resources.


7. Fixes that look right but aren’t

AttemptWhy it falls short
Longer timeouts on the dependency checksTaxRate’s /health returns 503 instantly. Time isn’t the problem.
Checking only the “critical” dependencies (database + TaxRate)The bursts continue: TaxRate is a shared dependency too. Any shared dependency takes every instance down at once.
Making /ready return 200 unconditionally, or turning off the proxy’s checkPart 12’s drain breaks; 502s come back during deploys. Readiness has a legitimate job.
More instances, restartsEvery instance asks the same dependency; ten instances fall over at the same moment too.
“Ignore the check if every instance fails” (fail-open)A reasonable safety net (see below), but the proxy isn’t yours, and readiness asking the wrong question stays unfixed. The AWS article also notes that fail-open hasn’t been proven to behave as expected in every partial-failure scenario.

8. In production: alternatives and prevention

A dependency’s problem is the problem of the request that uses it. When TaxRate degrades, break the feature, not the instance:

  • Return a clear 503 + Retry-After for checkout, or queue the order; the instance stays ready for everything else.
  • A circuit breaker per dependency: fail fast for a while without even asking a service that keeps failing.
  • A fallback for optional dependencies: serve the page without it, like the “Customers also bought” recommendations in Part 9.

Know about fail-open, but don’t lean on it. Some load balancers ignore health information when every target looks unhealthy:

  • AWS Application Load Balancer: if every target in a target group is unhealthy, it sends requests to all of them regardless of health status (ALB health checks).
  • Envoy: if the share of healthy hosts falls below the panic threshold (50% by default), it ignores health status and spreads traffic across all hosts (Envoy, panic threshold).

That keeps a bad readiness check from taking the whole site down. But not every proxy has it (Traefik in this lab doesn’t), and it doesn’t kick in when “almost all” fail: the one or two remaining instances take the entire load.

Alert at the edge. Requests the proxy answers itself don’t show up in the service’s metrics. To catch short bursts, use a short window:

- alert: EdgeServerErrorBurst
  expr: sum(increase(traefik_entrypoint_requests_total{entrypoint="web",code=~"5.."}[1m])) > 10
  labels:
    severity: page
  annotations:
    summary: "{{ $value }} 5xx at the edge in 1 minute (including those the proxy answered itself)"

As a complement: during business hours, have the uptime monitor page on the first failure; a “3 failures in a row” rule will always miss 10-second bursts.

Health check review checklist:

  • What happens if this check fails on every instance at the same time?
  • Does the check ask about something every instance shares (an external service, a shared cache, a shared database)? If so, can the instance really serve no requests without it?
  • Does liveness ask about anything external? It shouldn’t: when the dependency degrades, every pod restarts at once.
  • Is the state of dependencies monitored somewhere the load balancer doesn’t read (per-dependency call metrics, /health/dependencies)?
  • Does the load balancer fail open? If so, at what threshold?

The Kubernetes equivalent: putting an external dependency in a readinessProbe produces exactly the same result. When the dependency degrades, every pod becomes unready together, the Service has no endpoints left, and the ingress returns 503 to everyone.


Key takeaways

  • Liveness: “restart me if I’m stuck”. Readiness: “send me traffic”. Startup: “I’m still starting up”. None of them is “is the world OK?”.
  • Once a shared dependency goes into readiness, instance failures become correlated; at that moment redundancy stops helping.
  • Review every health check like code that can take the site down: “What if it fails on every instance at once?”
  • A dependency’s problem is the problem of the request that uses it: timeouts, fallbacks, circuit breakers, and a clear 503 + Retry-After if needed.
  • Measure at the edge: requests the proxy answers itself never show up in the service’s metrics or logs.
  • Short bursts slip past long-window alerts; set up a short-window 5xx counter at the edge.

Test yourself

1. Users are seeing 503s but there are no errors in the service’s logs or metrics. Where do you look first?

At the proxy in front of the service: the edge metrics (requests counted by status at the entry point) and the proxy’s log. When no ready instances are left, the proxy returns the 503 itself; the service never sees those requests. The gap between the edge’s request count and the service’s count shows the requests that never reached the service.

2. The database stayed in readiness. The database is also shared by every instance; why is that not a problem?

Because without the database an instance can serve no requests at all; whether readiness fails or not, the site doesn’t work. Readiness makes nothing worse. If a single instance has a connection problem (network, pool), taking it out also helps. TaxRate, on the other hand, is needed only by checkout: putting it in readiness also shuts down pages that could have worked.

3. If the proxy failed open (send to every instance if all are unhealthy), would this incident have happened?

Not in this form: when both instances failed at the same time, the proxy would have sent to both anyway and the pages would have worked. But readiness asking the wrong question would still be unfixed. If one of three instances failed a moment later than the others, the one remaining instance would take the whole load; Part 12’s drain would also lose its meaning while fail-open is in effect. Fail-open is a safety net, not a substitute for design.

4. Why didn’t the error-rate alert fire? What kind of alert would have caught it?

The alert looked at the error rate over a 2-minute window and waited for it to persist for a while; a 10-second burst either leaves the rate under the threshold or ends before the for duration elapses. The alert that catches it counts at the edge over a short window: for example, more than 10 5xx in 1 minute, with no for. Having the uptime monitor page on the first failure does the same job.

Further reading

Basics

Deep dives

Real-world incidents

  • Netlify, Load balancer service degradation, March 25 2021: an operating system update broke the same network setting on every backend node; over a few hours the nodes started failing the load balancer’s health check one by one, and traffic on that load balancer (~5% of global traffic) was down for ~4 hours. Netlify’s own node checks said “healthy”: not looking through the load balancer’s eyes is the equivalent here of looking at service metrics. One of the fixes was adding the load balancer’s view of backend health to alerting.

Next up: Delayed confirmations. This part’s fix is live: /ready now looks only at the database. A few days later, order confirmation emails move to a new worker: the API publishes a message for every order, and the worker reads the messages and sends the email. Orders are fine, but confirmations arrive late, first by a few minutes, then by close to an hour. We’ll learn to read consumer lag and to calculate why a queue can’t keep up.

The full lab: https://github.com/FARUK-YILDIRIM/nodejs-production-failure-lab. If you’ve solved the lab, run ./lab report 013 to generate the postmortem template and compare it with your own write-up.