What are health checks in ASP.NET Core?
Quick Answer
Health checks expose an endpoint (/health) that reports whether the app and its dependencies are working. Register checks with AddHealthChecks() (built-in ones for SQL Server, Redis, URLs via community packages), map with MapHealthChecks. Orchestrators (Kubernetes, load balancers) poll it to decide whether to route traffic or restart the pod.
A health check endpoint tells the outside world whether the app is OK. You register checks — there are ready-made ones for SQL Server, Redis and so on — and expose them at something like /health. The key distinction is liveness versus readiness: liveness is “is the process running,” and it should be cheap and not touch the database, because you don't want a database blip to make Kubernetes kill your pod. Readiness is “can it actually handle requests,” and that one does check the dependencies, and the load balancer uses it to decide whether to send traffic.
- Liveness — “is the process alive?” — should be cheap and not check dependencies (a failing DB shouldn't get your pod killed).
- Readiness — “can it serve traffic?” — checks dependencies (DB, cache, downstream APIs).
- Tag checks and map separate endpoints:
MapHealthChecks("/health/ready", new() { Predicate = c => c.Tags.Contains("ready") }). - Custom check: implement
IHealthCheckreturningHealthy/Degraded/Unhealthy.