Wednesday, January 23, 2019

Tinyurl design

We have different options to generate tiny url. The basic rule of thumb is that we need to convert the long url into tiny url and store it in database or cache for future retrieval.

1) Sometimes we would have restrictions on the tiny url. ex 41 bits
2) Allowed characters on the tiny url  could be caps and smaller alphanumeric characters



SOLUTION

  • When a long url is generated it is sent to the load balancer.
  • Load balancer sends the request to the zookeeper instance
  • We need to use token generation technique for generating tiny url
  • When the requests per sec are in thousands we cannot rely on a single server generating the     token.Token generation should be distributed across different servers
  • To avoid collision the token generation should be distributed with specific range to each server
          Ex 1st one million, second one million
  • When the token are exhausted we need to have new set of of tokens and range also should be changed
  • For security reason we should also ad some randomness in the generated url
  • Once the token is generated it would be stored in the cache (redis) and database server
  • All new request would be taken from the cache. If it is not able to find then it would be fetched from the database
  • For specific regions cached tokens would be available in the local CDNS



 


No comments:

Post a Comment