POST v1/data/longUrl/ { longUrl: http://.... }
GET v1/{shortUrl}/
A simple key value store should be enough
key value
shortUrl (str) longUrl (str)
Client will call our API gateway/load balancer. Compute, cache tier, and database tier can all be scaled out separately. Web services should be stateless (serverless??) since it just checks for cache hit otherwise gets the data from the key value store.
It also serves the purpose of generating keys. All of these operations can be done on elastic CPU that can be even auto scaled.
need help - how does cache get scaled out? i use aws redis and ddb so that's all handled for me.
Generation Flow
Redirect Flow
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Tiny URL generation.
we don't want the url to be too long. but it should support our 70 billion url use case. If we choose sha1, its not case sensitive so we will have 26 + 10 chars to work with. 36^n = 70billion. n = 7
we can take the first 7 chars of sha1. In case of collisions, we can check for the shorturl's existence in db and regenerate.
Explain any trade offs you have made and why you made certain tech choices...
Hashing and retrying is not the most efficient. Base62 is another option but i don't know it
Try to discuss as many failure scenarios/bottlenecks as possible.
we should have replication in the db tier so that we don't lose data.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?