Id generation nosql storage
I´m building an API that we need to have a unique id for every artifact.
We were thinking about us开发者_开发百科ing a GUID but looking at other APIs like foursquare/Facebook we see a different structure like:4d7adc94c7fca1431d6125a2 which is smaller.
So is there a best practices for id generation on nosql key-value storages?
Guids are 128bit and their generation algorithms ensure that a key generated on any machine in the whole world at any time is unique.
MongoDB for instance uses a 12byte=96bit key. This makes some sense, because the key is generated in a single cluster of machines, so the chance of having multiple keys is surely lower.
The question of Ids is the same whether data is stored in NoSQL or relational SQL databases. A centralized key generator, like incremental Ids makes key sizes much smaller which can sometimes be very important to boost performance. On the other hand, often this key size effect on performance is not too relavant and much more important, centralized key generation is considered a killer for distributed systems.
see http://www.mongodb.org/display/DOCS/Object+IDs
I think among best practices are Guids and BSON ObjectId. Centralized Ids are highly out of fashion at the moment, as distributed systems are mainstream. Your decision will depend also on the availability of a Guid generator.
精彩评论