Distributed sequence number generation?

后端 未结 13 1958
小鲜肉
小鲜肉 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: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

提交回复
热议问题