16 min read
Health checks, SLOs and alerts with Grafana
In one sentence: A health check says whether your API is alive and whether it can serve; an alert writes to you when what your customers notice, errors, slowness or an email that doesn’t arrive, goes past a limit. The shop gains both, and learns to fail well when something it depends on doesn’t answer.
What you will learn
- Separate “it’s alive” from “it can serve,” and explain why the liveness check doesn’t look at the database.
- Set an SLO on an SLI and use its error budget to decide when to alert.
- Write alerts on symptoms, with measured thresholds, without falling into alert fatigue.
- Decide what your API does when a dependency doesn’t answer: wait briefly, and fail open or closed.
Before you start, read: 05-metrics.md phase-9/04-zero-downtime.md phase-6/08-rate-limiting.md
The problem
Section titled “The problem”Imagine a Tuesday at eleven at night. PostgreSQL stops answering, and the shop answers 500 to every sign-in. You’re having dinner. You find out the next morning, from a customer’s email: “I couldn’t sign in last night.”
The dashboard from lesson 5 showed it, but nobody looks at a dashboard at eleven at night. The shop needs to come looking for you: an alert that writes to you when errors go past a limit. Phase 6 left it pending: a log nobody reads warns of nothing.
And before that, something more basic: “should I restart this copy?” and “should I send it customers?” are two different questions, and answering both with /health is expensive.
The analogy
Section titled “The analogy”The analogy
A restaurant has two questions that aren’t the same: is the cook OK? And can the kitchen serve dishes?
If the gas is cut off, the cook is perfectly fine, but can’t cook. The sensible thing is to hang “closed for a while” on the door, so nobody comes in to wait, and call the gas technician. Calling an ambulance for the cook doesn’t fix the gas. If the dishwasher breaks, on the other hand, they keep serving: more slowly, washing by hand.
And nobody waits for a customer to complain about the smoke: the detector beeps at the smoke, whether it comes from a frying pan or a cable.
Where the analogy breaks down
- In the restaurant, someone sees there’s no gas. In the shop, whoever hands out the requests only knows what the check answers.
- The shop can have many copies, and a PostgreSQL outage reaches all of them at once: restarting them all is much worse than one ambulance too many.
- A smoke detector comes with its limit from the factory. You choose your alerts’ limits, and they get measured: a copied limit alerts too much or too little.
The cook is /health/live; the kitchen that can serve, /health/ready; the dishwasher, the cache, and the smoke detector, an alert on what customers notice.
How it really works
Section titled “How it really works”Two questions, two routes
Section titled “Two questions, two routes”In Phase 9 you saw the two questions: is the copy alive (liveness)? and is it ready to serve (readiness)? Step 46 gives each one a route:
/health/live, the Liveness probeA periodic check that answers “is this program still alive?”. If it fails several times, whatever supervises it restarts it. It must look only at the program itself: if it looked at the database, a database outage would restart everything without fixing anything.Go to definition: if it doesn’t answer, the copy is restarted./health/ready, the Readiness probeA periodic check that answers “can this program serve requests right now?”. It looks at what the program needs to work, such as the database. If it fails, traffic stops going to it, but it is not restarted.Go to definition: if it says503, requests stop being sent to it, without restarting it.
// Liveness: is the process alive and answering? It asks nobody else, on purpose. Whoever uses it (an// orchestrator like Kubernetes) restarts the copy that doesn't answer. If it looked at the// database, a PostgreSQL outage would make it restart all the copies at once, and restarting them// doesn't fix PostgreSQL: it only adds copies starting up to an outage that was already there.// Only 503 while shutting down.app.get('/health/live', (c) => { if (shuttingDown()) return c.json({ status: 'shutting-down' }, 503); return c.json({ status: 'ok' });});It asks nobody, on purpose. If it looked at PostgreSQL, a database outage would make every copy’s probe fail at once, and they’d all be restarted. Restarting doesn’t fix PostgreSQL: it only adds copies starting up to an outage that was already there.
/health/ready asks three, half a second each
Section titled “/health/ready asks three, half a second each”It asks each dependency and says what it saw:
// Can this copy serve? All three at once (not one after another: three waits of 500 ms would be// 1.5 s). It fails if PostgreSQL or the queue's Redis fails: without the database there is no shop,// and without that Redis nobody can sign in (the limits close) and no job goes out. The cache is// reported, but doesn't count: without it, everything is read from PostgreSQL, slower.export async function checkAll() { const [db, queue, cache] = await Promise.all([ check(checks.db), check(checks.queue), check(checks.cache), ]); const ready = db !== 'failing' && queue !== 'failing'; return { ready, checks: { db, queue, cache } };}- All three at once (
Promise.all), and each one with 500 ms at most (check, in the same file). A frozen dependency never answers, and whoever asks needs an answer. - It fails if PostgreSQL or the queue’s Redis fails: without them there’s no shop, no sign-ins and no jobs.
- The cache is reported, but doesn’t count: without it, the shop reads from PostgreSQL, more slowly. It’s the dishwasher.
/health stays as it was
Section titled “/health stays as it was”It’s read by the Dockerfile’s HealthcheckA command Docker runs every few seconds inside a container to find out whether its program really works, not just whether it’s running. If it ends well, the container is healthy; after several failures in a row, it’s unhealthy. Compose uses it to wait for a service before starting the ones that depend on it.Go to definition, since Phase 7, and by deploy.sh. For them, “healthy” is: it reaches PostgreSQL and it isn’t shutting down. If it were /health/ready, a Redis outage would roll back a deployment that’s not to blame; if it were /health/live, a copy with no database would get through.
And who reads /health/ready? In your Compose, nobody: Docker has a single healthcheck, and nginx only looks at the real requests. The new routes are for an orchestrator like Kubernetes, which asks each question separately. A probe is only useful if someone does the right thing with its answer.
SLI, SLO and error budget
Section titled “SLI, SLO and error budget”Before alerting, you have to decide what “going well” is. In the shop:
- The SLISLI stands for Service Level Indicator.A number that measures whether the service is doing well for the people using it, such as “the percentage of requests answered correctly in under 500 ms”. It is what you measure; the target you set for it is the SLO.Go to definition, what’s measured: the share of
/v2’s responses that aren’t a 5xx. - The SLOSLO stands for Service Level Objective.The target you set for an SLI, for example “99.5% of requests are answered correctly each month”. It is not a contract with anyone: it is the line from which you decide it is time to fix things.Go to definition, the target: 99%, counted over 30 days.
- The Error budgetWhat an SLO lets you fail: with 99.5% monthly, 0.5% of requests. While budget is left you can take risks and deploy; once it runs out, it is time to stop new features and fix reliability.Go to definition, the 1% left over: with a million requests a month, 10,000 errors.
While there’s budget left, new features get deployed; if it runs out, it’s time to fix reliability. And it gives an alert its measure: with a 5% error rate that lasted, the whole month’s budget would run out in six days (30 divided by 5). That’s no longer bad luck.
Alerts on symptoms, not on causes
Section titled “Alerts on symptoms, not on causes”A cause is what can break something: the CPU at 90%, a Redis that’s down. A symptom is what whoever uses the shop notices: errors, slowness, an email that doesn’t arrive.
The shop alerts on symptoms. A symptom alerts you of any cause, including the ones nobody had thought of, and a cause nobody notices isn’t worth waking anyone up for. Grafana loads four rules from files in the step; asked through its API:
{"title":"5xx errors on /v2","for":"2m","noDataState":"OK","severity":"urgent"}{"title":"High p99 on /v2","for":"2m","noDataState":"OK","severity":"warning"}{"title":"Outgoing events stuck","for":"0s","noDataState":"OK","severity":"urgent"}{"title":"The API is not sending metrics","for":"1m","noDataState":"Alerting","severity":"urgent"}The first three are symptoms: errors, slowness and emails that don’t go out. The fourth watches the others.
A rule from the inside: query, last value and threshold
Section titled “A rule from the inside: query, last value and threshold”The errors one, in rules.yaml, has three steps. The first, A, the query to Prometheus:
- refId: A datasourceUid: prom relativeTimeRange: { from: 300, to: 0 } model: refId: A instant: true expr: >- sum(rate(http_server_request_duration_seconds_count{job="shop-api", http_route=~"/v2/.*", http_response_status_code=~"5.."}[1m])) / sum(rate(http_server_request_duration_seconds_count{job="shop-api", http_route=~"/v2/.*"}[1m]))What share of /v2’s responses were 5xx in the last minute, with the rate from lesson 5: the SLI seen the other way around, the share that fails. Then, the threshold:
- refId: B datasourceUid: __expr__ model: { refId: B, type: reduce, expression: A, reducer: last }- refId: C datasourceUid: __expr__ model: refId: C type: threshold expression: B conditions: [{ evaluator: { type: gt, params: [0.05] } }]- B keeps A’s last value, and C checks whether it goes over
0.05, 5%. for: 2m, in the list above: Grafana evaluates it every 10 seconds. When it’s met, it goes to pending; if it keeps being met for 2 minutes, to firing, and it alerts. A lone error wakes nobody up.noDataState: OK: with no traffic there are no errors to count, and it doesn’t alert.
The thresholds were measured with the shop healthy and a traffic script from the step (npm run traffic, which you’ll see in lesson 7): not a single 5xx in 5 minutes, and a p99 of 72 ms at most (the p99 threshold is 0.5 s). The reasoning is in the file’s comments: measure yours, because a copied threshold alerts too much or too little.
An email that doesn’t arrive gives no error
Section titled “An email that doesn’t arrive gives no error”With the queue’s Redis frozen, paying still gives 200: since Phase 9, it only writes to PostgreSQL. No error, and no email. That’s why step 46 adds a metric:
// How many seconds the oldest unsent outgoing event has been waiting (Phase 10, lesson 6). It is// what the customer notices when something fails without giving any error: the payment goes well,// but the email doesn't arrive. If the relayer works, it never goes over a few seconds; if it// grows, something is stopping it. It is read from PostgreSQL, not from Redis: that way it keeps// telling the truth when what has failed is the queue's Redis. The API reads it (server.ts), in a// hurry, like the queue's: one read at a time and, if PostgreSQL doesn't answer within waitMs,// nothing new. As with the queue's, the SDK then repeats the last value: with PostgreSQL frozen,// the age stands still instead of growing, and this alert doesn't fire (the others warn of that:// the slowness and the errors). unit: 's', and Prometheus adds it to the name:// shop_outbox_age_seconds.export const outboxAge = meter.createObservableGauge('shop.outbox.age', { description: 'Seconds the oldest unsent outgoing event has been waiting', unit: 's',});
/** Starts observing the age with read (unsentAge, in outbox.ts). */export function observeOutbox( read: () => Promise<number>, { waitMs = 2000 }: { waitMs?: number } = {},): () => void { return observeInAHurry(outboxAge, read, waitMs);}- It’s read from PostgreSQL, not from Redis, so it keeps telling the truth when what fails is Redis. With the relayer working, a few seconds; the rule alerts at 120.
- If PostgreSQL freezes, it goes quiet: the SDK (the library that sends the metrics) repeats the last value, lesson 5’s flat line. The errors and the slowness warn you of that.
The fourth rule watches the others
Section titled “The fourth rule watches the others”If the API goes down, it stops sending metrics, and the first three, with no data, go quiet: a dead API looks like a calm API. The fourth looks at how old the last sample of the outbox age is (one arrives every 5 seconds; with the API healthy, it gave us 3.09 seconds), and alerts if it goes over 60. Unlike the others, it also alerts with no data.
Whom it alerts, and how often
Section titled “Whom it alerts, and how often”contact.yaml sends an email to oncall@shop.example, over SMTP, the email protocol, to Mailpit, inside Compose’s network:
# The alerts' emails (lesson 6), over SMTP to Mailpit (compose.yaml), inside Compose's network:# they arrive at http://localhost:8025. Mailpit doesn't encrypt, so no STARTTLS. Grafana's# address, so the links in the email open your Grafana.GF_SMTP_ENABLED: 'true'GF_SMTP_HOST: mailpit:1025GF_SMTP_FROM_ADDRESS: alerts@shop.exampleGF_SMTP_FROM_NAME: Shop alertsGF_SMTP_STARTTLS_POLICY: NoStartTLSGF_SERVER_ROOT_URL: http://localhost:3100policy.yaml hands out the alerts:
- each rule, in its own email (
group_by: alertname); - 10 seconds of waiting before the first one, in case another from the same group arrives (
group_wait); - up to a minute to report a change, like it being resolved (
group_interval); - a reminder every 4 hours if it stays the same, not every minute (
repeat_interval).
Mailpit now keeps 5000 emails (MP_MAX_MESSAGES, in compose.yaml): with 500, the step’s traffic script deleted the alert ones in ten minutes.
Alert fatigue
Section titled “Alert fatigue”If nineteen out of twenty alerts a day ask for nothing, within a week you stop reading them, and the one that mattered gets lost. That’s Alert fatigueWhat happens when so many alerts arrive, many of them unimportant, that the people receiving them stop paying attention. One day they ignore the one that mattered. You avoid it by alerting only on what affects users and needs action now.Go to definition. It’s avoided with:
- alerts that ask you to act now; the rest, to a dashboard;
- measured thresholds and a
for; - severities:
urgentwakes someone up,warningwaits for working hours; - few reminders, and reviewing them: the one that fires without anyone doing anything gets fixed or deleted.
Failing well: the three fixes Phase 9 left
Section titled “Failing well: the three fixes Phase 9 left”The other half is failing well: fast, clearly and without dragging the rest down. Phase 9’s final review left three places where the shop didn’t.
1. The attempt limits waited for Redis endlessly: 12.2 seconds in lesson 4. Now each question waits 200 ms at most, like Phase 9’s cache. At the first one that doesn’t answer, the limit considers Redis down, and only asks it again once a second, so as not to pile up commands. And meanwhile? Each limit decides:
// The shop's limits. When signing in only the failures count, and from two sides: by email (it// protects each account, even if the attack comes from a thousand IPs) and by IP (it slows down// whoever tries many accounts at once). The trap of the limit by email: anyone can use up Ana's 10// attempts and leave her out for 15 minutes. That's why it's a while, not a lock forever. And the// IP's is higher, because behind one IP there can be a whole office, or a university.// If Redis fails (Phase 10, lesson 6), the two sign-in ones close: letting passwords through with no// limit is exactly the attack they exist to stop, and nobody can sign in until Redis is back (503).// The account-creation one opens: a few sign-ups with no limit while Redis is down cost less than// not letting any new customer in. It is a decision, not a rule: another shop might decide the// opposite.export const limits = { signInByEmail: createLimiter( { name: 'session-email', max: 10, window: 15 * 60, onFailure: 'closed' }, store, ), signInByIp: createLimiter( { name: 'session-ip', max: 30, window: 15 * 60, onFailure: 'closed' }, store, ), // Creating accounts: every attempt counts, whether it goes well or badly. accountsByIp: createLimiter( { name: 'accounts-ip', max: 5, window: 60 * 60, onFailure: 'open' }, store, ),};- The sign-in ones close:
503withRetry-After: 5, without waiting for Redis while it considers it down; only the once-a-second probe waits. Letting passwords through with no limit is exactly the attack they stop. - The account-creation one opens: it lets them through and says so in the log. A few sign-ups with no limit cost less than not letting any new customer in.
It’s a decision, not a rule: a shop with a fake-account problem would close both.
2. A borrowed connection that got cut could stop the API. It’s the gap from lesson 2: nobody listened to the 'error' of a connection in use, and Node stops the process when an error has nobody listening. It happens, for example, when the Phase 9 setting cuts a transaction that has been silent for 5 seconds. Now it’s listened to on every new connection:
// The same with a borrowed connection, the one a request or the relayer is using (Phase 10, lesson// 6). The pool only listens to the 'error' of the ones waiting in it: while one is borrowed, nobody.// If PostgreSQL cuts it then (it restarts, or idle_in_transaction_session_timeout closes a// transaction that has spent 5 s without saying anything, in outbox.ts), the 'error' had nobody to// listen to it and Node stopped the whole process. Now it is listened to on each new connection:// the query that was waiting fails with its error, like any other, and the process goes on. (One// that waits in the pool says it twice: here and in the pool.on('error') above.)// console.warn, and not the shop's log (log.ts): this file is also used by scripts that don't have// the API's configuration (migrate, seed), and log.ts requires it.pool.on('connect', (client) => { client.on('error', (error) => { console.warn('PostgreSQL cut a connection:', error.message); });});3. deploy.sh could take a copy that restarts in a loop for healthy, if it caught it healthy in its single look. Now wait_for_health looks at it twice, with about 5 seconds in between, and the RestartCount, the restarts Docker has counted, has to be the same both times.
All three say the same: when something you depend on fails, wait briefly, decide what you do and stay alive.
Watching from outside
Section titled “Watching from outside”In production, all this has a hole: a server can’t warn you of its own death. If the machine shuts down, Grafana shuts down with it. Real monitoring adds two pieces, outside the server:
- The metrics and the alerts, on another machine: a service with a free plan, like Grafana Cloud (check its current limits), or the same three tools on another server. The
OTEL_EXPORTER_OTLP_…addresses in the.envchange and, if the service asks for one, a key. The rules’ queries and thresholds work the same, but there they’re loaded through the service’s API or with Terraform, not with these files, and they have to be pointed at its data source and its labels. - A check from outside (uptime check): a service that requests
https://your-domain/healthevery minute from another network. It sees the same as a customer, and warns of what nothing inside sees: the machine off, the network cut or the certificate expired.
Try it
Section titled “Try it”The goal: see the shop tell “alive” from “ready,” trigger an alert and read its email, and see the attempt limit close without hanging.
Outputs from October 24, 2026, with the shop on Node 26, on a MacBook with Docker in a 2 GB virtual machine. Your times will be different.
Get the step ready
Section titled “Get the step ready”Put your project on step 46, as in the introduction:
cd ~/backend-course/phase-3curl -O https://backenddesdecero.com/practicas/shop-api/46-alerts.tar.gztar -xzf 46-alerts.tar.gzcp -R 46-alerts/. shop-api/cd shop-apinpm installgrep -q '^COMPOSE_FILE=' .env || printf '\nCOMPOSE_FILE=compose.yaml:compose.observability.yaml\n' >> .envdocker compose up -d --build --waitThe grep line checks whether your .env already has the COMPOSE_FILE from lesson 4’s “Try it”, and if not, adds it before starting: without it, the shop would start without Grafana. Compose recreates Grafana and Mailpit, because their configuration has changed.
The three answers, with everything healthy
Section titled “The three answers, with everything healthy”1. Everything healthy
API=$(docker compose port api 3000)for route in /health /health/live /health/ready; doprintf '%-14s' $route; curl -s -w ' %{http_code}\n' $API$routedoneWhat you will see:
/health {"status":"ok"} 200/health/live {"status":"ok"} 200/health/ready {"status":"ok","checks":{"db":"ok","queue":"ok","cache":"ok"}} 200API keeps the API’s port, as in lesson 5. printf '%-14s' pads the route with spaces so the columns line up, and -w adds the code. If you get 000, the API isn’t answering: check docker compose ps.
PostgreSQL stopped
Section titled “PostgreSQL stopped”2. Without the database
docker compose stop dbfor route in /health /health/live /health/ready; doprintf '%-14s' $route; curl -s -w ' %{http_code}\n' $API$routedoneWhat you will see:
Container shop-db-1 StoppingContainer shop-db-1 Stopped/health {"type":"about:blank","title":"Service Unavailable","status":503,"detail":"The database is not responding"} 503/health/live {"status":"ok"} 200/health/ready {"status":"failing","checks":{"db":"failing","queue":"ok","cache":"ok"}} 503/health/live stays at 200: restarting the process wouldn’t bring PostgreSQL back. /health/ready says 503 and why: db: failing. Don’t start PostgreSQL yet.
Trigger an alert
Section titled “Trigger an alert”Open another terminal, in the project’s folder, and launch one sign-in by Carmen per second:
3. Errors, one per second
API=$(docker compose port api 3000)while true; do curl -s -o /dev/null -w '%{http_code} ' --json '{"email":"carmen@example.com","password":"carmen-practice-2026"}' $API/v2/session; sleep 1; doneWhat you will see:
500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 …Without PostgreSQL, each one is a 500: 100% of what reaches /v2 fails. Leave it running. It’s a 500, not a 503: the shop only gives 503 where it has prepared for it, as in the Redis limits.
In the first terminal, ask Grafana how its rules are. Repeat the command every so often:
4. The rules’ state
curl -s localhost:3100/api/prometheus/grafana/api/v1/rules | jq -r '.data.groups[].rules[] | "\(.state) \(.name)"'What you will see:
firing 5xx errors on /v2inactive High p99 on /v2inactive Outgoing events stuckinactive The API is not sending metricsOurs was pending within 15 seconds of the first 500, and firing at 2 minutes and 11 seconds: the 2 minutes of the for. In Grafana, http://localhost:3100, you see it in Alerting, Alert rules, the Shop folder. If it’s still inactive after a minute, check that the loop is still writing 500.
5. The email
curl -s 'localhost:8025/api/v1/messages?limit=5' | jq -r '.messages[] | "\(.Created) \(.Subject)"'What you will see:
2026-10-24T18:45:32.547Z [FIRING:1] 5xx errors on /v2 (Shop urgent)It arrived 12 seconds after firing: the group_wait. The time is in UTC, the world’s reference time, with no summer time (that’s what the Z means). ?limit=5 asks for the last five.
6. What it says
curl -s localhost:8025/api/v1/message/latest | jq -r .TextWhat you will see:
…*5xx errors on /v2*
View alert ( http://localhost:3100/alerting/grafana/shop-errors-5xx/view?orgId=1 )
*Summary*More than 5% of the responses from /v2 have been 5xx errors for 2 minutes*Description*Look at the "The shop" dashboard (5xx errors by route) and the API log.
*Values*
A=1 B=1 C=1
*Labels*
*alertname* 5xx errors on /v2 *grafana_folder* Shop *severity* urgent…We’ve removed the header and the end. Summary and Description are the rule’s annotations: what’s happening and where to look. A=1: 100% of /v2’s responses were 5xx; C=1, the condition is met.
Fix it and wait for the RESOLVED
Section titled “Fix it and wait for the RESOLVED”Stop the loop with Ctrl + C in the second terminal, and start PostgreSQL:
7. PostgreSQL, back
docker compose start dbWhat you will see:
Container shop-db-1 StartingContainer shop-db-1 StartedNow wait about two minutes.
8. Resolved
curl -s 'localhost:8025/api/v1/messages?limit=5' | jq -r '.messages[] | "\(.Created) \(.Subject)"'What you will see:
2026-10-24T18:47:32.43Z [RESOLVED] 5xx errors on /v2 (Shop urgent)2026-10-24T18:45:32.547Z [FIRING:1] 5xx errors on /v2 (Shop urgent)The RESOLVED arrived 1 minute and 49 seconds after stopping the loop: first, the window’s minute passes with no requests to /v2 and the rule goes back to normal; then, Grafana waits to send the notice that it was resolved.
The cache doesn’t count
Section titled “The cache doesn’t count”9. Without the cache
docker compose stop cachefor route in /health /health/live /health/ready; doprintf '%-14s' $route; curl -s -w ' %{http_code}\n' $API$routedonedocker compose start cacheWhat you will see:
Container shop-cache-1 StoppingContainer shop-cache-1 Stopped/health {"status":"ok"} 200/health/live {"status":"ok"} 200/health/ready {"status":"ok","checks":{"db":"ok","queue":"ok","cache":"failing"}} 200Container shop-cache-1 StartingContainer shop-cache-1 StartedAll three, 200, with cache: failing: without the dishwasher, the kitchen keeps serving.
Redis frozen: the 503 that doesn’t wait
Section titled “Redis frozen: the 503 that doesn’t wait”Now, lesson 4’s situation again. Freeze the queue’s Redis and try to sign in twice in a row:
10. A limit that closes
docker compose pause redisfor i in 1 2; docurl -si -o session.txt -w 'curl: HTTP %{http_code} in %{time_total} s\n' --json '{"email":"carmen@example.com","password":"carmen-practice-2026"}' $API/v2/sessiondonegrep -i '^retry-after' session.txtcurl -s -w ' %{http_code}\n' $API/health/readydocker compose unpause redisWhat you will see:
Container shop-redis-1 Pausedcurl: HTTP 503 in 0.207522 scurl: HTTP 503 in 0.002586 sretry-after: 5{"status":"failing","checks":{"db":"ok","queue":"failing","cache":"ok"}} 503Container shop-redis-1 Unpaused- The first one waited the 200 ms and closed:
503in 0.21 s. - The second, right after, no longer asked Redis: 0.003 s. In lesson 4, the same sign-in took 12.2 seconds.
retry-after: 5: try again in a few seconds./health/ready,503withqueue: failing: this copy can’t handle sign-ins.
With attempts further apart, each one would be the probe: you’ll see it in lesson 7.
With Redis back, our next sign-in got in: 200 in 0.076 s. When you finish, delete session.txt: it carries Carmen’s session. Leave the shop running for lesson 7.
On your server
Section titled “On your server”/health doesn’t change: the healthcheck and deploy.sh stay the same, and each copy takes about 5 seconds longer to be considered healthy, because of the second look. The alerts don’t arrive: the server’s .env doesn’t have the OTLP addresses, and compose.production.yaml doesn’t gain Grafana. For that, Watching from outside.
You have already seen it
Section titled “You have already seen it”- The ATM that turns on its screen and says “out of service”: alive, but not ready.
- The smoke detector’s chirp when its battery runs low: a device warning you that it won’t be able to warn you anymore. It’s the fourth rule.
- A performance budget: this course fails its build if a page goes over 400 KB of JavaScript. A limit you set yourself, like an SLO.
Common mistakes
Section titled “Common mistakes”- Making the liveness probe look at the database. A PostgreSQL outage restarts every copy and fixes nothing.
- Checking with no maximum time. With a frozen dependency, the check waits along with it.
- Alerting on causes instead of what customers notice.
- Alerting on every error. Without a
foror a measured threshold, a lone500wakes someone up. - Watching the server only from inside. If the machine goes down, whoever warns you goes down with it.
Summary
Section titled “Summary”/health/livesays whether the process answers, without asking anyone;/health/ready, whether it can serve: PostgreSQL and the queue’s Redis, 500 ms each; the cache doesn’t count./healthstays the same.- An SLI measures what the customer notices, the SLO gives it a target and the error budget is what’s left over: if it runs out, it’s time to fix things.
- Alerts warn of symptoms, with measured thresholds and a
for. The shop has four: errors, p99, emails that don’t go out and an API that goes quiet. - Failing well is waiting briefly, deciding whether you open or close, and staying alive.
- A server can’t warn you of its own death: in production, the alerts live outside.
Did you get it?
Section titled “Did you get it?”To review:
Further reading
Section titled “Further reading”- Monitoring Distributed Systems, from Google’s SRE book: symptoms and causes, and why to alert on little.
- Service Level Objectives, from the same book: SLI, SLO and how to choose them.
- Alerting on SLOs, from Google’s SRE workbook: alerts based on the error budget.
- Configure Liveness, Readiness and Startup Probes, from Kubernetes: the two probes, and a third one for startup.
- Provision alerting resources from files, from Grafana: rules, contact points and policies from files.