Microservices & Event-Driven Architecture (EDA) Mastery

Service Discovery and Health Checks in .NET

1 Views Updated 5/4/2026

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."

Microservices & Event-Driven Architecture (EDA) Mastery
1. Foundations of Microservices
The Monolith to Microservices transition: When and why? Domain Driven Design (DDD): Bounded Contexts and Aggregates Database Per Service: Managing data consistency Service Discovery and Health Checks in .NET
2. Communication Patterns
Synchronous Communication: HTTP/gRPC and Service Mesh Asynchronous Communication: Message Brokers (RabbitMQ/Kafka) API Gateways: YARP (Yet Another Reverse Proxy) vs Ocelot Protobuf and Shared Contracts: Managing breaking changes
3. Event-Driven Architecture (EDA)
Introduction to EDA: Producers, Consumers, and Topics The Publisher/Subscriber Pattern in .NET Event Sourcing: Capturing every state change CQRS (Command Query Responsibility Segregation) with MediatR
4. Distributed Transactions & Resiliency
The Saga Pattern: Orchestration vs Choreography The Outbox Pattern: Ensuring reliable message delivery Idempotency: Preventing duplicate message processing Distributed Locking with Redis (Redlock)
5. Observability & Monitoring
Distributed Tracing with OpenTelemetry Centralized Logging: ELK Stack (Elasticsearch, Logstash, Kibana) Metrics and Dashboards: Prometheus and Grafana Correlation IDs: Tracking requests across services
6. Security & Identity
Centralized Authentication: IdentityServer4 & Duende Identity OAuth2 and OIDC Flow for Microservices API Key Management and Rate Limiting Mutual TLS (mTLS) for Internal Service-to-Service Security
7. Infrastructure & Deployment
Containerization: Production-grade Dockerfiles Kubernetes for .NET: Pods, Services, and Ingress Helm Charts: Managing complex deployments Blue-Green and Canary Deployments in K8s
8. FAANG Microservices Case Studies
Case Study: Designing a Global Notification Engine (Reliability at Scale) Case Study: Building a High-Performance Logging Pipeline (PB/Day)