Correlation IDs from Edge to Worker: Debugging Distributed Failures Faster

Without a shared request ID, logs across API, queue, and worker cannot be stitched together quickly. Correlation IDs turn scattered logs into one timeline.

Step 1: generate or accept correlation ID at API edge

const cid = req.header('x-correlation-id') || crypto.randomUUID()
res.setHeader('x-correlation-id', cid)

Step 2: propagate ID in async payloads

{
  "job": "publish_post",
  "correlation_id": "2f3a...",
  "post_id": 1417
}

Step 3: include ID in every structured log line

logger.info({ cid, step: 'worker.start', jobId })

Pitfall

Generating a new ID in every service hop. You lose end-to-end traceability.

Verification

  • One ID links edge request, queue event, and worker execution.
  • Incident triage finds root cause in one log query.
  • Missing ID paths trigger alerts.

Get New Tutorials by Email

No spam. Just clear, practical breakdowns you can apply right away.

Enjoy this tutorial?

Get new practical tech tutorials in your inbox.