Design a URL Shortener (TinyURL): Interactive System Design
URL Shortener
Guided ModeStep 3 β Adding a Load Balancer
A single API Server is a single point of failure. When traffic doubles, it becomes a bottleneck. We introduce a Load Balancer.
Request Flow
All traffic arrives at the Load Balancer
The Load Balancer is the single entry point. It distributes incoming requests across all healthy API servers.
Round-robin distribution
Request 1 β API Server 1. Request 2 β API Server 2. Request 3 β API Server 1. Each server handles 50% of traffic.
Health checks every ~5 seconds
The LB pings each API Server periodically. If one doesn't respond, LB stops routing to it β zero manual intervention.
Both API servers share the same Database
They both read and write to the same Database. The DB now receives 2Γ the queries β we'll address that in Step 4.
Why We Need This
Before: one API Server crash = total outage. With the Load Balancer, the surviving server handles all traffic until the failed one recovers.
Capacity now scales linearly: add a server, add proportional capacity. No downtime, no configuration changes.
Key Insight
API servers are stateless β any server can handle any request. This makes horizontal scaling trivial. Stateless design is the foundation of scalable systems.
Step 3 of 6
