Coder Social home page Coder Social logo

Comments (4)

RobThree avatar RobThree commented on August 18, 2024
  1. Yes. You'll want the generator-id part to be "globally" (or even "universally") unique; if you have multiple instances then (be it on different hosts, or on the same host in different processes or even in the same process in different threads), then each of the instances will need an unique generator-id.
  2. You're correct, as long as the max ID is less than the id's generated by IdGen at that time you should be ok. You can play with the epoch date if you want to; the closer you get it to "today" the lower your ID's will be. However, once you pick an epoch you'll need to stick with it.

You can consider an epoch of 2020-01-01 or 2021-06-01 or 2021-09-01 for example, and each of these epochs the ID's will decrease (and then increase each generated ID ofcourse) and probably get closer to your current maximum ID. But the "you'll need to stick with it" goes for the entire IdGeneratorOptions and IdStructure. I'm not saying it's impossible but it will be a real drag to change this (for example to have more generator-id bits) later on. So make sure you've thought things through for your specific situation and requirements.

That's about alle the advice I have I guess... Feel free to ask follow-up questions if you have any. It's a lot less complicated than it seems I guess.

from idgen.

nothings-more avatar nothings-more commented on August 18, 2024

Thanks for such thorough answers/explanations! And a couple of clarification questions from my side:

  1. is that correct that using different "generator-id" parts is the only way to make several instances of IdGenerator to generate unique sequences of IDs?
  2. as far as I understand, IdGenerator have kind of "resolution" , i.e. it can generate only limited number of IDs per time period - it is 4096 per millisecond with default settings, and can be increased by changing settings, but it will still be limited, right?

Thanks again.

from idgen.

RobThree avatar RobThree commented on August 18, 2024
  1. Yes. The README explains exactly how an ID is structured and generated.
  2. Yes, there's always a limit. You can sacrifice some generator-id bits trading less (possible) generators for more ID's per time period: for each bit added to the sequence part you'll double the max number for the sequence for the period. You can even sacrifice some timestamp bits (but that'll decrease the resolution of your timestamp). But I'd say 4096 per millisecond is a whole lot. That's over 4 million per second per generator. With 10 generators in the system you can do 40 million ID's per second. With 1024 generators (the maximum in the default settings) you can do a theoretical of 1024 * 4096 * 1000 = 4,194,304,000 ID's per second.

You can vary the ID structure's parts (timestamp, generator-id, sequence) number of bits; but whatever you pick you'll have to live with (or you'll have to renumber your ID's or do other trickery) once you start generating and using ID's in that chosen configuration. As long as all 3 parts add up to 63 bits (and generator-id and sequence don't exceed 31 bits) you should be good to go.

from idgen.

nothings-more avatar nothings-more commented on August 18, 2024

I see, thanks a lot

from idgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.