# Readiness vs Liveness Probes in ASP.NET Core

> Put a database check in your liveness probe and a database outage becomes a restart storm: Kubernetes kills every healthy pod in the fleet, over and over, until the database returns. The fix is a tag-based split of your health checks. Here is the setup, and the reasoning for which check goes where.

Published: 2026-11-26. Author: Milan Jovanović. Topic: Resilience. Tags: aspnetcore, health-checks, kubernetes, resilience.

Canonical: https://milanjovanovic.tech/blog/readiness-vs-liveness-probes-aspnetcore

A common Kubernetes health check setup makes a dependency outage worse.

The app has one health endpoint.
It checks the database, because "healthy" surely means "can reach the database".
Both the liveness and readiness probes point at it.

Then the database has a bad five minutes.
Every pod's liveness probe fails, so Kubernetes kills and restarts every pod.
The restarted pods come up, still can't reach the database, fail liveness again, and get killed again.
A database blip is now *also* a full application outage: a restart storm while it lasts, then cold caches and connection stampedes when the database finally returns.

The root cause is that the two probes ask different questions and need different answers.

## How Liveness and Readiness Probes Differ

**Liveness** asks: is this *process* broken in a way a restart would fix?
Deadlocked threads, a wedged event loop, unrecoverable internal state.
If it fails, Kubernetes kills the container and starts a new one.

**Readiness** asks: should this pod receive *traffic* right now?
Still warming up, dependency unavailable, mid-shutdown.
If it fails, Kubernetes removes the pod from service endpoints until the probe passes again.

Now apply the database test.
A restart can't fix a database outage.
A pod that can't reach the database probably shouldn't receive traffic either.

The same failing check calls for opposite reactions, so split the probes.
**Liveness checks the process, readiness checks the dependencies.**
A liveness probe should be so trivial it can only fail if the process itself is unable to serve HTTP at all.

![Two probes with opposite reactions: a failing liveness self check restarts the container, while a failing readiness dependency check only removes the pod from the service endpoints](https://milanjovanovic.tech/blogs/articles/readiness-vs-liveness-probes-aspnetcore/liveness-vs-readiness.png)

| Concern | Liveness | Readiness |
| --- | --- | --- |
| Question it answers | Is the process broken in a way a restart would fix? | Should this pod receive traffic right now? |
| Reaction to failure | Kubernetes kills and restarts the container | Kubernetes removes the pod from Service endpoints until the probe passes |
| What it checks | A trivial self check, tagged live | Hard dependencies such as the database, tagged ready |
| Endpoint in this article | /health/live | /health/ready |
| During a database outage | Keeps passing, so nothing restarts | Fails, so the pod leaves rotation until the database returns |

## The Tag-Based Split in ASP.NET Core

ASP.NET Core's [**health checks**](https://milanjovanovic.tech/blog/health-checks-in-asp-net-core) support tags exactly for this.
Register a trivial self check tagged `live`, and dependency checks tagged `ready`:

```bash
dotnet add package AspNetCore.HealthChecks.NpgSql
dotnet add package AspNetCore.HealthChecks.Rabbitmq
```

```csharp
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using RabbitMQ.Client;

var builder = WebApplication.CreateBuilder(args);

// AddRabbitMQ() with no factory checks the IConnection registered in DI.
builder.Services.AddSingleton<IConnection>(_ =>
{
    var factory = new ConnectionFactory
    {
        Uri = new Uri(builder.Configuration.GetConnectionString("RabbitMq")!)
    };

    return factory.CreateConnectionAsync().GetAwaiter().GetResult();
});

builder.Services.AddHealthChecks()
    // Liveness: trivial. If this fails, the process is truly wedged.
    .AddCheck("self", () => HealthCheckResult.Healthy(), tags: ["live"])
    // Readiness: hard dependencies only.
    .AddNpgSql(
        builder.Configuration.GetConnectionString("Database")!,
        name: "postgres",
        tags: ["ready"])
    .AddRabbitMQ(
        name: "rabbitmq",
        tags: ["ready"]);

var app = builder.Build();

app.MapHealthChecks("/health/live", new HealthCheckOptions
{
    Predicate = registration => registration.Tags.Contains("live")
});

app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
    Predicate = registration => registration.Tags.Contains("ready")
});

app.Run();
```

The RabbitMQ check reuses the application's long-lived connection, so the app registers one `IConnection` singleton; without it, the check reports `Unhealthy` and `/health/ready` never passes.

The `Predicate` makes each endpoint run only the checks whose tags match.
`/health/live` executes the self check and nothing else, so a database outage cannot fail it.
`/health/ready` executes the dependency checks, so a pod that loses the database is removed from rotation and added back when connectivity returns.

Without a predicate, `MapHealthChecks` runs *every* registered check, which is precisely the single-endpoint mistake this article opened with.
The moment anyone registers a new `AddCheck` without thinking about probes, an unfiltered liveness endpoint starts running it too.

## Wiring It Into Kubernetes

The deployment manifest points each probe at its endpoint:

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: orders-api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: orders-api
  template:
    metadata:
      labels:
        app: orders-api
    spec:
      containers:
        - name: orders-api
          image: registry.example.com/orders-api:1.4.2
          ports:
            - containerPort: 8080
          startupProbe:
            httpGet:
              path: /health/live
              port: 8080
            failureThreshold: 30
            periodSeconds: 2
          livenessProbe:
            httpGet:
              path: /health/live
              port: 8080
            periodSeconds: 10
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /health/ready
              port: 8080
            periodSeconds: 5
            failureThreshold: 2
```

Notes on the numbers:

- The **startup probe** gives the app up to 60 seconds (30 x 2s) to come up before liveness probing begins. Without it, liveness probing starts right away, so a pod that needs 45 seconds to warm up (EF Core model building, cache priming) fails three liveness probes 10 seconds apart and is restarted within about 30 seconds, on every restart.
- Liveness tolerates 3 failures 10 seconds apart: a restart is triggered only after ~30 seconds of an unresponsive process.
- Readiness reacts faster (2 failures, 5 seconds apart), because pulling a pod from rotation is cheap and quick recovery is the point.

Play the database outage forward with this setup.
Readiness fails on all pods and the Service's endpoint list empties out.

In-cluster callers get fast connection-refused errors, because kube-proxy rejects traffic to a Service with no ready endpoints; requests that come through an ingress controller or service mesh get a 503 from that proxy.
Their [**retry policies**](https://milanjovanovic.tech/blog/retry-vs-circuit-breaker) and fallbacks should be handling both anyway.

Liveness keeps passing, so the processes stay up, connection pools intact, caches warm.
Database recovers, readiness passes on the next probe cycle, and traffic resumes within seconds, with zero restarts.

The same split works outside Kubernetes too: load balancer health checks should target `/health/ready`, while anything that *recycles* a process when its check fails should target `/health/live`.
**Docker health checks** depend on the runtime: plain Docker only marks the container unhealthy, but Docker Swarm replaces unhealthy tasks, so a Swarm health check belongs on `/health/live`.

## What Belongs in a Readiness Check?

The liveness side is easy: the self check, and nothing else.
Resist the urge to make it smarter; every condition you add is a new way to restart healthy pods.

Readiness requires more judgment.
The test: **can this pod serve any meaningful traffic without the dependency?**

- **Database, when every endpoint needs it**: yes, readiness.
- **Message broker, for a service whose job is consuming messages**: yes.
- **Redis cache with a database fallback behind it**: no. The pod still serves requests without Redis, just slower. Taking it out of rotation converts a degraded state into an outage.
- **Third-party APIs**: almost never. You don't want a vendor's bad day emptying your service endpoints, especially when a [**fallback**](https://milanjovanovic.tech/blog/fallback-pattern-polly-dotnet) already covers that dependency.
- **Optional features' dependencies**: no. That's what per-feature degradation is for.

In the "yes" cases, if all pods share the dependency, readiness failure is all-or-nothing, and an empty endpoint list behaves like an outage anyway.
That's still strictly better than the restart storm (recovery is instant and stateless), but readiness is per-pod machinery being used to express a cluster-wide fact.

Also make dependency checks cheap and bounded.
A readiness check that runs `SELECT 1` with a 2-second timeout is fine; one that runs an unindexed query against a struggling database every 5 seconds from 50 pods is additional load exactly when the database can least afford it.
For deeper monitoring (measuring what's degraded and why), use a separate diagnostics endpoint with richer **health check output**, locked away from the probes.

## Summary

Probes are automated actions, not monitoring.
A liveness failure restarts the container; a readiness failure routes traffic around the pod.
Write each check by asking which of those reactions you want when it fails.

- Liveness: a trivial self check, tagged `live`. If the process can answer HTTP, it's alive.
- Readiness: hard dependencies only, tagged `ready`. Database yes (when every endpoint needs it), cache and third parties no.
- Filter with `HealthCheckOptions.Predicate` on separate endpoints; never expose an unfiltered health endpoint to a probe.
- Add a startup probe for slow starters, and keep dependency checks cheap and time-bounded.

## Frequently asked questions

### What is the difference between readiness and liveness probes?

Liveness asks "is this process broken beyond recovery?" and a failure triggers a container restart. Readiness asks "should this pod receive traffic right now?" and a failure only removes the pod from service endpoints. Restarting is destructive; removing from rotation is reversible.

### Should a liveness probe check the database?

No. A database outage would fail liveness on every pod, and Kubernetes would restart your entire healthy fleet in a loop until the database recovers. Restarting an app does not fix a database. Dependency checks belong in readiness, where the reaction is to stop routing traffic.

### How do I split health checks in ASP.NET Core?

Tag each check when registering it, then map two endpoints with HealthCheckOptions.Predicate filtering by tag: a /health/live endpoint that runs only a trivial self check, and a /health/ready endpoint that runs dependency checks like database and message broker connectivity.

### What is a startup probe for?

It gives slow-starting apps time to initialize before liveness kicks in. Kubernetes withholds liveness and readiness probing until the startup probe succeeds. With the default liveness settings (three failures, 10 seconds apart), a pod that needs a minute to warm up would otherwise be restarted within about 30 seconds, every time.

### Should readiness checks include every downstream dependency?

Only hard dependencies the pod cannot serve any meaningful traffic without. If a dependency is optional or protected by a fallback, keep it out of readiness; otherwise a degraded but working feature takes the whole pod out of rotation.
