UUID generation algorithm and performance


What’s the best-performing way to choose unique document IDs in Couchbase?

I know that Couch DB != Couchbase, but the Couch DB documentation is pretty clear that asking the server to generate sequential UUIDs is better than generating random UUIDs:

Impact of UUID choices: the choice of UUID has a significant impact on the layout of the B-tree, prior to compaction.
For example, using a sequential UUID algorithm while uploading a large batch of documents will avoid the need to rewrite many intermediate B-tree nodes. A random UUID algorithm may require rewriting intermediate nodes on a regular basis, resulting in significantly decreased throughput and wasted disk space space due to the append-only B-tree design.

Does this advice apply to Couchbase?

In our use case, we have no inherently meaningful unique identifier that we can use as a document ID, so we’ve been using GUIDs generated by the clients when documents are created, instead of letting the server generate IDs for us. Would we see improved database performance if we let the server generate UUIDs for us, using a sequential algorithm?

Can anyone explain how the UUID() function works?

If you are using Couchbase 4.x, you can use the N1QL UUID() function. The random keys will be distributed uniformly across your cluster, which is what you want.