Home / Learn Secure SQL / Correlation IDs
Correlation IDs
Tying every log line from one request together, across services.
The idea, explained simply
In plain terms
A correlation ID is a unique identifier generated at the start of a request and passed through every service, log line, and downstream call involved in handling it, letting you reconstruct the full path of one request later.
Why we use it
In a system with multiple services, a single user action can touch many components; without a shared correlation ID, reconstructing what happened across all of them during an investigation is far harder.
Under the hood
Generate a correlation ID (or accept one from an incoming request header) at the entry point, include it in every log line for that request, and forward it in any downstream service calls.
Real-world use
- Web application code review
- Backend development
- Database administration
const correlationId = req.headers['x-correlation-id'] || crypto.randomUUID();
logger.info('order_created', { correlationId, orderId });Quick quiz
1. A correlation ID's main purpose is...
Ties related log lines together.