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...
API that takes in a long url writes it to DB and returns a short url
We have another API that takes in a short URL and returns a long URL
We can aslo implemnt URLs to ensure security and validation
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.
We use a relational database such as MySQL as the source of truth, storing:
short_url_id (primary key)long_urlInstead of hashing with linear probing, we use a globally unique ID generator:
[a-zA-Z0-9]) to form the short URLWhy this works
We implement a multi-tier cache (e.g., Redis/Memcached) in front of the database.
The ID generation service is replicated across multiple nodes using a Snowflake-style algorithm where each node has a unique worker ID. If a generator instance fails, traffic is routed to healthy instances. To prevent split-brain, worker IDs are statically assigned or coordinated via a consensus system like ZooKeeper or etcd.
In the event of a cache purge or restart, the system falls back to the database as the source of truth. Popular URLs are gradually repopulated into higher cache tiers based on access frequency, accepting temporarily higher latency during cache warm-up.
To handle traffic bursts (e.g., viral links), the system enforces rate limiting at the API gateway and uses request queues or token buckets for write requests. Excess requests receive HTTP 429 responses with retry-after headers to prevent cascading failures.