---
title: "Give the server a health check · Agent Wranglers"
url: https://agentwranglers.se/playbook/engineering/build-test-and-deploy/health-check-and-rollback
updated: 2026-10-20
licence: "All rights reserved"
---

# Give the server a health check

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy)
- Rule: Give the server a health check address that tests its dependencies, so deploys and monitors know when it is broken.
- How: Add an address such as `/healthz` that runs a cheap query against the database and other dependencies. Give each dependency check a short timeout, such as one second. Answer 200 when all work and 503 when one fails. Keep it fast, uncached and free of private data. The [one-step deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/atomic-deploys-with-rollback) polls it and rolls back on failure. For more depth, see [liveness and readiness](https://agentwranglers.se/playbook/operations/running-the-service/liveness-and-readiness).
- Check: Stop a dependency on a test server. The health check answers 503 within two seconds.

Example:

```js
app.get('/healthz', (req, res) => {
  res.set('Cache-Control', 'no-store');
  try {
    db.prepare('SELECT 1').get();
    res.type('text').send('ok');
  } catch {
    res.status(503).type('text').send('database unavailable');
  }
});
```

```python
# Flask
@app.get("/healthz")
def healthz():
    headers = {"Cache-Control": "no-store"}
    try:
        db.execute("SELECT 1")
        return "ok", 200, headers
    except DatabaseError:
        return "database unavailable", 503, headers
```

```go
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Cache-Control", "no-store")
	ctx, cancel := context.WithTimeout(r.Context(), time.Second)
	defer cancel()
	if err := db.PingContext(ctx); err != nil {
		http.Error(w, "database unavailable", http.StatusServiceUnavailable)
		return
	}
	w.Write([]byte("ok"))
})
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers engineering playbook: https://agentwranglers.se/playbook/engineering/build-test-and-deploy/health-check-and-rollback`.

- Previous: [Deploy in one step and roll back by itself](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/atomic-deploys-with-rollback)
- Next: [Release to a small share first](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/staged-rollouts)
- [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy)
