The sane variant of this approach, where you increment a counter and assign that number, is part of the official documentation.
The problem with your approach is that counting is a relatively expensive operation. Moreover, it's not even collision safe because two threads could count simultaneously and get the same number, so the second insert will fail.
Generally speaking, sequences create a bottleneck because you need a single point of coordination. For a write-heavy system, the number of operations is doubled (an additional $inc
for every insert). To make matters worse, sequences leak a lot of information to the outside (i.e. the number of entries in the database).
If you're running a web shop, blog, etc. you probably want your URLs to be a lot prettier, descriptive and SEO-friendly like /products/displays/27-inch/iiyama-2734FW
.
If you're building a web application where the URLs aren't visible to search engines anyway, I believe that neither /users/433
nor /users/532af835a715eae43f00002c
will be a reason for your customer to choose or not choose your application. Maybe a wise customer would, but then they'd reject the former option...