QA
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→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?