How do we generate unique key for the record? Cassandra has their timeuuid generator, how about aerospike?
Most programming languages have a UUID library. You can generate a UUID and use the raw bytes of the UUID as the value of a key.
- Java β UUID (Java Platform SE 7 )
- Python β 20.15. uuid β UUID objects according to RFC 4122 β Python 2.7.18 documentation
- Node.Js β GitHub - broofa/node-uuid: This code is now maintained at https://github.com/uuidjs/uuid
- C# β Guid.NewGuid Method (System) | Microsoft Docs
- Go β http://godoc.org/code.google.com/p/go-uuid/uuid
- Ruby β uuid | RubyGems.org | your community gem host
- C β uuid_generate(3): create new unique UUID value - Linux man page
And PHP - PHP: uniqid - Manual
Most programming languages uses type 4 UUID. Even itβs almost impossible that collision ever happen, if thinking about scaling, people will prefer something like type 1 UUID that is not randomly generated.
@chris , @rbotzer - What if we have to generate UID in a distributed system ?
Java UUID wonβt ensure a unique key in that case.
You can use elements that add enough random noise to get around the timestamp collision problem.
For example in PHP you can use a function such as this:
function gen_id() {
return uniqid(getmypid().getmyinode(), true);
}
Between the process ID, the inode of the file, and the microtime we get back a good unique ID, even for a distributed system, that runs around 1.4ΞΌs on my machine.
There should be elements such as those (MAC address of a card, process ID, etc) that work for your case.