DEV Community

Adrian
Adrian

Posted on

How long until bit.ly runs out of unique numbers?

This is an exercise for code newbies. It actually doesn't require any programming, just a little bit of calculation:

  1. Consider a service such as bit.ly that generate short Urls

  2. Assume that the generated key is always 7 alphanumeric characters long (using both upper case and lower case letters)

  3. Suppose people around the world are generating short Urls at a rate of 1000 short Urls every second.

Alt Text

Question: How long takes until bit.ly runs out of unique sequences for the short Urls?

Top comments (3)

Collapse
 
kaykleinvogel profile image
Kay Kleinvogel

So first we have to calculate the number of possible URLs.
Each character can has 62 possible outcomes (26 + 26 +10).
And we have 7 alphanumeric characters.
Since the order of the characters is important (/abcde != /edcba) we have to apply the permutation 👨‍🎓.
But since we are replacing characters we have chosen before (e.g. /aaaa is possible) we have to use permutations with replacements.

626=56,800,235,584 62^{6}=56,800,235,584‬

So now that we have the number of possible URLs we just have to divide it by the frequency of the URLs being created.

56,800,235,5841000=56,800,235.584seconds \frac{56,800,235,584‬}{1000} = 56,800,235.584 seconds

So bit.ly would run out in about ‬56,800,235 seconds (about 658 days).

Collapse
 
codeguppy profile image
Adrian

why 62 ^ 6?

Collapse
 
kaykleinvogel profile image
Kay Kleinvogel

Should have read the task better. It's 7 digits so it should have been 62^7