cpuidentity

Is it safe to assume 64-bit counter doesn't suffer from overflow?


32-bit counters overflow fast.

128-bit space is considered "infinite" (should exceed life of the Universe, so used as UIDs).

What about 64-bit counter? Are they practically "infinite"? Can one use them for assigning DB IDs?


Solution

  • World records for overclocking a CPU are around 10 GHz. If we assume a CPU was running at that frequency, and every cycle was used to increment a 64-bit counter, it would overflow in about 58 years.

    Of course, it is possible to assign IDs in a way that generally resembles a sequential counter, but is actually parallelized. If we imagine a 1,000,000 node distributed database with each node allocating IDs at only 10 MHz, it would only take 5.8 years to fill up the entire space of 64-bit integers. Plenty of things last more than 6 years.

    Doing something 2^64 times is definitely something within the scope of what human society can do right now. One could contrive scenarios where quasi-sequentially allocated 64-bit ints could be used up in some database. But for a single computer, and for almost all projects, it is not plausible, and it's safe to use 64-bit counters.