C# Interview Question #190

What are health checks in ASP.NET Core?

Testing, Security, APIs & Reliability Senior Advanced

Quick Interview Answer

Health checks expose application health information that infrastructure can use for monitoring, orchestration, and traffic management.

Detailed Explanation

Health checks expose application health information that infrastructure can use for monitoring, orchestration, and traffic management.

Checks can verify whether the application is alive and whether critical dependencies such as databases or external services are reachable.

Liveness and readiness should be distinguished. Liveness indicates whether the process should be restarted, while readiness indicates whether the application is currently able to receive traffic.

Health endpoints should avoid exposing sensitive internal information publicly.

Code Example

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

app.MapHealthChecks("/health");