Design a Tiny URL Service
Design a service where user will give the long-URL and we need to return a short-URL.
And when he gives the short-URL we need to give back the original long-URL.
Very Famous Interview Question:
- Problem statement is very simple.
- This question has some very interesting challenges specifically trying to design it at scale.
- When interviewer asks this question it’s certain that he is not looking for a solution:
- Where we take a longer url and generate the shorter url and store it in hash and return the longer-url from it.
- But he asks this to test our knowledge on scalability and durability.
- The solution of using a map is neither scalable nor durable.
While designing a service we need to think about below things straightaway:
- API (Application Program Interface):
- createTiny(longUrl) ——> tinyUrl
- getLong(tinyUrl) ——>longUrl
- Application Layer
- Interviewer is concerned to know how do we generate the tiny URL which is unique.
- Coz actual URL can be 100 characters long but we need to generate a tinyUrl which 7-8 characters long.
- Persistance Layer
- Interviewer is interested to see how we design the persistence layer.
- Basically where and how we store the long and short URL.