InterviewHubPRO
Section Overview
Q56

Question 56 of 60

Part 5: Production Scale, Deployment & Observability (51 - 60)

93%
Node.js & Libuv•Part 5: Production Scale, Deployment & Observability (51 - 60)

Health Check Endpoints: Liveness vs Readiness.

In Simple Words:

  • /healthz/liveness: Checks if the Node.js process is alive and its Event Loop is unblocked. If failing, Kubernetes restarts the pod.
  • /healthz/readiness: Checks if the application can accept user traffic (verifies database and Redis connectivity). If failing, Kubernetes stops sending requests to this pod.
javascript
app.get('/healthz/liveness', (req, res) => res.status(200).send('OK'));

app.get('/healthz/readiness', async (req, res) => {
  try {
    await dbPool.query('SELECT 1');
    await redis.ping();
    res.status(200).send('READY');
  } catch (err) {
    res.status(503).send('NOT_READY');
  }
});