πŸ’¬
βœ‰οΈ
πŸ“Έ
▢️

Loading…

Design a URL Shortener (TinyURL): Interactive System Design

URL ShortenerGuided Mode

Step 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

1

All traffic arrives at the Load Balancer

The Load Balancer is the single entry point. It distributes incoming requests across all healthy API servers.

2

Round-robin distribution

Request 1 β†’ API Server 1. Request 2 β†’ API Server 2. Request 3 β†’ API Server 1. Each server handles 50% of traffic.

3

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.

4

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