Video in progress
Should you add a DB check to liveness and readiness probes?
Not to liveness: restarting a pod doesn't fix a missing DB, and all the pods reboot at once. To readiness, carefully: if one shared dependency goes down, all the pods leave traffic and the service doesn't respond at all instead of returning 503.
📖 Answer
The liveness question: "has this process entered an unrecoverable state?" (a deadlock, memory full, a stuck event loop). If the answer is "yes", a restart helps.
The readiness question: "can I accept traffic right now?" (startup isn't finished, the cache isn't warm, shutdown has begun).
A case that happened in prod: the DB failed over for 30 seconds. The liveness probe had a DB check, so all 20 pods restarted. When the DB came back, 20 pods started up at the same time, filled their connection pools and ran their migration checks. The DB struggled again. A 30-second problem turned into a 10-minute outage.
The right setup in Spring Boot 3:
management:
endpoint.health.probes.enabled: true
endpoint.health.group:
liveness:
include: livenessState
readiness:
include: readinessState
By default Boot doesn't add external dependencies to the liveness and readiness groups, so don't break that. Adding the DB to readiness makes sense only when one of the pods can't reach the DB (for example, only its own connection pool is broken). All the pods look at the same DB, and if it goes down, returning a fast 503 is better than pulling them out of traffic: the client at least gets a clear error.
If startup is slow, add a startupProbe: liveness isn't checked until it finishes.
Sign up to mark studied questions and save your progress.