Tutorials Microservices & Event-Driven Architecture (EDA) Mastery

Service Discovery and Health Checks in .NET

On this page

Dynamic Infrastructure

In a cloud environment, IP addresses are ephemeral. Containers die and restart constantly. You need a way for Service A to find Service B without hard-coding URLs.

1. Service Discovery (Consul / K8s DNS)

In Kubernetes, we use **CoreDNS**. You just call `http://payment-service` and K8s handles finding the right IP of a healthy instance. In non-K8s environments, tools like **Consul** allow services to 'Register' themselves and their health status in a central registry.

2. Health Checks: The Vital Signs

.NET has a built-in Health Check middleware. It's not just "Is the app running?". A real health check verifies:

  • **Database Connectivity:** Can I ping SQL?
  • **Memory Usage:** Is the pod near its limit?
  • **External APIs:** Is Stripe/SendGrid reachable?
If these fail, the Load Balancer automatically stops sending traffic to that instance until it recovers.

4. Interview Mastery

Q: "What is the difference between a 'Liveness' probe and a 'Readiness' probe?"

Architect Answer: "A **Liveness** probe tells K8s: 'Am I alive or dead?'. If it fails, K8s kills and restarts the container. A **Readiness** probe tells K8s: 'I'm alive, but I'm busy (e.g., heating up cache or migrating DB)'. If it fails, K8s keeps the container alive but stops sending it traffic. Using only Liveness probes can lead to 'Restart Loops' where a slow-starting service is killed before it can finish booting."

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Microservices & Event-Driven Architecture (EDA) Mastery
Course syllabus
1. Foundations of Microservices
2. Communication Patterns
3. Event-Driven Architecture (EDA)
4. Distributed Transactions & Resiliency
5. Observability & Monitoring
6. Security & Identity
7. Infrastructure & Deployment
8. FAANG Microservices Case Studies
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details