An extremely fast UUID alternative, 10-135 times faster

From time to time, we need to give something (like requests, objects, etc.) unique numbers. Timestamp and random number cannot ensure uniqueness, UUID and generating IDs with Redis are slow. Therefore, I created WUID, an extremely fast unique number generator.

WUID is 10-135 times faster than UUID and 4600 times faster than generating unique numbers with Redis. It generates unique 64-bit integers in sequence. The high 24 bits are loaded from a data store. By now, Redis, MySQL, and MongoDB are supported.

Benchmarks

BenchmarkWUID       100000000           10.3 ns/op         0 B/op          0 allocs/op
BenchmarkRand        50000000           24.6 ns/op         0 B/op          0 allocs/op
BenchmarkTimestamp  100000000           12.3 ns/op         0 B/op          0 allocs/op
BenchmarkUUID_V1     20000000          107 ns/op           0 B/op          0 allocs/op
BenchmarkUUID_V2     20000000          106 ns/op           0 B/op          0 allocs/op
BenchmarkUUID_V3      5000000          359 ns/op         144 B/op          4 allocs/op
BenchmarkUUID_V4      1000000         1376 ns/op          16 B/op          1 allocs/op
BenchmarkUUID_V5      3000000          424 ns/op         176 B/op          4 allocs/op
BenchmarkRedis          30000        46501 ns/op         176 B/op          5 allocs/op
BenchmarkSnowflake    5000000          244 ns/op           0 B/op          0 allocs/op

Features

  • Extremely fast
  • Thread-safe
  • Being unique within a data center
  • Being unique across time
  • Being unique globally if all data centers share the same data store, or they use different section IDs
  • Being capable of generating 100M unique numbers in a single second
  • Auto-renew when the low 40 bits are about to run out

If you are interested in the project, take a look at https://github.com/edwingeng/wuid

Does “…in sequence” literally mean what it says? That is, does the generator just autoincrement the previous ID?

These ID’s should not be used in a security-sensitive context then. ID’s that are just monotonously increasing sequences can leak information to attackers.

1 Like

Yeah, you are right :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.