Skip to content
System Design Lab
Microservice Patterns

Health Checks

Let the platform ask each instance "can you serve traffic?" so dead or warming instances are taken out of rotation — without building a health check that takes down the whole fleet.

Beginner 4 min read· Updated 2026-11-18

What you will learn

  • Distinguish liveness, readiness and startup checks and who acts on each.
  • See how active probes remove a hung instance that passive signals miss.
  • Avoid the deep-health-check trap that ejects every instance at once.
  • Configure Spring Boot Actuator probes and Kubernetes health checks.

Before you start

Overview

A restaurant manager walks past every station before the doors open and during service: "Are you ready? Are you okay?" A cook who has burned their hand is sent home; a cook still setting up is not given orders yet. Health checks are that walk-around for servers.

A health check is an endpoint (or command) that reports whether an instance can do its job. Load balancers and orchestrators call it periodically and act on the answer: stop routing traffic to the instance, or restart it.

Liveness, readiness, startup

CheckQuestionAction on failure
LivenessIs the process stuck beyond repair (deadlock, broken event loop)?Restart the instance.
ReadinessShould this instance receive traffic right now (warmed up, not overloaded, not shutting down)?Remove it from the load balancer until it passes again.
StartupHas a slow-starting app finished booting?Delay liveness checks so the app is not killed while starting.

Run it

A hung instance accepts connections but never answers, so passive error counting may never notice it. Compare A and B. Scenario C is the most common real-world mistake; scenario D shows readiness protecting a rolling deploy.

Loading simulation…

Implementation: Spring Boot Actuator + Kubernetes

application.yml
management:
  endpoint:
    health:
      probes:
        enabled: true           # /actuator/health/liveness and /actuator/health/readiness
      group:
        readiness:
          include: readinessState   # do NOT add db here unless the app is useless without it
  endpoints:
    web:
      exposure:
        include: health
deployment.yaml (excerpt)
containers:
  - name: shop-api
    image: shop-api:1.42.0
    startupProbe:
      httpGet: { path: /actuator/health/liveness, port: 8080 }
      periodSeconds: 5
      failureThreshold: 30        # allow up to 150 s to start
    livenessProbe:
      httpGet: { path: /actuator/health/liveness, port: 8080 }
      periodSeconds: 10
      failureThreshold: 3
    readinessProbe:
      httpGet: { path: /actuator/health/readiness, port: 8080 }
      periodSeconds: 2
      failureThreshold: 2

Advanced Spring Boot marks readiness as REFUSING_TRAFFIC during graceful shutdown, so Kubernetes stops routing before in-flight requests are cut. Warm caches and JIT before declaring readiness (e.g. publish AvailabilityChangeEvent with ReadinessState.ACCEPTING_TRAFFIC after a warm-up job) to avoid the latency spike in scenario D.

Trade-offs

BenefitsCosts
Active probesDetect hung or idle instances that passive signals miss.Extra traffic; probe interval × threshold delays detection.
Deep checksCatch broken configuration (bad credentials) early.Correlated failures: a shared dependency ejects the whole fleet.
Aggressive livenessStuck processes are restarted quickly.Slow-but-alive instances get killed during load spikes, making things worse.

Production considerations

  • Answer health checks on a separate thread pool or port so a saturated app still responds (or deliberately reports not-ready).
  • Keep liveness dumb: "is the process responsive?" Never put dependencies in liveness — restarting does not fix the database.
  • Fail open: if every instance is unhealthy, many load balancers route to all of them anyway; know what yours does.
  • Combine with passive outlier detection in the load balancer.

Further reading

Related topics