Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
Post - api/vi/createURL { longUrl ,userId, timestamp , return short url}
get -> api/v1/getLongUrl{ short url, userId}
301,302
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
Components will be user, write server , read server, database and cache for quering highly asked APIS
The architecture will be microservice architecture and we can store it whenever needed
Write server - will have convert long to short url
Read server - We can use redis for freq reads else we use Db calls
LFU cache in redis
We will also have a load balance to ensure system is not overloaded
Database /Storage- user id, id, long url , short url
for write we will come to database store the shorturl and retrieve it to user
for read at first we will come to db for a new request and based on location wise we will store the freq queried short url to redis and keep it there
We also can create a read write replica where db will have read schemas and right ones. in this way write can not be disturbed and once the read storage are replciated we can have them used .
for a better handling of keys we can pre compute some keys and create a table of used and unused keys
We can shard the date by short code
RDBMS - like a dynamo db or mysql
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
ID Generation —
x-fingerprint + tinyUUIDCaching — Scenario Checks
What specific approach will you take for cache purging when a link is disabled or edited?
Purge strategy (update/disable):
DEL shortCode (and any secondary keys like longUrlHash→shortCode). Next read repopulates from DB. For “disabled”, you can also set a tombstone key so it doesn’t keep hammering DB.What specific TTL or eviction policy will you implement to balance freshness and memorys
Ans TTL for each cache with LFU for volatile
What specific strategies will you implement to mitigate hotspots and ensure an even traffic spread
detect hotspots via metrics (top-N shortCodes by QPS), auto-flag “hot keys” to edge-cache longer or pin to L1 cache, and alert on sudden traffic skew.
Rate limiting -
How will you handle generator outages or split-brain scenarios?