Using short ID generator and duplicates
I want to use friendly URLs in my web application. I prefer generating a short unique ID instead of a GUID. From what I know if I store data using the Add command and the key is duplicated, it will return an error. So my question is whether its safe to use my own unique short ID generator and handle duplicate key exception in the application layer in order to insert the document again with a different key until it's accepted.
I know that the chances to get duplicated, even with a short ID (like the one used by bitly) are rather small, but if If duplicated can't be inserted I have no problem using it, because I prefer a shorter ID than the GUID.
Any suggestions,
So I can use it the same as like in RDBMS (only numbers) with no problems with the cluster or performance?
Furthermore, is it BigInt?
I use ASP.NET
Idan,
Yes you can, and it is really very fast because when you call the increment methods it done (like any of the Couchbase CRUD) operation using the Memcached protocol.
So generating the ID/Incrementing the sequence will have no impact to your application, even in a large cluster, thanks to the vBucket architecture.
You can find the documentation about the increment method for Microsoft ASP here:
http://www.couchbase.com/docs/couchbase-sdk-net-1.1/couchbase-sdk-net-up...
Regards
Tug
Do you have some idea, how is it possible generate increment ID in nodejs ? I use couchnode ..
Hello Donald
The increment/decrement -incr()/decr()- functions have just been added to the Couchnode API.
You can see some tests that are using the functions here:
- https://github.com/couchbase/couchnode/blob/master/tests/09-incr-decr.js
Be sure you are using the latest libcouchbase library.
Regards
Tug
Tug, sorry, it was my mistake.
Thank you very much !
Hello Idan,
A quite simple approach will be to use Counter ID, with the increment command. Is that compliant with your use case?
You create a numeric item and you just increment it, and use it in your key. Like that you are sure that it is unique and small. It is more or less the same thing that using a Sequence in RDBMS engine.
Is that Ok with your business requirements ?
You can find more information here:
http://couchbasemodels.com/patterns/counter_id
Also which language (SDK) do you use for your application it will help to find a good approach.
Regards
Tug
Tug
@tgrall