Skip to content

Correlation ID

Medium — good to knowBackend

ELI5 — The Vibe Check

A correlation ID is like a tracking number for a request as it bounces between microservices. When a user's request touches 5 different services, the correlation ID ties all the logs together. Without it, debugging distributed systems is like finding a needle in a haystack — blindfolded.

Real Talk

A correlation ID is a unique identifier propagated through all services and components handling a single request. It's typically generated at the API gateway or first service and passed via headers (X-Correlation-ID). It enables end-to-end request tracing across distributed systems by linking logs, metrics, and spans from different services.

Show Me The Code

app.use((req, res, next) => {
  req.correlationId = req.headers['x-correlation-id'] || uuid();
  res.setHeader('X-Correlation-ID', req.correlationId);
  logger.addContext('correlationId', req.correlationId);
  next();
});

When You'll Hear This

"Search the logs by correlation ID to trace the request across all services." / "Every microservice must forward the correlation ID to downstream calls."

Made with passive-aggressive love by manoga.digital. Powered by Claude.