Generating unique key

How do we generate unique key for the record? Cassandra has their timeuuid generator, how about aerospike?

1 Like

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.

And PHP - PHP: uniqid - Manual

:slight_smile:

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.