POST /url
GET /url/{url_id}
We're essentially implementing a key/value store that should be able to scale easily. We want to optimize for a high read to write ratio but don't expect consistency concerns given the fact that requests don't collide with each other and eventual consistency is okay, e.g. if a shortened link doesn't route anywhere the first time, the user can reload and try again. Because of this, I think we should opt for a NoSQL database that maps hashes to URLs. Because of the high read pattern, we should replicate the database with a leaderless architecture. Changes should propagate every few seconds to the rest of the machines.
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
We need a hashing service that will take a URL and turn it into a unique hash. The hashing algorithm should have no collisions and needs to support ~40,000,000 unique values assuming we can recycle old/stale URLs on a yearly cadence. Thus, we should hash URLs to a 32-bit sequence.
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?