Tutorials Microservices Mastery
Health Checks: Monitoring system vitals in real-time
On this page
Health Checks
Just because a .NET process is "Running" doesn't mean it is healthy. If the API survived but the Database connection is broken, the service is useless. Health Checks allow your infrastructure (Kubernetes, F5, Azure) to know if a service is actually capable of doing its job.
1. Liveness vs Readiness
- Liveness: "Am I alive?" If this fails, K8s will physically restart the container. (Checks if the process is stuck in a loop).
- Readiness: "Am I ready to handle traffic?" If this fails, K8s stops sending user traffic to this Pod but *doesn't* restart it. (Checks DB connection, Redis connection, etc).
2. HealthCheckUI
In .NET, we use the Microsoft.Extensions.Diagnostics.HealthChecks package. We can also add a dashboard (AspNetCore.HealthChecks.UI) that shows a "Green/Red" status for every microservice in the ecosystem on a single screen.
4. Interview Mastery
Q: "Why should a Health Check NEVER perform heavy business logic?"
Architect Answer: "Health checks are called frequently (usually every 10 seconds). If your health check performs a complex SQL JOIN or calls 5 other services, it will put unnecessary load on your system. A health check should be 'Shallow'—just verify that the socket can open and the basic connection is alive. If the health check itself causes a bottleneck, it might lead to a false-positive failure and trigger an unnecessary restart loop."