Beginner LevelSystem Design & Architecture
How do Heartbeat Health Checks detect failed server instances?
β Interview Prompt: Explain Heartbeat Health Checks, active vs passive health checks, HTTP `/healthz` endpoints, and automated load balancer rerouting.
Heartbeat Health Checks allow load balancers and orchestrators (Kubernetes) to monitor the operational status of backend server instances:
How Health Checks Work:
1
Load balancer sends periodic HTTP requests (e.g. 'GET /healthz') every 5 seconds to backend nodes.
2
If a node responds with '200 OK' $\rightarrow$ Node is healthy.
3
If a node fails $N$ consecutive health checks (or times out) $\rightarrow$ Node marked unhealthy and removed from active traffic routing!
Code Implementation Example
typescript
app.get('/healthz', async (req, res) => {
// Verify DB connection health before returning 200 OK
const isDbAlive = await checkDatabaseConnection();
if (isDbAlive) return res.status(200).json({ status: 'HEALTHY' });
res.status(500).json({ status: 'UNHEALTHY', reason: 'Database connection failed' });
});π‘Implementing a `/healthz` endpoint checking database connectivity.
π― Interview Key Takeaway
Expose lightweight `/healthz` endpoints to allow load balancers to detect and automatically bypass unhealthy server instances.
#System Design#Health Checks#Heartbeat#Load Balancer#Beginner
Back to all System Design & Architecture Questionsβ