The standard approach involves generating a unique id (smaller integer, usually an auto increment id), and then using that id in a bijective function to generate a smaller string as described here: https://stackoverflow.com/a/742047/762747
But this approach cannot work for distributed systems at scale. The id in case of NoSQL databases are generally much larger to ensure uniqueness. One can try to generate auto increment ids, but it is surely going to be inefficient.
Are there any other approaches to generating short URLs. Specifically:
1) How does twitter generate t.co URLs, as it is the best example I can think of when we are talking about scale. The tweet ids are much larger (they use snowflake), so we can say that twitter does not (and probably cannot) use auto increment ids.
2) In case they use the same approach, then is the URL shortening asynchronous, to ensure that they don't take a performance hit while generating the auto increment id and short url?
As for my specific case, I am trying to generate a unique shortened string from the mongo BSON id. The above approach yields a 16 character base 62 string when I try to shorten the BSON id. I can take the unique auto increment id route, but that sounds inefficient for obvious reasons. Thoughts? If twitter can do it, we can as well. Good folks @twitter, do you mind sharing your approach?