---
title: Deployment
summary: Getting code from your laptop to users, reliably and repeatably.
section: shipping
phase: ship
order: 1
last_reviewed: 2026-11-20
---

# Deployment

Deployment turns a repo into a running service at a URL. The goal is to make it boring: every merge to `main` ships automatically, and a bad release can be rolled back in one click.

## You'll be able to
- Choose a hosting model that fits your app
- Understand builds, CI/CD, preview deployments and rollbacks
- Ask an agent for a deployment setup that holds up in production

## The mental model
**Push → CI builds & tests → artifact (bundle or container image) → deploy to an environment → health check → traffic switches over.** A rollback means pointing traffic back at the previous artifact.

## Key concepts
- **Hosting models:**
  - **Platform (PaaS / frontend clouds):** Vercel, Netlify, Cloudflare, Render, Railway, Fly.io. Push to git and it's live. **The default.**
  - **Serverless functions:** Code runs per request, with no servers to manage. Watch for cold starts, time limits and statelessness.
  - **Containers:** A **Docker** image packages your app with its runtime, so it runs the same everywhere. Run it on Fly, Railway, Cloud Run, ECS, or a VPS.
  - **VPS:** A raw virtual machine (Hetzner, DigitalOcean). Cheapest, but every operational task is yours (updates, TLS, firewall).
  - **Kubernetes:** Container orchestration at scale. You almost certainly don't need it yet.
- **Build:** Compile and bundle your code into what actually runs.
- **CI/CD:** Continuous Integration (test every push) and Continuous Delivery/Deployment (ship automatically). GitHub Actions is the common choice.
- **Environments:** Local → preview (per-PR) → staging → production.
- **Preview deployments:** A live URL for every PR. Very useful for reviewing agent work.
- **Zero-downtime / blue-green / rolling:** The new version starts before the old one stops.
- **Health check:** An endpoint (`/health`) the platform checks before sending traffic.
- **Infrastructure as Code (IaC):** Infrastructure defined in files (Terraform, Pulumi, SST) instead of clicked together in a console.
- **Edge vs region:** Edge functions run near users. Your database sits in one region, so place compute close to it.

## Decisions you make (not the agent)
| Decision | Sensible default | Choose otherwise when… |
|---|---|---|
| Host | Vercel/Netlify (Next.js, static), Railway/Render/Fly (long-running servers, workers) | Cost at scale or compliance → containers on a cloud or VPS |
| Packaging | Platform-native build | Multiple services or portability needed → Dockerfile |
| CI | GitHub Actions: lint, type-check, test on every PR | — |
| Deploy trigger | Merge to `main` → prod; PR → preview | Regulated → manual approval gate |
| Region | Same region as your database | — |

### Not sure? Answer a few questions

```decision
title: Pick your deployment setup
Q: What are you deploying? | Host
- A Next.js app or a static site -> Vercel or Netlify | The platform defaults for Next.js and static sites.
- A long-running server or a background worker -> Railway, Render or Fly | They are built for long-running processes.
- Cost at scale or compliance matters more than convenience -> Containers on a cloud or a VPS | More control, and more to operate yourself.
Q: One service or several? | Packaging
- One app on a standard framework -> The platform's native build | No extra tooling to maintain.
- Several services, or I need to move between hosts -> A Dockerfile | Containers give portability.
Q: Does your industry require sign-off before a release? | Deploy trigger
- No -> Merge to main deploys to production, and every pull request gets a preview | The default workflow.
- Yes (a regulated environment) -> Add a manual approval gate before production | Keeps a human decision in the release path.
```

## What good output looks like

- A pipeline where every PR runs checks, merging deploys, and every PR gets a preview
- Configuration comes from environment variables per deploy, with secrets in the platform's secret store, never in the repository
- A rollback path that has been **tried**, plus a written note of what it does not undo
- A health check, and compute in the same region as the database
- Every manual step (clicks, DNS, secrets) listed instead of assumed

## Red flags
- Deploying from a laptop by hand
- No way to roll back
- Secrets baked into a Docker image or committed (see [Environments & secrets](/docs/shipping/environments-and-secrets.md))
- Compute running in a different region from the database (slow queries)
- Kubernetes for a side project
- **Common agent mistakes:** a workflow that deploys production from every branch push; long-lived cloud credentials stored as secrets where the provider supports short-lived access through OIDC (GitHub's documentation recommends OIDC for cloud access); a migration step that leaves the old version of the code unable to run, so rolling back doesn't help; secrets printed in build logs

## Worked example

**Task:** A release goes out and errors spike. You roll back.

The pipeline the agent set up merges, migrates the database, then deploys. This release's migration dropped a column the old code still reads. You press the platform's rollback button and the site is still broken.

**What a good result contains:** a rollback that has been rehearsed, migrations written so the previous version of the code still works with the new schema (expand now, contract in a later release), and a short written note of what the rollback does not cover.

**The wrong turn:** a rollback switches traffic back to an earlier build. That is what the Twelve-Factor App calls a release-management feature: you point at a previous release. It doesn't reverse your database. On Vercel, as of November 2026, an instant rollback points production domains back at an earlier deployment but does not change environment variables, databases or external APIs, and afterwards new pushes don't go live until you promote a deployment again. Here the old code meets a schema it doesn't understand.

**How review catches it:** before the release, ask *what does a rollback not undo?* and rehearse it in staging: deploy, migrate, roll back, and check the app. Read every migration with one question: can the previous version of the code run against the new schema? If not, split it using expand/contract (see [Schema & migrations](/docs/data/schema-and-migrations.md)).

## Sample prompts

### Weak vs strong
```compare
## Weak
Deploy my app.
## Why it fails
No host, database, checks, environments or rollback plan, so the agent picks a platform and wires up whatever is easiest, and you find the gaps in production.
## Strong
Set up deployment for this Next.js app on Vercel with a Neon Postgres database.
- GitHub Actions: on PR run install, lint, type-check, tests; block merge on failure
- Vercel preview deploy per PR using a Neon branch database per preview
- Run Drizzle migrations against prod as a step before promoting production
- Document required env vars in .env.example and the README
Explain each piece and what I need to click/configure manually.
## Why it works
It names the host and database, the checks that block a merge, preview deployments, the migration step, documentation of environment variables, and asks for the manual steps it can't do.
## What changed
- **Host and database** are named
- **Checks** (lint, type-check, tests) must pass before a merge
- **Previews** use a per-PR database branch, so tests don't touch production
- **Migrations** run as a step before promotion
- **Manual steps** are listed instead of hidden
```

```text
Write a production Dockerfile for this <Node/Python> service: multi-stage build,
minimal base image, non-root user, healthcheck, only production deps, and a
.dockerignore. Then a fly.toml (or railway config) to deploy it in <region> with
zero-downtime rolling deploys.
```
*Why it works:* It asks for the specific production practices (multi-stage build, non-root user, health check) rather than "a Dockerfile", so the agent can't stop at one that merely runs.

### Write the rollback runbook
```text
Write a rollback runbook for this app on <platform>. Cover: how to roll back the application, exactly what that does and does not undo (database schema, environment variables, external services, scheduled jobs), how to tell whether a migration makes the previous version incompatible, and how to roll forward instead when rollback isn't safe. Include a rehearsal I can run in staging and what a successful rehearsal looks like.
```
*Why it works:* It asks for the limits of rollback up front. The rehearsal turns the runbook into something tested.

### Audit the pipeline
```text
Audit our CI/CD configuration. List: any step that deploys production from a branch other than main; any manual step that isn't documented; secrets used in workflow files (and whether they are printed, passed as command-line arguments, or available to workflows from forks); long-lived cloud credentials where short-lived access through OIDC is available; whether merges are blocked when checks fail; and whether the app and the database are in the same region. Don't change anything yet.
```
*Why it works:* It names the pipeline mistakes agents most often make, so the answer is a short list you can verify.

### Explain what each stage does
```text
Walk through the pipeline stage by stage: what triggers it, what it builds, which environment variables each stage reads and where they come from, what failure blocks, and what is deployed at the end. Point out anything that happens only in a person's head or browser, and anything that differs between preview and production.
```
*Why it works:* Build, release and run are separate stages. Stating the inputs and the failure behaviour of each shows the gaps.

## Check your understanding

```quiz
Q: What does a rollback typically do?
- [ ] Reverses everything the release changed, including the database
- [x] Points traffic back at an earlier build. It doesn't undo database changes or changes to external services
- [ ] Deletes the release
> Why: A release is a build plus its configuration, and rollback switches to a previous one. Data changes and outside systems are separate.

---

Q: Which migration style keeps a rollback safe?
- [ ] Dropping the old column in the same release as the code change
- [x] Expand first, switch the code over, and contract in a later release, so the previous code still works
- [ ] Editing the migration after it ran
> Why: The previous version of the code has to work against the schema that is live when you roll back.

---

Q: Where should configuration that differs between deploys live?
- [ ] In constants in the code
- [x] In environment variables set per deploy, with secrets in the platform's secret store
- [ ] In a config file committed to the repository
> Why: The Twelve-Factor App's test: could you open-source the codebase today without exposing any credentials?
```

## Checklist
- [ ] Every PR runs automated checks
- [ ] Production deploys are automated
- [ ] Rollback is tested and takes one click
- [ ] Health check endpoint exists
- [ ] Compute and database are in the same region
- [ ] I know what a rollback does not undo, and I have rehearsed it
- [ ] Migrations are compatible with the previous version of the code
- [ ] Production deploys come only from `main`

## Go deeper
- [The Twelve-Factor App](https://12factor.net)
- [Docker: Get started](https://docs.docker.com/get-started/)
- [GitHub Actions docs](https://docs.github.com/en/actions)
- [Twelve-Factor App: Build, release, run](https://12factor.net/build-release-run): why rollback is switching releases
- [Vercel: Instant Rollback](https://vercel.com/docs/instant-rollback): what a rollback does and doesn't change
- [GitHub: Using secrets in GitHub Actions](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions)
- [Schema & migrations](/docs/data/schema-and-migrations.md): changing a database without breaking the old code
