User should be able to generate shortURL
User should land up on the actual page/url when he comes with shortURL
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
As we target for milllions of customers, we may need to shard the database. And we need to handle the creation of unique short URL.
So we can go with timestamp + worker + counter based id which then can be given as base 32 URL
we target for high system availability, so we need to maintain read replicas of nosql db.
Sharding should be done on url id .
keep redis (cache) for keeping recent urls to avoid db calls.
System should ensure not to loss any record - if write db/master is down - elect slave as write db.
What if write db writes the url record but error while returining the response to server - our goal is redirect users to actual url on basis of short url. so if there's any error in between, we can write the same into another db. we're okay with duplication
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.