Software Engineering Glossary

Correlation ID

Also known as: Request ID Message ID Trace ID

A correlation id is a unique value attached to a request so its response can be matched back to it later, even when many requests are in flight and replies arrive out of order. The sender keeps a map of correlation id to pending request, and when a response echoes the same id, the sender knows exactly which request it belongs to. It is what makes asynchronous messaging, pipelining, and a request waiting list work.

Key Takeaways

  • It ties an asynchronous response back to the request that caused it, without relying on arrival order.
  • Every response must echo the same id the request carried, so the receiver can look it up.
  • It is the key that a pending-requests map or request waiting list is indexed on.
  • The same id, propagated across services, becomes a trace id that lets you follow one request through a whole system.

How It Works

  1. The sender generates a unique id and stamps it on the outgoing request.
  2. It stores the id in a map that points to the waiting caller, future, or callback.
  3. The receiver copies the id onto its response.
  4. When the response arrives, the sender reads the id, finds the matching entry, and completes it.

Where It Is Used

  • gRPC and HTTP/2 use per-stream ids so multiplexed responses can arrive in any order.
  • Message brokers and RPC frameworks stamp a correlation id on each message for request-reply.
  • Distributed tracing tools like OpenTelemetry propagate a trace id, a correlation id spanning many services.

Related glossary terms