Clocks, Ordering, and Unique IDs

Wall clocks on different machines can drift and jump. Do not assume timestamps from two hosts provide a perfect total order. NTP reduces clock skew but does not make distributed clocks identical. Use monotonic clocks for measuring elapsed time and wall-clock timestamps for human-oriented event time.

Identifiers can be generated centrally, randomly, or in a distributed fashion. UUIDs reduce coordination but may be less compact or less locality-friendly depending on version and storage. Snowflake-style IDs combine time and worker identity, requiring careful worker allocation and clock rollback handling. Database-generated sequences are simple but may create a central dependency.

If order matters, define what kind: per-entity order, partition order, causal order, or global order. Global ordering is expensive and often unnecessary. Use sequence numbers, optimistic versions, partitioned logs, or consensus only when the required semantics justify the cost.

Key Takeaways
  • Timestamps do not guarantee a global event order.
  • Choose IDs based on uniqueness, locality, and coordination needs.
  • Specify the scope of ordering before implementing it.