Skip to content

X-Request-ID

Unique identifier for tracking a specific request through distributed systems and logs.

The X-Request-ID header (also known as Request-ID) contains a unique identifier assigned to each HTTP request. This identifier allows developers and operations teams to trace a single request as it flows through multiple services, load balancers, proxies, and application layers. It’s invaluable for debugging, monitoring, and correlating log entries across distributed systems. The header can be set by the client, a load balancer, or the first service that receives the request.

Include this header in every request and response in distributed systems, microservices architectures, or any application where request tracing is important. It should be generated at the edge of your system (load balancer or API gateway) if not provided by the client.

When debugging production issues, you need to correlate logs across multiple services handling the same request. Without a request ID, finding related log entries is nearly impossible in high-traffic systems. This header enables end-to-end request tracing, performance monitoring, and error tracking across your entire stack.

Generate a unique identifier (typically a UUID) for each incoming request and propagate it through all downstream services. Log this ID with every log entry related to the request.

Example code in Javascript (Express middleware):

import { v4 as uuidv4 } from 'uuid';
app.use((req, res, next) => {
const requestId = req.headers['x-request-id'] || uuidv4();
req.id = requestId;
res.setHeader('X-Request-ID', requestId);
console.log(`[${requestId}] ${req.method} ${req.path}`);
next();
});

Example code in Javascript (Fetch client):

fetch('https://api.example.com/data', {
headers: {
'X-Request-ID': crypto.randomUUID()
}
});
X-Request-ID: 550e8400-e29b-41d4-a716-446655440000