Sent from my iPhone

On Dec 30, 2009, at 11:01 AM, Bernd Lutz <[email protected]> wrote:

Hello everyone,

I'm currently exploring the possibility to port an app from MySQL to CouchDB. The app uses friendly URLs, e.g. http://myapp.com/content/friendly-identifier . Every content has an unique identifier which derives from the content title.

If there would be only a few users creating content a simple check for the identifier's uniqueness would be enough. But what if there are multiple database nodes and let's say thousand users creating identifiers. So we cannot get a consistent view result on a single node nor being sure that another user doesn't add a same identifier on another node in parallel.

I hope you got the problem. How would you handle it?

My approach:
Setting up a special node and database handling idenifiers with a view having the identifier as key.
1. Adding a new document with the identifier.
2. Check the uniqueness by queriing the view.
3. If ok, all right. Otherwise: Recursively add a postfix "-n" until the result is unique.

Of course the identifier won't be used as document _id.
I think this is a common problem not only for url friendly identifiers. A common usage could be also the unique user name.


I think it's actually good practice to use docids for friendly identifiers. Then collisions between URL slugs will appear as couchdb conflicts (eventually, in the case of distributed app, and immediately, in the case of a single node or partitioned cluster).

Best regards and a happy new year,
Bernd

Reply via email to