Scale From Zero to Millions of Users
Every giant system started tiny. In this chapter we begin with one server and one user, and every time something breaks we add exactly one new piece to fix it. By the end you will know the building blocks behind nearly every large website.
- 1.1Single server setupTo start simple, everything runs on one server: the web app, the database, the cache. Here is what happens when someone visits your site:…
- 1.2Separate the database (and pick SQL or NoSQL)As users grow, one box is not enough. We split it into two: a web tier (handles web and mobile traffic) and a data tier (the database).…
- 1.3Vertical vs horizontal scaling⬆️ Vertical scaling ("scale up") Add more CPU and RAM to one server ✅ Very simple, no code changes ❌ Hard limit: you can't add infinite CPU…
- 1.4Load balancerA load balancer spreads incoming traffic across a group of web servers. Users connect to the load balancer's public IP. The web servers are…
- 1.5Database replicationThe web tier is now redundant, but we still have one database. The fix is replication, usually in a master/slave setup (also called…
- 1.6CacheA cache is a temporary store, kept in memory, for expensive or frequently used data. Memory is much faster than a database, so repeated…
- 1.7Content delivery network (CDN)A CDN is a network of servers spread around the world that cache static content: images, videos, CSS and JavaScript files. A user gets the…
- 1.8Stateless web tierTo scale the web tier horizontally, we must move state (like user session data) out of the web servers. 🔒 Stateful server Remembers client…
- 1.9Multiple data centersAs your site gets popular internationally, you add more data centers for better availability and speed. Users are geoDNS-routed…
- 1.10Message queueA message queue is a durable, in-memory buffer that lets parts of a system talk asynchronously: one side drops work into it, and the other…
- 1.11Logging, metrics and automationA small site can get by without these tools. A large business can't. Logging: monitor error logs to find problems early. Logs can be…
- 1.12Database scaling and shardingThere are two ways to scale a database: Vertical: a more powerful machine. Amazon RDS offers servers with 24 TB of RAM, and in 2013 Stack…
- 1.13Millions of users and beyondScaling is an endless journey. As you grow past millions of users you may also split the system into smaller services (decoupling). But…