Client
The person’s browser or mobile app.
Starts the request and follows the redirect.Learn why each component exists, how requests and data move through the architecture, where bottlenecks and failures appear, and how design choices change behavior at scale.
Attempt the prompt before studying the reference architecture. Return after the lecture and compare your decisions with the model.
Users submit long URLs and receive short links. Opening a short link must quickly redirect to the original destination. Links may expire, and a popular link can receive a sudden traffic spike.
Design the APIs, data model, short-code generation, storage, caching, traffic routing, scaling strategy and failure behavior.State assumptions when information is missing. Interviewers care about reasoning and tradeoffs more than one perfect architecture.
Before looking at protocols or capacity, understand the simple job each component performs.
The person’s browser or mobile app.
Starts the request and follows the redirect.The traffic coordinator at the front door.
Chooses a healthy API server for each request.The decision maker.
Validates the code, checks storage and builds the response.The system’s fast, short-term memory.
Keeps popular mappings close so they can be returned quickly.The permanent record book.
Stores every durable short-code mapping and its expiry.Imagine that a7K2 has already been opened before, so its destination is available in the system’s fast memory.
The user clicks the link. Their browser asks the URL shortener to open short.example/a7K2.
Traffic reaches the front door. The load balancer sends the request to an available API server.
The API looks for the code. It asks Redis whether it remembers where a7K2 should go.
Redis remembers it. The saved destination is returned immediately, so the permanent database is not needed.
The API sends directions back. It tells the browser to redirect to the long destination.
The browser follows the redirect. The destination page opens, completing the healthy request.
What made it healthy? Every component was available, the mapping was cached, no queue accumulated, and the database was protected from unnecessary work.
The user experience above becomes a sequence of network, application and cache operations.
GET /a7K2The browser sends an HTTPS read request containing the short code.
LB → API replica 02The load balancer selects a healthy stateless API instance.
GET link:a7K2The API validates the code and performs a Redis lookup.
Cache hit → destination URLRedis returns the mapping, so PostgreSQL is not queried.
302 Location: https://example.com/guideThe API sends an HTTP redirect with the destination header.
Browser → destination websiteThe client follows the redirect; that external request is outside the shortener.
Choose a workflow, advance one step at a time, and connect each explanation to the highlighted component.
Active now: client · The highlighted route is the path this request follows.
The browser requests GET /a7K2. The code identifies a saved destination.
GET /a7K2 plus normal browser headersNormal request paths explain how the product works. Traffic, failure and resilience scenarios explain how the architecture behaves when conditions change.
A popular short code is already stored in Redis.
Client → Load balancer → API → Redis → API → ClientRedis returns the destination and PostgreSQL does no work. This is the fastest normal read path.The short code is valid but Redis does not currently hold it.
Client → Load balancer → API → Redis miss → PostgreSQL → Redis → ClientPostgreSQL supplies the durable mapping, the API warms Redis, and later opens can become cache hits.A user submits a new destination that needs a short code.
Client → Load balancer → API validation → PostgreSQL commit → ClientThe mapping is durable before the API returns the short URL. Read caching is not a substitute for this write.Neither Redis nor PostgreSQL has an active mapping for the code.
Client → Load balancer → API → Redis miss → PostgreSQL → API → ClientThe API returns 404 for an unknown code or 410 for an expired resource instead of redirecting.Normal demand fits across the API, cache and database tiers.
Watch: Redis serves most reads. PostgreSQL receives about 1.16K operations/s, so queues and errors should remain near zero.A low hit rate sends more read work to PostgreSQL.
Watch: More reads reach PostgreSQL. Watch database utilization and pending work rather than assuming an online cache is enough.A viral burst exceeds API dispatch capacity.
Watch: The two-replica API tier can dispatch only 12K requests/s. Its queue grows before downstream capacity can help.Write-heavy traffic bypasses the read cache and pressures storage.
Watch: Writes bypass the read cache and reach PostgreSQL. A high cache-hit rate cannot remove durable write demand.Losing Redis sends all dispatched work to PostgreSQL.
Watch: Every dispatched request falls back to PostgreSQL. Database demand rises above capacity, pending work grows and requests begin to fail.One API replica cannot dispatch the full incoming workload.
Watch: The surviving replica cannot dispatch the 8K requests/s workload. API pending work accumulates even when Redis is healthy.Reduced database service capacity creates pending work.
Watch: The normal 1.16K operations/s database demand now exceeds service capacity. Database queues expose the new bottleneck.Database headroom absorbs the Redis fallback workload.
Watch: All 8K requests/s reach PostgreSQL and still fit. This shows that a dependency outage causes overload only when fallback capacity is insufficient.Experiment runs every preset for 30 simulated seconds and records comparable evidence.