Comments (9)
tl;dr: No guarantees, especially in the legal sense (see all-caps text).
Expecting IDs to be unique "at any point of space and time", is an unrealistic standard. It's not practical to build such a solution. It requires a source of uniqueness that, as you expand the context in which you need your IDs to be unique, becomes ever more illusory. _Thus, the goal of node-uuid is not to provide universally unique ids but, rather, to faithfully implement the industry accepted methods for generating UUIDs, as defined in RFC 4122_. Those methods are known to be imperfect, but they are the best we have to work with.
Having said that, to your question about uuids in the context of node.js clusters ...
Where v4 UUIDs are concerned, these are just randomly generated values. Thus, they're only probabilistically unique. For any two ids there is a theoretical 0.00000000000000000000000000000000002% chance of collision. But the actual probability depends on the quality of the random number source. On node.js, this is crypto.randomBytes()
, which is the best we have available, but you'll have to decide if that's "good enough".
v1 IDs are timestamp based. What makes them interesting in the context of a node cluster is their "node" field. The node is a value unique to the system generating the IDs. RFC4122 specifies that this should be the hosts MAC address... but in thinking about this, I'm not sure that's a good thing. Cluster processes would (I assume) all share the same MAC address, which would actually increase, not decrease, the risk of collision. Fortunately the spec goes on to state that if the MAC address isn't available (and on node.js it isn't... at least, not easily) then the node field should be randomly generated, which is what node-uuid does. So we avoid that little pitfall. But it also means there's a 0.0000000000004% chance that any two cluster processes will have the same node value. Should that happen, then it just comes down to whether or not they're generating IDs at during the same system clock tick. :-/
If you want to insure UUID uniqueness across your cluster processes, then I would suggest using v1({node:aUniqueVal})
, where aUniqueVal
is some value you know to be unique to each cluster process.
from uuid.
In v1 Could we perhaps replace the MAC address with the node.js pid? Wouldn't that help with clusters?
For example replace MAC address with process.pid
and pad the rest with random.
from uuid.
+1 for the awesome explanation, thanks you.
from uuid.
@nodesocket not sure it's a good idea, if you run node.js inside a docker its pid will always be 1.
from uuid.
Onecould grab the first non 'internal' interface's IPV4 address from os.networkInterfaces()
, use that as the first 4 butes of the node ID, and then use the process.pid
to generate the last two bytes:
var addr = '1.2.3.4.'; // say from os.networkInterfaces().eth0[0].address
var pid = process.pid;
var nodeid = [
...addr.split('.').map(function(n){return parseInt(n,10)}),
(pid >>> 8) & 0xff,
pid & 0xff
];
// nodeid is now something like [ 0x01, 0x02, 0x03, 0x04, 0x56, 0x78]
var u = uuid.v1({node:nodeid});
from uuid.
@tmorehouse IP-based UUIDs introduces the requirement that you shouldn't have systems on LANs that assign similar IP ranges.
from uuid.
Yeah, this would only work for systems that have unique IP's across instances, and across fork()
ed processes on those instances
But the nice thing about node-uuid
is that you can assign your own 6 byte node ID value any way you like, assuming your are only using these UUIDs (V1) within your application (i.e. no other UUID generation is used).
from uuid.
Hello,
Simple question, using the uuid.v1 method, is it possible to re-create a uuid if you supply the options
fields that were used to create it in the first place?
from uuid.
@murphman300 https://github.com/kelektiv/node-uuid/blob/master/test/test.js#L77
from uuid.
Related Issues (20)
- Double spaces in the deprecation message HOT 1
- Vulnerable dependencies (indirect security issues) HOT 2
- NPM Deprication Message is ambiguous HOT 2
- Question: Do we still need it?
- Sponsored issue: Incremental UUID HOT 1
- [BUG] uncorrect validation uuid HOT 1
- [question] is posible decode uuid to data back ? HOT 1
- Add UUID type to use in TypeScript HOT 1
- validate method returns false for a valid UUID HOT 6
- Issue in the import statement HOT 1
- [BUG] Installing `uuid` has an inconsistent dependency chain causing build issues in ci/cd pipelines HOT 2
- uuidv6 has been officially adopted by the IETF HOT 3
- Tracking Issue: RFC 9562 / uuid@10 HOT 1
- Make `Uint8Array` the one and only type used for binary (byte) uuid values
- Drop support for `offset` argument, commit to `Uint8Array` type for binary uuids
- Add v8 Support HOT 1
- Port codebase to TypeScript HOT 1
- v7: passing `options.msecs` results in zero-value timestamp HOT 5
- Error: Cannot find module 'node:crypto' when I upgrade uuid version from 9.0.0. to 10.0.0 HOT 4
- Reduce package size by code splitting HOT 5
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 uuid.