DEV Community

Discussion on: Building a url-shortener. My architecture.

Collapse
 
nedsoft profile image
Chinedu Orie

Nice approach. You didn’t shade light to how you’re going to ensure that the random string remains unique. Consider a scenario where you have a million requests per second, how do you ensure that no url is lost due to duplicate random string.

Collapse
 
petrussola profile image
Pere Sola

Great point, Chinedu. I am saving the new random string in the DB table alongside the long URL. If the next request generates the same short string and finds it in the DB when querying it, it will create a new one before returning it to the client. Thoughts?

Collapse
 
nedsoft profile image
Chinedu Orie

Cool, I think that makes sense. You'd probably index the random string column to enhance the performance because for every new record, you'd search for a duplicate random string.