flashman
← All guides

UUIDs and correlation IDs in distributed systems

Generate UUID v4 values, trace requests across services, and avoid ID collisions.

2026-06-04 · 5 min read

  • uuid
  • backend

Universally Unique Identifiers (UUIDs) are 128-bit values, usually shown as 36-character strings. Version 4 UUIDs are random and ideal for database primary keys, correlation IDs in logs, and idempotency keys.

UUID v4 vs other versions

For most web apps, v4 is the safe default when ordering is not required.

  • v4 — random, no coordination needed
  • v1 — time-based, can leak MAC-derived data (avoid in public IDs)
  • v7 — time-ordered random (growing adoption for databases)

Correlation IDs

Attach a UUID to each inbound HTTP request and propagate it through microservices. Log the same ID everywhere to stitch traces in Kibana or CloudWatch without guessing.

Collision probability

Random UUID collisions are astronomically unlikely for practical deployments. Still use database unique constraints as the source of truth.

Try these tools