What are health checks in ASP.NET Core?
Quick Answer
Health checks expose an endpoint (/healthz) reporting whether the app and its dependencies are working. Orchestrators (Kubernetes, load balancers) poll it to decide whether to route traffic or restart the pod. Split liveness (is the process alive?) from readiness (can it serve requests — DB reachable, cache warm?).
Health checks are a standard endpoint the infrastructure hits to know the state of the app. The important distinction is liveness versus readiness. Liveness answers “is this process wedged, should you kill it” and must be cheap and not touch dependencies — if the database is down you don't want Kubernetes restarting every replica in a loop. Readiness answers “can this instance actually handle a request right now” and does check the database, the cache, downstream services, so the load balancer stops sending traffic to an instance that can't fulfil it. ASP.NET Core has built-in checks for SQL Server, Redis and so on that you compose and tag.
builder.Services.AddHealthChecks().AddSqlServer(cs).AddRedis(cs);thenapp.MapHealthChecks("/healthz/ready", new(){ Predicate = c => c.Tags.Contains("ready") });.- A liveness probe should be cheap and dependency-free — a failing DB shouldn't restart a healthy process, just stop new traffic.
- Statuses:
Healthy,Degraded(still serving, e.g. slow),Unhealthy. - Don't expose detailed internal info on a public health endpoint.