Microservices & Event-Driven Architecture (EDA) Mastery

Correlation IDs: Tracking requests across services

1 Views Updated 5/4/2026

The Thread that Binds

Tracing is for performance; Correlation IDs are for debugging. It is a single, unique GUID that follows a request through every database, queue, and microservice it touches.

1. Generating the ID

The API Gateway creates a `X-Correlation-ID` if one doesn't exist. This ID is then added to the **Logging Scope** of every service. When you search for this ID in Kibana, you see a chronological list of EVERYTHING that happened for that specific user request across the entire system.

2. Propagation in .NET

We use **Middleware** to extract the Correlation ID from incoming headers and put it into an `AsyncLocal` storage. We then use a **DelegatingHandler** in our `HttpClient` calls to automatically add that same ID to outgoing headers. This ensures the chain is never broken.

4. Interview Mastery

Q: "What is the difference between TraceID and CorrelationID?"

Architect Answer: "Technically, they are very similar. A **TraceID** is often managed by an observability tool (like OpenTelemetry) and is used for timing and system mapping. A **CorrelationID** is often business-defined and used for log aggregation. In modern .NET 8 apps, we often use the `Activity.Current.TraceId` as our Correlation ID to reduce complexity and ensure our logs and traces are perfectly aligned."

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)