and the service is highly scalable and (potentially) highly available; each instance can generate many thousand IDs per second, and you can run multiple instances on your LAN/WAN;
用 Scala 编写,在 JVM 上运行。
b) You could generate the unique IDs on the clients themselves, using an 这种方法来源于如何制作 UUID 和雪花的 ID。 There are multiple options, but something along the lines of:
最重要的40位左右: 时间戳; ID 的生成时间。(我们使用时间戳中最重要的位使 ID 可以按生成时间进行排序。)
The next 14 or so bits: 每台发电机计数器, which each generator increments by one for each new ID generated. This ensures that IDs generated at the same moment (same timestamps) do not overlap.
最后10位左右: A unique value for each generator.使用这个函数,我们不需要在生成器之间进行任何同步(这非常困难) ,因为所有生成器都会因为这个值而产生不重叠的 ID。
C)您可以在客户端上生成 ID,只需使用 timestamp and random value.,这样就避免了需要知道所有的生成器,并为每个生成器分配一个唯一的值。另一方面,这样的 ID 不是 保证全局唯一的,它们只是 very highly likely唯一的。(要发生碰撞,一个或多个发生器必须在完全相同的时间创建相同的随机值。)类似于:
What we do is, We create a buffer of ids, Initially, the queue will have 0 to 20 ids that are ready to be dispatched when requested. Multiple clients can request an id and redis will pop 1 id at a time, After every pop from left, we insert BUFFER + currentId to the right, Which keeps the buffer list going. Implementation 给你