Deployment & CI/CD Basics
What happens between pushing a code change and that change running live for real users.
What is it?
Code that works on your laptop still has to reach a real server that users can access, without breaking what already works. Doing that by hand (copying files, restarting things, hoping nothing was forgotten) is slow and error-prone, especially as a team grows.
CI/CD stands for Continuous Integration and Continuous Deployment (or Delivery):
- Continuous integration: every change is built and tested automatically when it's pushed, so problems are caught early instead of piling up.
- Continuous deployment (or delivery): once a change passes those checks, it ships to production automatically (or with one click), using the same repeatable steps every time.
Explain like I'm 10
Think of a factory assembly line versus one craftsperson building each product by hand. The line runs the same checks and steps on every item (the same inspection, the same packaging), catching defects early and shipping consistently, instead of relying on someone to remember every step each time.
Examples
A CI pipeline definition
# .github/workflows/ci.yml (conceptual)
name: CI
on: [push]
jobs:
test:
steps:
- run: npm install
- run: npm run build
- run: npm testOn every push, this pipeline installs dependencies, builds the project and runs the tests, so nobody has to remember to.
A deployment step that only runs after tests pass
jobs:
test:
steps:
- run: npm test
deploy:
needs: test # only runs if the "test" job succeeded
steps:
- run: ./deploy.sh productionThe deploy job only runs if the test job succeeds, so broken code never reaches production.
How it works
On each push, a CI/CD system runs a defined sequence: install dependencies, build the project (if needed), run the tests, and sometimes extra checks like linting or security scanning.
If every step passes, a deploy step can run: package the app (often as a container image), push it to a hosting platform or server, and switch live traffic to the new version. Ideally there's a quick way to roll back if something still goes wrong once it's live.
Why does it exist?
Manual deployment is slow, inconsistent, and depends on someone remembering every step every time, which fails as a team and codebase grow. CI/CD makes shipping repeatable, automated and verified: every change gets the same checks, and getting a fix live becomes fast and low-risk instead of a stressful manual ritual.
When to use it
Set up CI at the start of any real project; even one automated test run per push catches obvious mistakes early. Add continuous deployment once your tests give you confidence that a passing pipeline means the change is safe to ship.
When not to use it
For a throwaway prototype or a script you'll run once by hand, a full pipeline is unnecessary ceremony. It pays off when code is deployed and changed repeatedly.
Common mistakes
Deploying automatically even when tests fail, which defeats the point of tests gating the pipeline.
Having no quick way to roll back a bad deployment once it's live.
Treating a green pipeline as proof everything is fine, when the tests don't cover the part that broke.
Practice exercises
- Easy:
Describe, in order, the steps you'd expect a CI pipeline to run for a typical Node.js backend.
- Medium:
Explain why a deploy step should only run after the test step succeeds, and what could go wrong otherwise.
- Hard:
Describe a rollback strategy for a deployment whose serious bug is found only after it reached production.
Interview questions
What does CI/CD stand for, and what does each part mean?
Continuous Integration: automatically building and testing every change as it's pushed. Continuous Deployment/Delivery: automatically or reliably shipping a change that passes those checks to production.
Why is it important that deployment only happens after tests pass?
It stops broken or untested code from reaching production automatically. The test suite is a gate every change must pass.
Why is manual deployment risky as a team or codebase grows?
It relies on a person doing every step correctly every time, which gets more error-prone and inconsistent as complexity and team size grow.
What is a blue-green deployment?
Two identical production environments: 'blue' (live) and 'green' (the new version). Green is deployed and checked while blue serves all traffic, then traffic switches to green at once, leaving blue as an instant rollback target.
What is a rolling deployment?
New instances come up and old ones go down a few at a time, instead of switching everything at once. During the rollout, old and new versions both serve live traffic.
What's a key tradeoff between blue-green and rolling deployment?
Blue-green needs double the infrastructure at once but gives instant, clean rollback with no mixed-version traffic. Rolling needs less extra infrastructure but runs old and new side by side, which is a problem if they aren't compatible.
What is a canary deployment?
The new version goes to a small share of real traffic or users first and is monitored, then rolled out further once it looks healthy. This limits the damage of a bad deploy compared with shipping to everyone.
Why does a database migration need special care during a rolling or blue-green deployment?
Old and new code use the same database during the rollout. A migration that removes or renames a column the old code still uses breaks the old instances before they're retired.
What is a CI pipeline's build step generally responsible for, beyond installing dependencies?
Compiling or transpiling code, bundling assets, or otherwise producing the runnable artifact that is then tested and deployed, e.g. type-checking plus bundling for a TypeScript project.
Why does `needs: test` on the deploy job matter mechanically, not just as convention?
It tells the CI system not to start the deploy job until the test job has finished and succeeded. If tests fail, deploy is actually skipped, not just expected to be.
What's the difference between continuous delivery and continuous deployment?
Continuous delivery makes every passing change ready to release, usually with one manual approval to ship. Continuous deployment ships it to production automatically, with no manual step.
Why is a build artifact often packaged as a container image?
A container image bundles the app with its exact runtime and dependencies, so it runs the same everywhere and the tested environment matches the one it runs in.
Why should the same build artifact that passed CI be the one deployed, rather than rebuilding from source at deploy time?
Rebuilding risks a different result (a dependency resolving differently, an environment difference), so what ships was never what was tested. Reusing the same artifact guarantees what was tested is what ships.
What does rollback mean in a deployment context, and why does it need to be fast?
Reverting production to the last known-good version after a bad deploy is found. The longer a broken version is live, the more users and requests it affects, so slow rollback extends the damage.
How does blue-green deployment make rollback close to instant?
The previous version, blue, is still running and untouched after the switch. Rolling back just routes traffic back to blue, with no rebuild or redeploy.
Scenario: a deploy passes CI, ships, and real users then hit errors no test caught. What does this reveal?
A green pipeline only proves the existing tests passed. It says nothing about behavior they never exercised, so this points to a coverage gap for that code path, not a broken pipeline.
What is a health check, and what role does it play during a deployment?
An endpoint or process that reports whether an instance is healthy and ready for traffic. The deployment system uses it to decide whether new instances can take traffic, or to halt a rollout automatically if they keep failing.
Why might a CI pipeline include a linting step in addition to tests?
Linting catches problems tests don't check directly (style inconsistencies, unused variables, some likely bugs) by analyzing the code without running it.
Trap: a team's CI pipeline is green, but they still deploy manually by copying files to a server 'for now.' What risk does this defeat?
A passing pipeline isn't a safety guarantee if deployment isn't the same automated, repeatable process every time. Manual deployment brings back exactly the human error CI/CD exists to remove, however solid the CI checks are.
What secrets-related concern is specific to CI/CD pipelines?
Pipelines often need credentials (deploy keys, API tokens) to deploy. Store them securely, e.g. as encrypted pipeline secrets, not in the pipeline definition file, which anyone with repo access can often see.
Why run the same test suite on every pull request, not just on the main branch after merging?
Catching a problem before merge means a broken change never lands on the branch others build on, instead of being found and reverted later.
What does it mean for a deployment pipeline to be idempotent, and why does that matter?
Running the same deploy step twice (e.g. after a retry) gives the same end result instead of compounding the effect. It matters because pipelines sometimes retry steps after transient failures, like a flaky network call.
Follow-up: is a fast rollback path alone enough to guarantee a bad deploy is safe?
No. You also need monitoring and alerting to detect the bad deploy quickly. A fast rollback that only happens after users have been affected for hours limits far less damage than it could.
How does a canary deployment differ from A/B testing, even though both route a subset of traffic differently?
A canary is about deployment safety: checking the new version works before a full rollout, usually briefly. A/B testing compares two versions' real-world outcomes, often over longer, to decide which is better, not to safety-check a release.
Advanced: why might a rolling deployment be a poor fit for a breaking database schema change, even with careful ordering?
Old and new code must both work with whatever schema exists during the rollout. Some schema changes have no safe intermediate state that satisfies both, so you need another strategy, like a multi-step expand-and-contract migration.