SCALABILITY PATTERNS · 9 MIN
Rate Limiting, Replication & CDNs
Common patterns that keep a system fast and alive under heavy load.
ARCH explains
- Rate limiting (token bucket) caps how often one user can call an API.
- Read replicas copy the database so many readers don't overload the primary.
- A CDN serves images and scripts from servers near the user.
Real world: Ticket sites limiting clicks per second during a big concert sale.
Code
tokens, cap = 3, 3
for t in range(5):
if tokens > 0:
tokens -= 1; print(t, "allowed")
else:
print(t, "rate limited")Output ›
0 allowed
1 allowed
2 allowed
3 rate limited
4 rate limitedTry it in the online compiler →Checkpoint quiz
What does a CDN mainly reduce?