Health Check Endpoints
Expose HTTP endpoints that report application health status for use by load balancers, orchestrators, and monitoring systems.
Description
Health check endpoints are dedicated HTTP routes that report whether an application instance is functioning correctly. They serve as the primary mechanism for load balancers, container orchestrators, and monitoring systems to determine whether to route traffic to an instance, restart it, or trigger alerts. Well-designed health checks are critical for automated recovery and zero-downtime deployments.
Kubernetes distinguishes between three types of probes: liveness (is the process alive and not deadlocked -- restart if failing), readiness (can this instance serve traffic -- remove from load balancer if failing), and startup (has initial loading completed -- don't check liveness until passing). Each serves a different purpose and should check different things. A liveness check should be lightweight (is the event loop responsive), while a readiness check should verify connectivity to critical dependencies (database, cache, external APIs).
Health check responses should include structured JSON with overall status, individual dependency statuses, and relevant metadata (version, uptime, response times). Checks should have timeouts shorter than the probe interval to prevent cascading failures. Avoid checking non-critical dependencies in readiness probes to prevent unnecessary cascading unavailability. Consider providing a detailed /health endpoint for monitoring dashboards and a lightweight /healthz for high-frequency load balancer polling.
Prompt Snippet
Implement two health check endpoints: GET /healthz as a lightweight liveness check returning 200 with {status: 'ok'} in under 10ms (no dependency checks), and GET /health/ready as a readiness check that verifies PostgreSQL connectivity (SELECT 1), Redis PING, and S3 bucket access with individual timeouts of 2s each. Return 200 with detailed JSON including each dependency's status and latency, or 503 if any critical dependency fails. Include app version from package.json and process uptime. Do not cache health check results, and ensure the endpoint is excluded from authentication middleware.Tags
Related Terms
Load Balancing
Distribute incoming network traffic across multiple server instances to ensure reliability and optimal resource utilization.
Graceful Shutdown
Handle process termination signals to finish in-flight requests and close resources cleanly before exiting.
Container Orchestration (Kubernetes basics)
Automate deployment, scaling, and management of containerized applications using Kubernetes.
Zero-Downtime Deployments
Deploy application updates without any period of unavailability by gradually replacing old instances with new ones.
Application Monitoring (APM)
Monitor application performance, trace requests across services, and identify bottlenecks using APM instrumentation.