Video in progress

What's the difference between liveness and readiness probes?

Liveness answers "is the process alive, does it need a restart?". Readiness says "is it ready to accept traffic right now?"; if it isn't, the instance isn't killed, only temporarily taken out of the load balancer.

📖 Answer

In a Kubernetes environment, Spring Boot Actuator provides both endpoints:

/actuator/health/liveness
/actuator/health/readiness
livenessProbe:
  httpGet: { path: /actuator/health/liveness, port: 8080 }
  periodSeconds: 10
readinessProbe:
  httpGet: { path: /actuator/health/readiness, port: 8080 }
  periodSeconds: 5

A common interview mistake: adding the database state to liveness. If the database drops out for 30 seconds, Kubernetes treats all the pods as "dead" and restarts them, even though the application itself is healthy. As a result, even after the database recovers, the service is busy restarting.

The right approach:

  • liveness: only the application's internal state (a deadlock, an unrecoverable error);
  • readiness: external dependencies can be taken into account, because it only stops traffic.

For apps that start slowly there's also a startupProbe: until it finishes, liveness isn't checked.