The Health Check Pattern
You'll learn how to expose endpoints that report a system's operational status so external tools can monitor, route, and manage it.
What It Is
The Health Check Pattern involves creating dedicated endpoints (typically HTTP) that allow external systems to query whether your service is functioning properly. Think of it like the "Are you okay?" checks a friend might do—except automated monitoring systems, load balancers, and orchestrators like Kubernetes are asking, and your service responds with "yes, I'm fine" or "no, something's wrong."
Why It Matters
Without health checks, orchestration systems can't tell if your service crashed, if a dependency failed, or if it's just slow. They might keep sending traffic to a dying instance or restart a perfectly healthy one. Health checks enable intelligent routing and recovery.
Typical Implementation
A health check endpoint (like /health or /readiness) returns:
- 200 OK if the service is healthy
- 503 Service Unavailable (or similar) if unhealthy
The response often includes diagnostic details: database connectivity, disk space, memory usage, or dependency status.
Two Common Types
Liveness checks answer "Is the service running at all?" (Should we restart it?)
Readiness checks answer "Can it handle requests right now?" (Should we route traffic to it?)
A service might be alive but not ready if it's still warming up caches or a critical dependency is down.
Analogy
Imagine a restaurant with a host at the door. Liveness: "Is anyone here?" Readiness: "Can you seat and serve customers right now?" The kitchen might be on fire (not ready), but staff are present (alive).
Key Takeaway:
Health check endpoints provide programmatic visibility into service status, enabling automated monitoring, traffic management, and recovery decisions in resilient systems.