ASP.NET Core › Health Checks
How would you implement a startup-specific health check distinct from ongoing liveness/readiness, useful for slow-starting applications with lengthy initialization (like cache warming or large data loads)?
AdvancedAnswer
Kubernetes supports a distinct startupProbe specifically for slow-starting containers, giving the application a longer grace period during initial startup before liveness probing begins (preventing Kubernetes from prematurely killing a container still legitimately warming up) -- implemented in ASP.NET Core by tagging a set of checks representing 'has initial startup work completed' (like cache pre-loading, initial data sync) and exposing them at a separate /health/startup endpoint, distinct from the ongoing /health/live and /health/ready endpoints used after startup completes.
public class StartupCompleteHealthCheck : IHealthCheck {
public static volatile bool IsStartupComplete = false;
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken ct = default) {
return Task.FromResult(IsStartupComplete ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy("Still warming up"));
}
}
// A hosted service sets IsStartupComplete = true once cache warming finishes
app.MapHealthChecks("/health/startup", new HealthCheckOptions { Predicate = c => c.Tags.Contains("startup") });Real-world example A service with a multi-minute in-memory cache warm-up on startup configures a Kubernetes startupProbe against /health/startup with a generous timeout, preventing Kubernetes from repeatedly killing and restarting the pod during legitimate slow startup, while the separate liveness probe only begins once startup genuinely completes.