Proposed solution: Generate unique IDs in a distributed environment

后端 未结 2 1652
深忆病人
深忆病人 2021-02-01 08:47

I\'ve been browsing the net trying to find a solution that will allow us to generate unique IDs in a regionally distributed environment.

I looked at the following option

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 09:02

    I think this looks pretty solid. Each region maintains consistency, and if you use XDCR there are no collisions. INCR is atomic within a cluster, so you will have no issues there. You don't actually need to have the Machine code part of it. If all the app servers within a region are connected to the same cluster, it's irrelevant to infix the 00001 part of it. If that is useful for you for other reasons (some sort of analytics) then by all means, but it isn't necessary.

    So it can simply be '4' . 1' (using your example)

    Can you give me an example of what kind of "sorting" you need?

    First: One downside of adding entropy (and I am not sure why you would need it), is you cannot iterate over the ID collection as easily.

    For Example: If you ID's from 1-100, which you will know from a simple GET query on the Counter key, you could assign tasks by group, this task takes 1-10, the next 11-20 and so on, and workers can execute in parallel. If you add entropy, you will need to use a Map/Reduce View to pull the collections down, so you are losing the benefit of a key-value pattern.

    Second: Since you are concerned with readability, it can be valuable to add a document/object type identifier as well, and this can be used in Map/Reduce Views (or you can use a json key to identify that).

    Ex: 'u:' . '4' . '1'

    If you are referring to ID's externally, you might want to obscure in other ways. If you need an example, let me know and I can append my answer with something you could do.

    @scalabl3

提交回复
热议问题