Video in progress
What is a correlation ID (request ID), and why do you need it in logs?
A correlation ID is a unique identifier given to a single request, and it is written on every log line related to that request. By searching for that ID, you find the complete history of one request among thousands of interleaved logs.
📖 Answer
In prod the logs come in mixed together: hundreds of requests are running at once, and the lines are interleaved. A customer wrote "my payment didn't go through": which lines are theirs?
If every request gets an ID at the entry point and it is added to every log line:
2026-11-03 10:15:02 INFO [req=7f3a9c] Buyurtma qabul qilindi orderId=881
2026-11-03 10:15:02 WARN [req=7f3a9c] Kartani tekshirish 2-urinish
2026-11-03 10:15:03 ERROR [req=7f3a9c] To'lov rad etildi: insufficient funds
Now searching by req=7f3a9c is enough. If you also return the ID to the customer in the error response, the support team can ask for it and find the request immediately.
In microservices this ID is passed to the next service through a header (for example, X-Request-Id or the W3C traceparent). In current projects the traceId from tracing itself is often used instead of a separate correlation ID.
In Java this is usually done through the MDC: the ID is set in a filter and added to the log pattern automatically.
Sign up to mark studied questions and save your progress.