- Published on
Health Checks for Microservices
- Authors

- Name
- Mamun Rashid
Building Robust Health Checks for Microservices 🚀
Modern service architectures depend on health checks. They confirm a system is running and catch problems early. This article covers the /health_check endpoint, a standard monitoring tool that every service should provide. Automated systems and human operators both use it to see whether a service is working as expected, and it makes diagnosis quick when something breaks.
🎯 Motivation
Tools like Kubernetes use liveness and readiness probes to watch service health and step in when something goes wrong. A reliable health check makes our services more resilient and gives us a clear view of how the system is performing.
🔍 Key Probes and Their Purpose
The liveness probe checks that a service is still alive and working. Services sometimes get into a broken state that only a restart can fix. The liveness probe catches this and lets the system restart the service automatically.
livenessProbe: httpGet: path: /health_check port: 8000 initialDelaySeconds: 10 periodSeconds: 120 successThreshold: 1 failureThreshold: 3 timeoutSeconds: 5Kubernetes calls the
/health_checkendpoint on a schedule to confirm the service responds. If a call fails (for example, it returns a503status), Kubernetes tries again, and if the failures keep coming, it triggers a restart.A person can check the same endpoint and read the status code:
- 200 OK means all is well.
- 503 Service Unavailable means the service needs a restart.
The readiness probe checks whether a service is ready to accept traffic. A service can be alive but not yet able to handle requests, for example while it is still loading configuration. The readiness probe keeps traffic away from it until it is.
readinessProbe: httpGet: path: /health_check?check_dependencies=true port: 8000 initialDelaySeconds: 5 periodSeconds: 300 successThreshold: 1 failureThreshold: 1 timeoutSeconds: 5It decides whether the service can handle requests by checking its dependencies, such as databases or caches.
For a detailed view of readiness, call it yourself:
curl -i "http://localhost:8080/health_check?check_dependencies=true&full=true"- pass: the system and its dependencies are healthy.
- degraded: the service can take traffic, with some limitations.
- fail: the service is not ready.
🏁 Startup Probe
The startup probe checks that the service has started correctly. Slow-starting containers need it most, because without it they can fail liveness checks before they are fully up.
startupProbe:
httpGet:
path: /health_check?check_dependencies=true&strict=true
port: 8000
failureThreshold: 30
periodSeconds: 10
Kubernetes holds back the liveness and readiness probes until this probe confirms the service has started, so a slow start doesn't cause needless restarts.
📊 System State Representation
The /health_check endpoint reports the state of the system. It returns a JSON object with the health of the service and each of its dependencies:
{
"status": "degraded",
"version": "0.0.1-dev",
"dependencies": {
"configuration": "pass",
"database": "pass",
"blob_storage": "pass",
"redis": "fail"
}
}
- pass: the service and its dependencies all work.
- fail: the service or a critical dependency has failed.
- degraded: a non-critical dependency is down, but the service still works.
💡 Design Guidelines for Health Checks
Query Parameters
Query parameters control how much the health check does:
| Parameter | Description |
|---|---|
full |
Toggles human-readable output |
check_dependencies |
Enables checks on service dependencies (e.g., databases, caches) |
strict |
Forces a service failure if any dependency check fails |
Example endpoints:
- Basic check:
/health_check - Dependency check:
/health_check?check_dependencies=true - Strict check:
/health_check?check_dependencies=true&strict=true
Unauthenticated Endpoint
In most cases the advice is to leave the /health_check endpoint unauthenticated, so monitoring tools and infrastructure systems can call it without extra setup.
🔐 Security Considerations
The /health_check endpoint should only reveal a high-level status, pass or fail, for each dependency. Sensitive details such as endpoint URLs belong in the logs and out of the public response. Credentials belong in neither.
A response that follows this rule:
{
"status": "fail",
"version": "0.0.1-dev",
"dependencies": {
"redis": "fail",
"database": "pass",
"blob_storage": "pass"
}
}
🔧 Monitoring and Alerting
Monitoring systems like Datadog, or Prometheus through its blackbox exporter, query the /health_check endpoint often. They go by the HTTP status code when deciding to alert or take corrective action:
- 200 OK: the service is healthy.
- 503 Service Unavailable: the service or a dependency is down, which raises an alert.
Tip: Watch how often the checks run so they don't overload the service. If needed, lengthen the interval.
📈 Scaling and Resource Usage
Health checks add to resource usage, especially when they run often. Keep them cheap so they don't slow the service down or hog its resources.
🌐 Kubernetes Configuration Example
In Kubernetes, both the readiness and liveness probes go in the container section of the deployment configuration:
readinessProbe:
httpGet:
path: /health_check?check_dependencies=true
port: 8000
initialDelaySeconds: 5
periodSeconds: 300
livenessProbe:
httpGet:
path: /health_check
port: 8000
initialDelaySeconds: 10
periodSeconds: 120
With this setup, services stay stable and fast, and they recover from failures on their own.
Conclusion 🎉
Resilient services start with health checks. They show the state of a service and its dependencies, so systems can heal themselves and operators hear about problems early. Whether you run Kubernetes or another platform, every service should have a well-built /health_check endpoint.
Follow the standard design and configuration laid out here, and your services will be healthier, more reliable and easier to maintain.
Enjoyed this post?
Subscribe to get notified about new posts and updates. No spam, unsubscribe anytime.
By subscribing, you agree to our Privacy Policy. You can unsubscribe at any time.
Discussion
Loading comments...
This website is still under development. If you encounter any issues, please contact me.
Found this useful? Support the blog