When debugging production issues, logs are your best friends. But in multi-threaded applications or systems handling multiple requests, logs can quickly become messy and hard to trace. This is where MDC (Mapped Diagnostic Context) and NDC (Nested Diagnostic Context) come in. 🔹 What is MDC? MDC (Mapped Diagnostic Context) allows you to store key-value pairs that are automatically added to your log entries. 👉 Example use case: Storing userId , transactionId , or requestId in MDC so every log line contains this contextual information. This makes tracing requests across distributed services much easier. Code Example (SLF4J with Logback): import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; public class MDCExample { private static final Logger log = LoggerFactory.getLogger(MDCExample.class); public static void main(String[] args) { MDC.put("userId", "12345"); MDC.put("transactionId", "...