Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Spring readiness: report an unavailable dependency without forcing liveness failure

Last updated: 30 Sept 20264 min read
tutorial
IntermediateBy AITrove Editorial

A readiness check decides whether an instance should receive work; a liveness check asks whether restarting the instance is warranted.

Download Spring source kit

The local indicator changes state

The source kit injects a BooleanSupplier into a HealthIndicator. When the fixture's receipt store is available, health is UP; after it becomes unavailable, health is DOWN. That proves the indicator's local mapping only. A running Boot application still has to register it in the intended health group and expose that group through the deployment's probe configuration.

A shared database outage can make every replica unready, which may be useful to stop new traffic but can also remove all endpoints from service. Putting the same external check into liveness can cause mass restarts while the database remains down. Actuator health explains the public endpoint boundary. Design the probe after testing the orchestrator's behavior under dependency failure.

Keep diagnostics private

The fixture returns only UP or DOWN. Internal exceptions, credentials, network addresses and detailed dependency state should not be published from a public health endpoint. A check also has a latency and load cost; a slow remote call on every probe can become its own outage trigger.

Checked source

Java
static class ReceiptStoreIndicator implements HealthIndicator {
    private final BooleanSupplier available;
    ReceiptStoreIndicator(BooleanSupplier available) { this.available = available; }
    @Override public Health health() {
        return available.getAsBoolean() ? Health.up().build() : Health.down().build();
    }
}

Verification boundary

ReadinessIndicatorContractTest.localDependencyStateChangesTheIndicatorResult runs in the downloadable Spring source kit. The excerpt leaves out surrounding setup and imports; the kit contains the complete test.

Costs and limits

A BooleanSupplier call is constant-time in the fixture. A real dependency probe needs a bounded timeout, concurrency budget and deployment test. This test does not wire the indicator into a readiness group or prove orchestrator behavior.

Common Mistakes

  • Do not add a shared external dependency to liveness without evaluating restart cascades.
  • Do not expose internal connection details in public health responses.
  • Do not assume a passing unit indicator test proves a deployed probe route.

Read next

Spring Boot Actuator health: public liveness without public diagnostics, Spring Boot metrics: bound tag values instead of tracking each receipt, Spring Boot receipt API project: build, test and inspect the limits.

Continue with checked upload and readiness

Continue with Spring Boot readiness health group: withdraw traffic on a required dependency failure.

Checked file and migration continuation

Continue with Spring Boot and Flyway: choose who runs migrations before traffic starts.

spring
spring-boot
dependency-readiness
Storage details