Comments (9)
How about this?
from idgen.
What do you think about adding something about version bits,
I don't want to give people ideas; essentially all of the 'host' bits can be used for whatever, but I don't want to encourage 'abuse' of any of the bits. If you want to reserve some bits for versioning in your project then go ahead, but I don't want this to become a common practice.
and/or multiple id structures being active at the same time
Again, it's perfectly possible, but I don't think it's a good idea so I don't want to encourage it.
Technically you can have a generator per - say - entity. As long as your customer
entities have a dedicated IdGenerator
from, say, your products
then there will be no collisions. As long as they're all on the same host/process/thread/... you can consider the id's not much different from an RDBMS using autoincremented id's; usually such tables have id's 1, 2, 3, ... and that's fine; they live in their own "namespace" (the table). Customer 1 doesn't "collide" with Product 1. But the scenario what IdGen (or Snowflake if you will) is designed for is if there are multiple hosts/processes/threads/... (i.e. "generators") generating id's for the same entity and you want to avoid collisions without having to coordinate these generators (other than assigning them a GeneratorId
on instantiation).
I think there is a typo (comma), and I fixed it below. You've captured the gist though.
I literally had it there and then got rid of it ðĪŠ I've put it back ð
from idgen.
That should work fine. Did you consider putting the version bit last?
gggggggggggggv
\-----------/|
| +-> deployment bit
v
generator bits as usual
13 bits
That should be "more correct" sortability-wise ('less impact'). Also it would have a nice even/uneven effect for blue/green. Though your option will work just as fine too.
from idgen.
I'm fine with what you have. It brings attention to the issue, and I understand that being prescriptive here may not make sense. We can only so much. ðĪ·ðŋ
from idgen.
What do you think about adding something about version bits, and/or multiple id structures being active at the same time?
I think there is a typo (comma), and I fixed it below. You've captured the gist though.
Although changing the structure at a later stage isn't impossible, careful consideration is needed to ensure no collisions will occur.
from idgen.
Again, it's perfectly possible, but I don't think it's a good idea so I don't want to encourage it.
In my case it's blue/green deployments. So, it is unavoidable. Both id structures are only active for some time.
from idgen.
@rmandvikar I've edited / updated my previous comment but I noticed you already ð'ed it. Just making sure you're aware of it.
In my case it's blue/green deployments. So, it is unavoidable. Both id structures are only active for some time.
What's stopping you from reserving generator id's per (blue/green) deployment? Which is, essentially, what a 'version' bit does ofcourse.
from idgen.
I have taken a bit of a practical approach considering complexity, maintainability, et. al. for generator_id. Where,
generator_id = 13-bit generator_id hash function based on string generator id
A hash function has pros/cons. It is easy to understand, and maintain as long as the string ids are known beforehand, which is always the case.
generator_id (14 bit):
vggggggggggggg
|\-----------/
| v
| generator bits as usual
v 13 bits
deployment bit
1 bits
from idgen.
That should be "more correct" sortability-wise ('less impact'). Also it would have a nice even/uneven effect for blue/green. Though your option will work just as fine too.
I forgot to mention. One advantage of keeping the deployment version
bit as MSB is that it won't shift as the id structure changes. The timestamp
at 41 bits with 1 ms tick gives ~69 years, which suffices for me now, and I don't plan to change that. But, I do plan to increase the generator
bits, and shrink the sequence
bits in future, if needed. So, the fixed position of the version
bit helps quite a bit (pun-intended ð) in that case.
// 41/14/8
tttttttttttttttttttttttttttttttttttttttttvgggggggggggggsssssssss
\---------------------------------------/|\-----------/\-------/
timestamp v generator sequence
version
Just mentioning as it may be helpful to someone; a hack I have due to blue/green deployments, combined with the lack of version
bit in the very first deploy, is to use the sequence
MSB as an interim version
bit (the version
bit mentioned above in generator
will also be added). 2^8 = 256 calls /ms/generator volume is very high, and the sequence
MSB will always be 0
, and it can be versioned to 1
. The interim version
bit in sequence MSB can be removed as a fast follow, then relying on the version
bit in generator
going forward.
So,
// note: deployments when changing id structure from 41/10/12 -> 41/14/8
tttttttttttttttttttttttttttttttttttttttttggggggggggsssssssssssss
now: .........................................x.............0........ # sequence MSBs always 0 due to not as high traffic
tttttttttttttttttttttttttttttttttttttttttvgggggggggggggsssssssss
+1: .........................................0.............1........ # generator MSB versioned to 0, sequence MSB versioned to 1
+2: .........................................1...................... # generator MSB versioned to 1, sequence MSB version removed
+3: .........................................0...................... # generator MSB versioned to 0
+4: .........................................1...................... # generator MSB versioned to 1
...: repeat 3, 4
from idgen.
Related Issues (20)
- Drop support for netstandard 1.1 HOT 5
- Non-generic IIdGenerator HOT 5
- Avoid spending a sign bit by using ulongs HOT 13
- Tag 3.0.3 is missing HOT 1
- IdGen is generating 17bit Id instead of 16bit? What should we change in the method so that it generate 16 bit Id instead of 17 bit now and in the future it continuous to generate 16 bit Id? HOT 11
- Is there a way to shorten the number of digits generated for an id? HOT 5
- Handling uniqueness ID across multiple instance of same service HOT 6
- IdGenerator does not contain a definition for 'Take' HOT 1
- Consider adding IdGenerator#CreateFromDateTime HOT 5
- Public Method Comments HOT 1
- SpinWait drastically slows continous ID generation rate for small tick length HOT 10
- Could we log how often we overflow sequence IDs and have to spinwait? HOT 1
- Concurrency issues with instances scale up HOT 2
- Use dependabot to keep references up to date HOT 1
- Sequence input for CreateId() HOT 3
- IIdGenerator is registered as a singleton, but duplicate IDs are still generated HOT 4
- Debugging InvalidSystemClockExceptions HOT 15
- Is there a way to generate id from the past HOT 1
- How to use this in distributed computing ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
ð Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google âĪïļ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from idgen.