ASP.NET Core Web API Interview Question #147

What are health checks in ASP.NET Core?

Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced

Quick Interview Answer

Health checks expose application health information for infrastructure such as orchestrators, load balancers, and monitoring systems. Checks can report whether the process is running and whether critical dependencies are available.

Detailed Explanation

Health checks expose application health information for infrastructure such as orchestrators, load balancers, and monitoring systems. Checks can report whether the process is running and whether critical dependencies are available.

Health endpoints should be designed carefully: readiness and liveness have different purposes, and detailed dependency information should not be exposed publicly without appropriate controls.

Code Example

builder.Services.AddHealthChecks()
    .AddDbContextCheck<AppDbContext>();

app.MapHealthChecks("/health");