What is the ASP.NET Core Health Checks middleware, and what problem does it solve?
Short answer
The Health Checks middleware (Microsoft.AspNetCore.Diagnostics.HealthChecks) provides a standardized way for an application to report its own operational health status, exposed via an HTTP endpoint (typically /health) that returns Healthy, Degraded, or Unhealthy -- this lets…
Advertisement
AModel answer
The Health Checks middleware (Microsoft.AspNetCore.Diagnostics.HealthChecks) provides a standardized way for an application to report its own operational health status, exposed via an HTTP endpoint (typically /health) that returns Healthy, Degraded, or Unhealthy -- this lets external systems (load balancers, container orchestrators like Kubernetes, monitoring dashboards) programmatically determine whether an instance is functioning correctly and should continue receiving traffic, without needing custom application-specific monitoring logic.
// Program.cs
builder.Services.AddHealthChecks();
var app = builder.Build();
app.MapHealthChecks("/health");
// A simple GET /health request returns "Healthy" with 200 OK if no checks failReal-world example
A Kubernetes deployment configures a liveness probe pointing at an app's /health endpoint, automatically restarting any pod instance that starts reporting Unhealthy, without requiring manual monitoring intervention.
Likely follow-ups
- What's the difference between liveness and readiness health checks?
- How do you add a custom check for a specific dependency like a database?
Related topics