Deployment & environments

Vercel vs a Docker container on a VPS, environment config, preview deploys, running migrations safely (expand-migrate-contract).

About 27 min read3-question knowledge check

The mental model

Deployment is the moment your code stops being a thing you control and becomes a thing your users depend on. The whole discipline is about changing a running system without the people using it noticing — new code, new schema, new config, all swapped in while requests are in flight. The mental model that organizes it: a deploy is not "copy files and restart"; it is a controlled transition between two versions of a system that must both work during the overlap.

The single most important idea, the one that separates engineers who have caused an outage from those who are about to: old code and new code run at the same time during every deploy. Whether you use rolling updates, blue-green, or a platform like Vercel, there is always a window where some requests hit the old version and some hit the new one. If your database schema, your API contract, or your config assumes only one version exists, that window is where writes get dropped and errors spike. This is why schema changes must be done as expand → migrate → contract, never as a single "rename the column and deploy" — the rename breaks the old code that is still serving traffic.

The analogy: deploying is like replacing the engine of a plane while it's flying. You cannot land (take downtime) for most products, so you add the new engine alongside the old, shift load to it gradually, confirm it works, and only then remove the old one — and at every step both engines must be capable of flying the plane. A schema migration is the same shape: add the new column (both engines have fuel), backfill it (fill the new tank), switch reads to it (fly on the new engine), then drop the old column (remove the dead engine). Do it in one step and you have a moment with no working engine.

Why this exists as a topic: "it works on my machine" is a statement about one environment with one version and one config. Production is many machines, two versions mid-deploy, and config you cannot see. The gap between those is where deployment lives.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision