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
database(relational and NoSQL) and database design
caching
loading balancing
single point failure
horizontal scaling
API design
CAP and distributed system theories
architectural thinking(any methodologies ? any principles to follow)
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://tinyurl.com/ would generate a shorter URL:
When you visit the short URL, you’ll be redirected to the link the long URL points to
Follow-up/Guiding Questions:
what’s the relationship between the long and short URLs?
should we make the short URL unique? some hash functions? md5? base64? database table auto-increment id?
how to map the short URL to the long URL?
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?
can we predict the pattern of short URLs? If we can predict that, what would happen? Any security threats?
if the user can specify the expiration time of the URL, what would you do?
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?
say we have 1 million new URL shortening requests per month, how would you deal with the storage?
how would you design the API?
what database would you choose? why? how would you design database schemas?