Session 4 Slides
Session 4 · 75 minutes · slides

Hosting, Scaling, and the Cloud

From one rented server to the distributed architecture behind products serving millions

  1. 4.1 From localhost to production
  2. 4.2 Step 1: everything on one server
  3. 4.3 Step 2: the database gets its own machine
  4. 4.4 Step 3: many web servers behind a load balancer
  5. 4.5 Step 4: caches, CDNs, and storage
  6. 4.6 The cloud menu
  7. 4.7 Shipping code safely

Arrow keys or space to move, F for full screen. Every slide has a Book button back to the full text.

Session 4 · 4.1 From localhost to production · 1/2Book ↗

Deploying, and the three environments

EnvironmentWho uses itPurpose
DevelopmentEach programmer, own machineWrite and try code; break things
StagingThe team, testersPrivate replica of production to check a release
ProductionReal customersThe actual business; real, protected data
Session 4 · 4.1 From localhost to production · 2/2Book ↗

Uptime and latency

UptimeDowntime per yearTypical of
99%About 3.7 daysHobby site on one cheap server
99.9%About 8.8 hoursSmall business with sensible hosting
99.99%About 53 minutesPayments, banking, large SaaS
99.999%About 5 minutesTelecom; very expensive
Each extra nine costs dramatically more. Latency: users notice anything over ~100 ms.
Session 4 · 4.2 Step 1: everything on one server · 1/2Book ↗

Rent one computer and install everything

Browser Browser Phone app Customers, anywhere the internet HTTPS, port 443 One rented server (VPS), Linux, IP 203.0.113.7 Web server Nginx HTTPS, static files Back end Python app port 5000 Database PostgreSQL port 5432 All three programs share one processor, one memory, one disk, one power supply
Step 1: the single-server deployment. Simple, cheap, and enough for thousands of daily visitors. Every component shares the same hardware, so every component shares the same fate.
Session 4 · 4.2 Step 1: everything on one server · 2/2Book ↗

Why it eventually breaks

Take each next step when the problem is real, not before.
Session 4 · 4.3 Step 2: the database gets its own machine · 1/2Book ↗

Separate the data tier

Customers HTTPS Web server (public IP) Nginx HTTPS, static Back end Python Database server (private IP) PostgreSQL more memory, fast disks, backups SQL over the private network No path from the internet to the database. Only the web server may connect.
Step 2: the database moves to its own machine on a private network. The public internet can reach the web server but not the database. Each machine can now be sized for its own job.
Session 4 · 4.3 Step 2: the database gets its own machine · 2/2Book ↗

Why the second bill is worth it

Session 4 · 4.4 Step 3: many web servers behind a load balancer · 1/3Book ↗

Two ways to add capacity

Vertical: one bigger machine 4 GB 64 GB still only one Ceiling: the largest machine that exists Horizontal: more identical machines 4 GB 4 GB 4 GB 4 GB … and as many more as needed Ceiling: none in principle. Losing one copy is survivable.
Two ways to add capacity. Vertical scaling is a bigger box; horizontal scaling is more boxes. Modern architecture is built around the second.
Session 4 · 4.4 Step 3: many web servers behind a load balancer · 2/3Book ↗

Horizontal scaling with a load balancer

Customers HTTPS Load balancer public IP health checks Web server 1 Nginx + Python Web server 2 Nginx + Python Web server 3 failed: skipped Identical copies of the same code. Add a fourth in minutes. Database server PostgreSQL (one copy) Session store Redis: who is logged in Shared state lives here, not on any web server
Step 3: horizontal scaling. The load balancer is the only public address. Web servers are interchangeable and disposable; anything that must be remembered between requests lives in the shared database or session store.
Session 4 · 4.4 Step 3: many web servers behind a load balancer · 3/3Book ↗

The catch: servers must be stateless

Ask before launch: "Can we run two copies of this?"
Session 4 · 4.5 Step 4: caches, CDNs, and storage · 1/2Book ↗

Four more components

Session 4 · 4.5 Step 4: caches, CDNs, and storage · 2/2Book ↗

The standard architecture of a serious web product

Customers web + mobile CDN images, CSS, JS static files Load balancer HTTPS ends here Private network: not reachable from the internet Web server Web server Web server stateless, N copies Redis cache + sessions Database primary (writes) Replica reads, standby Object storage uploads, PDFs CDN pulls files from storage Third-party APIs Stripe, Claude, email
Step 4: the standard architecture of a serious web product. Every box here can be rented as a managed service. Compare with the single server in Step 1: same three tiers, each one now duplicated, cached, or moved closer to the user.
Session 4 · 4.6 The cloud menu · 1/2Book ↗

How much of the work do you want to do yourself?

LayerYou getYou manageExamples
IaaSVirtual machines, disksEverything on themEC2, DigitalOcean
PaaS"Here is my code; run it"Just code and dataRender, Railway, Vercel, Fly.io
SaaSA finished productYour settingsGmail, Shopify, Slack
ServerlessRun this function on demandThe functionAWS Lambda, Cloudflare Workers
Pizza: rent a kitchen, a meal kit, delivery, or a vending machine that bakes one slice.
Session 4 · 4.6 The cloud menu · 2/2Book ↗

Containers, and the advice for this course

Session 4 · 4.7 Shipping code safelyBook ↗

How code reaches customers

Developer commits to Git Tests run automatically (CI) Staging team checks it Production deployed (CD) Monitoring errors, latency alerts and bug reports flow back to the developer
How code reaches customers. Each arrow is automated. A change that fails its tests never reaches staging; one that misbehaves in production is caught by monitoring and rolled back through version control.
1 / 1Hosting, Scaling, and the Cloud