📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Microservices Health Checks

Health Checks

5 min read Quiz at the end
Liveness restarts crashed services; readiness removes unhealthy pods from load balancer traffic.

Health Checks and Readiness Probes

@app.get("/health")
def liveness():
    """Liveness: is the service running?"""
    return {"status": "alive", "service": "user-service"}

@app.get("/ready")
def readiness():
    """Readiness: is service ready for traffic?"""
    try:
        db.execute("SELECT 1")
        redis_client.ping()
        return {"status": "ready"}
    except Exception as e:
        return {"status":"not ready","error":str(e)}, 503

# Kubernetes probes
livenessProbe:
  httpGet: {path: /health, port: 8000}
  initialDelaySeconds: 10
  periodSeconds: 30
  failureThreshold: 3

readinessProbe:
  httpGet: {path: /ready, port: 8000}
  periodSeconds: 10
  failureThreshold: 3
Topic Quiz · 1 questions

Test your understanding before moving on

1. What is the difference between a liveness probe and a readiness probe?
💡 Liveness = is the process alive? Readiness = is the service ready to serve traffic?