Skip to main content

Health Module

The liveness and readiness probe โ€“ monitoring critical service dependencies for load balancers and orchestration.

Liveness Readiness Rate Limit


๐Ÿ“– Table of Contentsโ€‹


Base Route : /api/v1/healthโ€‹

The health endpoint is public (no authentication required) and is rateโ€‘limited generously to accommodate load balancer probes (AWS ELB, Kubernetes, etc.).


Endpoint Overviewโ€‹

MethodEndpointAccessDescription
GET/PublicReturns the health status of the API and its critical dependencies (MongoDB, Redis, Typesense).

Rate limit: 3000 requests per 15 minutes per IP (see Rate Limiting Guide). This is intentionally high for production load balancers but still prevents DoS attacks.


Endpoint Detailsโ€‹

GET /โ€‹

Probes the connectivity to MongoDB, Redis, and Typesense. Returns a 200 OK only if all dependencies are reachable. If any dependency fails, returns 503 Service Unavailable with details about the failing component.

Headers: None required.

Response (200 OK โ€“ all services healthy):

{
"success": true,
"statusCode": 200,
"message": "All services are operational",
"data": {
"status": "healthy",
"timestamp": "2026-05-22T10:30:00.000Z",
"uptime": 86400,
"services": {
"mongodb": "connected",
"redis": "connected",
"typesense": "connected"
}
},
"timestamp": "2026-05-22T10:30:00.000Z"
}

Response (503 Service Unavailable โ€“ dependency failure):

{
"success": false,
"statusCode": 503,
"message": "Service Unavailable: One or more dependencies are down.",
"data": {
"status": "unhealthy",
"timestamp": "2026-05-22T10:35:00.000Z",
"uptime": 86400,
"services": {
"mongodb": "connected",
"redis": "disconnected",
"typesense": "connected"
},
"failedService": "redis"
},
"timestamp": "2026-05-22T10:35:00.000Z"
}

Response Structureโ€‹

FieldTypeDescription
data.statusstring"healthy" if all dependencies are connected, otherwise "unhealthy"
data.timestampstring (ISO)Current server time
data.uptimenumberServer uptime in seconds (since server.ts started)
data.services.mongodbstring"connected" or "disconnected"
data.services.redisstring"connected" or "disconnected"
data.services.typesensestring"connected" or "disconnected"
data.failedServicestring(Only on 503) Name of the first failing dependency

How checks are performedโ€‹

ServiceCheck Method
MongoDBmongoose.connection.readyState === 1
RedisPing command via Redis client
TypesenseSimple GET /health request to the Typesense cluster (timeout 3 seconds)

Error Responsesโ€‹

StatusCodeExample messageWhen
200OK"All services are operational"All dependencies healthy
503SERVICE_UNAVAILABLE"Service Unavailable: One or more dependencies are down."Redis, MongoDB, or Typesense unreachable
429TOO_MANY_REQUESTS"Health check rate limit exceeded."More than 3000 requests in 15 minutes

The health endpoint never returns a 500. Dependency failures always map to 503 to distinguish from application crashes.


Runbookโ€‹

For manual testing with Thunder Client / Postman, see ../../testing/health-runbook.md (if created). The runbook covers:

  • Normal healthy response
  • Simulating Redis failure (stop Redis container)
  • Simulating MongoDB failure
  • Rate limit testing (3000 requests)

Integration with Orchestrationโ€‹

Docker Compose Healthcheckโ€‹

In docker-compose.prod.yml, the API container does not have its own healthcheck; instead, it depends on the healthchecks of MongoDB, Redis, and Typesense. For production, you can add:

reshma-api:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/api/v1/health"]
interval: 30s
timeout: 10s
retries: 3

Kubernetes Liveness & Readinessโ€‹

livenessProbe:
httpGet:
path: /api/v1/health
port: 5000
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /api/v1/health
port: 5000
initialDelaySeconds: 5
periodSeconds: 5


Always know your service status โ€“ the Reshmaโ€‘Core health check engine.