Microservice Health Check Pattern
Design a complete health check strategy for microservice architectures with separate endpoints for different consumers: load balancers, orchestrators, and monitoring.
Patterns
Detailed Explanation
Microservice Health Check Pattern
In microservice architectures, a single health endpoint is not enough. Different consumers need different levels of detail and different failure behaviors.
Multi-Endpoint Strategy
GET /health → Simple (for load balancers)
GET /health/live → Liveness (for Kubernetes)
GET /health/ready → Readiness (for Kubernetes)
GET /health/detailed → Full component checks (for monitoring)
Simple Endpoint (/health)
{ "status": "UP" }
Liveness Endpoint (/health/live)
{
"status": "ok",
"checks": {
"deadlockDetection": { "status": "ok" },
"memoryThreshold": { "status": "ok" }
}
}
Readiness Endpoint (/health/ready)
{
"status": "ok",
"dependencies": {
"database": { "status": "ok", "responseTime": "12ms" },
"redis": { "status": "ok", "responseTime": "3ms" },
"user-service": { "status": "ok", "responseTime": "45ms" }
}
}
Detailed Endpoint (/health/detailed)
{
"status": "UP",
"timestamp": "2024-01-15T10:30:00Z",
"version": "2.3.1",
"uptime": "72h 14m",
"checks": {
"database": { "status": "UP", "duration": "12ms", "poolSize": 20 },
"redis": { "status": "UP", "duration": "3ms", "hitRate": "94%" },
"disk": { "status": "UP", "usage": "45%" },
"memory": { "status": "UP", "heapUsed": "256MB" }
}
}
Security Considerations
| Endpoint | Authentication | Detail Level |
|---|---|---|
| /health | None | Minimal |
| /health/live | None | Internal only |
| /health/ready | None | Dependency names |
| /health/detailed | Required | Full details |
The detailed endpoint should require authentication to prevent exposing internal infrastructure information. Never include connection strings, credentials, or IP addresses in health responses.
Use Case
Production microservice deployments that need to serve health information to multiple consumers: cloud load balancers, Kubernetes, monitoring dashboards, and on-call debugging tools.