SaFi Bank Space : SaFi Designing A URL Shortening Service like TinyURL

Target Level:

Middle-level to Lead Developer

Expected Duration:

1-2 hours

Goals:

  • Check to see if the candidate can describe technical details

  • Check to see if the candidate can approach the problem in a systematic way

  • Check to see if the candidate have a solid understanding of the following aspects

  1. database(relational and NoSQL) and database design

  2. caching

  3. loading balancing

  4. single point failure

  5. horizontal scaling

  6. API design

  7. CAP and distributed system theories

  8. architectural thinking(any methodologies ? any principles to follow)

  9. coding

(If 4 of these items are OK, the candidate is a qualified senior software engineer. As for lead engineer, 6 of these items should be OK)

Problem Description:

Design a URL shortening service like Tiny-URL service. The goal is to design a highly scalable service that could allow users to create shorter URLs, given long URLs, and have read and write functionality. So what is Tiny_URL? https://tinyurl.com/ is a URL-shortening web service that creates shorter aliases for long URLs. Whenever the user visits the short URL, he/she will be redirected to the original URL. For example, we have a long URL:

https://thorntech.com/simple-cloud-file-transfer-aws-s3-azure-blob/?gclid=EAIaIQobChMIoKWA5dL4-AIVgMEWBR3fxgQYEAAYASABEgJsT_D_BwE

, https://tinyurl.com/ would generate a shorter URL:

tinyurl.com/2p9ckswz

When you visit the short URL, you’ll be redirected to the link the long URL points to

Follow-up/Guiding Questions:

  1. what’s the relationship between the long and short URLs?

  2. should we make the short URL unique? some hash functions? md5? base64? database table auto-increment id?

  3. how to map the short URL to the long URL?

  4. how to redirect short URL to the long URL in near real time with minimal latency? caching? how to expire caching entries? Least Recently Used?

  5. can we predict the pattern of short URLs? If we can predict that, what would happen? Any security threats?

  6. if the user can specify the expiration time of the URL, what would you do?

  7. high availability is mandatory for such a service, so how would you approach this? how would you distribute short URL visits/requests to different backend service instances?

  8. say we have 1 million new URL shortening requests per month, how would you deal with the storage?

  9. how would you design the API?

  10. what database would you choose? why? how would you design database schemas?