title: URL Shortener algorithm
body: <p>I recently bought myself a domain for personal URL shortening.
  And I created a function to generate alphanumeric strings of 4 characters as reference.</p>
  
  <p>BUT</p>
  
  <p>How do I check if they are already used or not? I can't check for every URL if it exists in the database, or is this just the way it works and I have to do it?
  If so, what if I have 13.000.000 URLs generated (out of 14.776.336). Do I need to keep generating strings until I have found one that is not in the DB yet?</p>
  
  <p>This just doesn't look the right way to do it, anyone who can give me some advise?</p>