Skip to the content.

Timestamp as Unique ID

Timestamps can effectively serve as unique identifiers, particularly in real-time systems. Let’s explore how timestamps work as IDs, including more technical considerations.

Why Use Timestamps?

Granularity of Timestamps

Example: The Unix timestamp for August 16, 2024, 12:00 PM UTC1729214400123.

Storage Calculation

To determine how many bits are needed for storing millisecond-based timestamps:

Thus, a 42-bit integer can store millisecond-precision timestamps spanning 100 years.

Custom Epoch

If you use timestamp as such, 100 years would be counted from January 1, 1970.

So, it would be ideal to change the epoch to a new date, say August 16, 2024:

  1. Calculate the Epoch Offset:
    Find the milliseconds between the original epoch and the new one.

  2. Adjust Timestamps:
    Subtract this offset from all future timestamps.

Formula:

text{new_timestamp} = text{unix_timestamp} - text{offset}

Collision Handling

Clock Skew in Distributed Systems

Use Cases

Conclusion

Timestamps are a powerful way to generate unique IDs with built-in time context, especially in systems that benefit from naturally ordered IDs. With 42 bits, millisecond-precision timestamps can comfortably represent over 100 years of data, making them a compact and efficient alternative to UUIDs or other unique ID systems.