Video in progress

How can adding a database check to a readiness or liveness probe take down the whole service?

If the database slows down temporarily, the check on every pod fails at the same time. In liveness this leads to a mass restart, and in readiness every pod leaves traffic and the service is 100% unavailable, even though it could have worked partially.

📖 Answer

In Spring Boot, if there is a DataSource, the db health indicator is added automatically and becomes part of the combined /actuator/health. If you point the probes at that combined endpoint, the risk starts there.

The scenario: Postgres had a failover that lasted 40 seconds.

  • Liveness depends on the DB: all pods failed 3 times and Kubernetes restarted them. When the DB comes back, 30 pods are starting at once: a cold JIT, empty caches, all of them opening DB connections. The DB struggles again, a cascade.
  • Readiness depends on the DB: no restarts, but every pod has left the Service. Now even pages that could have worked from the cache return 503.

The right direction in Boot 3:

management:
  endpoint:
    health:
      probes:
        enabled: true
      group:
        readiness:
          include: readinessState
        liveness:
          include: livenessState

By default the liveness and readiness groups look only at the application's internal state (ApplicationAvailability) and don't check external systems. This is deliberate.

When can you add the database to readiness? If the service can do nothing useful without the database and the pods connect to different databases (for example, each pod to its own replica), pulling one pod out makes sense. If all pods look at the same database, failing readiness fixes nothing.

Do you need to know the database's state? Yes, but that is a job for metrics and alerts (hikaricp_connections_pending, the error share), not for a probe. And the application should return a proper error even without the database and protect itself with a circuit breaker.