Distributed sequence number generation?

后端 未结 13 1752
小鲜肉
小鲜肉 2020-11-29 14:32

I\'ve generally implemented sequence number generation using database sequences in the past.

e.g. Using Postgres SERIAL type http://www.neilconway.o

相关标签:
13条回答
  • 2020-11-29 15:17

    It can be done with Redisson. It implements distributed and scalable version of AtomicLong. Here is example:

    Config config = new Config();
    config.addAddress("some.server.com:8291");
    
    Redisson redisson = Redisson.create(config);
    RAtomicLong atomicLong = redisson.getAtomicLong("anyAtomicLong");
    atomicLong.incrementAndGet();
    
    0 讨论(0)
  • 2020-11-29 15:20

    If it really has to be globally sequential, and not simply unique, then I would consider creating a single, simple service for dispensing these numbers.

    Distributed systems rely on lots of little services interacting, and for this simple kind of task, do you really need or would you really benefit from some other complex, distributed solution?

    0 讨论(0)
  • 2020-11-29 15:22

    I have written a simple service which can generate semi-unique non-sequential 64 bit long numbers. It can be deployed on multiple machines for redundancy and scalability. It use ZeroMQ for messaging. For more information on how it works look at github page: zUID

    0 讨论(0)
  • 2020-11-29 15:23

    Distributed ID generation can be archived with Redis and Lua. The implementation available in Github. It produces a distributed and k-sortable unique ids.

    0 讨论(0)
  • 2020-11-29 15:25

    I know this is an old question but we were also facing the same need and was unable to find the solution that fulfills our need. Our requirement was to get a unique sequence (0,1,2,3...n) of ids and hence snowflake did not help. We created our own system to generate the ids using Redis. Redis is single threaded hence its list/queue mechanism would always give us 1 pop at a time.

    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 here

    0 讨论(0)
  • 2020-11-29 15:25

    One solution that is decent is to use a long time based generation. It can be done with the backing of a distributed database.

    0 讨论(0)
提交回复
热议问题