Correlation IDs Across Services
You'll learn how to link logs from multiple services that handle a single user request using correlation IDs.
When a user request flows through five different microservices, each service generates its own logs. Without a connection between them, debugging feels like trying to solve a mystery with scattered clues—you know something went wrong, but you can't see the complete picture.
The Core Problem
A single API call might touch:
- API Gateway → logs request
- Auth Service → logs authentication
- Order Service → logs order creation
- Payment Service → logs payment processing
- Notification Service → logs email sent
Each service logs independently. How do you know which auth log entry relates to which order log entry?
Enter Correlation IDs
A correlation ID (also called trace ID or request ID) is a unique identifier generated at the entry point of your system and passed through every service in the request chain. Each service includes this ID in its logs.
The analogy: Think of it like a tracking number for a package. Every warehouse that handles your package scans the same tracking number, letting you follow its journey from start to finish.
How It Works
- Generate a correlation ID when the request enters your system (e.g.,
req-a7f3c-9d2e1) - Propagate it through HTTP headers, message queues, or RPC metadata
- Log it with every log entry in every service
- Query centralized logs by correlation ID to reconstruct the entire request flow
With structured logging, each service includes:
{"correlationId": "req-a7f3c-9d2e1", "service": "payment", "message": "payment processed"}
Now you can filter all logs by correlationId and see the complete request journey across all services.
Key Takeaway: Correlation IDs transform scattered service logs into a cohesive story, making distributed system debugging dramatically easier by linking all logs from a single request flow.