Home > database >  create urls like Instagram posts or youtube video
create urls like Instagram posts or youtube video

Time:06-13

I'm building a social network and I're going to create my own urls at random the question that has been on my mind for a long time is how to create urls like Instagram posts like Django like the following:

https://www.instagram.com/p/CeqcZdeoNaP/

or

https://www.youtube.com/watch?v=MhRaaU9-Jg4

My problem is that on the one hand these urls have to be unique and on the other hand it does not make sense that on a large scale when the number of uploaded posts by the user is more than 100,000 I set unique = True Because the performance of the database decreases

Another point is the use of uuids, which solves this problem of uniqueness to a large extent, but the strings produced by uuid are very long, and if I shorten these strings and reduce the number of letters in the string, there is a possibility of a collision. And that several identical strings are produced

I wanted to know if there is a solution to this issue that generated urls are both short and unique while maintaining database performance

Thank you for your time

  • Related