FullStack AI Hub
Studio
System Design · 08. Shipping
11 min
10 steps
Beginner

CI/CD & Deployments

Ship safely from Git commit to production with immutable artifacts, blue-green switching, and expand-and-contract migrations.

System Design08. ShippingLesson 1 of 2
11 minBeginner10 steps

CI/CD & Deployments

Ship safely from Git commit to production with immutable artifacts, blue-green switching, and expand-and-contract migrations.

Change Failure Rate
35%
Rollback Time
45 min
Server Drift
High
Deploy Cadence
1× / month
Live UsersLoad BalancerServer A(v2)Server B(Broken)Server C(v1)
Live Production Traffic
Build / Artifact Promotion
Readiness / Smoke Probe
Healthy Green Traffic
Error / Rollback Trigger
In This LessonStep 1 of 10
What You Will Master
  • ✓Eliminate snowflake server drift with automated CI gates and immutable signed artifacts
  • ✓Ship zero-downtime releases using rolling connection draining and Blue-Green cutovers
  • ✓Evolve live production database schemas safely with the Expand-and-Contract pattern
  • ✓Track DORA engineering metrics and achieve sub-minute MTTR via instant artifact rollback

Architectural Trade-Off Comparison Matrix

PatternBest ForKey Trade-Off
Rolling DeploymentCost-efficient stateless fleets replacing pods gradually (25% surge / 0 unavailable)Old and new app versions run concurrently; rollback requires another rolling wave
Blue-Green DeploymentMission-critical APIs needing instant 1-second cutover and <10-second rollbackRequires temporary 2× compute capacity while Blue stays warm beside Green
Expand-and-Contract DBRenaming or splitting live production SQL columns without breaking running codeSplits one schema change into 3 small sequential PRs (Expand → Backfill → Contract)
Immutable Signed DigestGuaranteeing Staging and Production run the exact bit-for-bit verified containerEnvironment differences must be injected strictly via runtime config/secrets, never rebuilds

Step-by-Step Architectural Breakdown (10 Steps)

Full architectural walkthrough transcript and state transitions for CI/CD & Deployments.

STEP 01 · PROBLEMJump to step →

Manual SSH Deploys & Configuration Drift

Early teams deploy by SSHing into production servers and running `git pull && npm install && pm2 restart`. Soon Server A has Node 20.1, Server B has a hotfixed config file from last Friday’s incident, and Server C fails mid-install—creating **snowflake servers**.

Every deploy becomes a white-knuckle Friday evening ritual: broken builds take down live users during `restart`, and rolling back requires guessing which package versions used to work.

watch:If you have to SSH into a server to deploy or debug a missing dependency, your production environment is not reproducible.

Configuration DriftSnowflake ServersMutable InfrastructureDeploy Downtime
STEP 02 · SOLUTIONJump to step →

Automated Continuous Integration (CI) Gates

**Continuous Integration (CI)** runs an identical, containerized verification suite on every pull request before code can merge to `main`: static typing & lint, unit tests, ephemeral database integration tests, and SAST/CVE dependency scans.

Fast parallel CI (< 6 minutes) catches regressions when the diff is 40 lines and fresh in the author’s mind—never 3 weeks later in a giant release branch.

good:Keep CI green and fast (<10 min) by sharding tests across parallel workers and caching dependencies; slow 45-minute CI pipelines encourage huge, risky batch PRs.

Continuous IntegrationParallel Test ShardsSAST / CVE ScanMerge Gate
STEP 03 · TECHNIQUEJump to step →

Build Once, Promote Immutable Signed Artifacts

Never rebuild code separately for Staging and Production—an upstream npm package or base OS update between builds means what you tested in Staging is **not** what you shipped to Prod.

Instead, CI builds **one immutable Docker container image**, signs its cryptographic **SHA-256 digest** (`@sha256:8f3a...`), and promotes that **exact same digest** through Dev → Staging → Production, injecting only environment config at runtime.

idea:Pin deployments to immutable `@sha256:...` digests rather than mutable tags like `:latest`—so autoscaling a new pod at 3 AM always pulls the exact verified bytes.

Immutable ArtifactsBuild Once Promote ManySHA-256 DigestSBOM Signing
STEP 04 · TECHNIQUEJump to step →

Rolling Deployments & Graceful Connection Draining

A **Rolling Deployment** replaces old `v1` pods with `v2` pods one batch at a time (`maxSurge: 1, maxUnavailable: 0`). The load balancer only adds a new `v2` pod once its **`/readyz` readiness probe** returns HTTP 200.

To eliminate deploy-time `502 Bad Gateway` blips, handle **`SIGTERM` gracefully**: remove the `v1` pod from the LB first, wait 5 seconds for kube-proxy/LB propagation, finish all in-flight HTTP requests, and only *then* exit.

watch:Never kill a process immediately on `SIGTERM`! In-flight checkout requests take 100–500 ms to complete—always drain active connections cleanly.

Rolling UpdateReadiness ProbeSIGTERM DrainingZero 502 Deploys
STEP 05 · SOLUTIONJump to step →

Blue-Green Deployments (Instant Cutover)

In a **Blue-Green Deployment**, your live fleet (**Blue v1**) serves 100% of users untouched while you provision a completely identical parallel fleet (**Green v2**). You run full smoke tests against Green privately before a single real customer hits it.

When Green passes verification, you flip the Load Balancer target group from Blue → Green in **< 1 second**. You never have mixed v1/v2 versions fighting over shared UI assets—and **Blue stays warm** for instant 10-second rollback if anything looks off.

good:Blue-Green eliminates mixed-version chaos and guarantees sub-minute rollback, at the trade-off of paying for 2× compute for the 15–30 minutes Blue stays warm.

Blue-Green DeployAtomic LB CutoverWarm StandbyZero Mixed Versions
STEP 06 · TECHNIQUEJump to step →

Zero-Downtime DB Migrations: Expand-and-Contract

Notice that both Blue (`v1`) and Green (`v2`) share the **same live database**. If `v2` runs `ALTER TABLE users RENAME COLUMN name TO full_name`, every remaining `v1` server (and any rollback to Blue!) immediately crashes with `column "name" does not exist`.

Solve this with **Expand-and-Contract**: (1) **Expand** by adding nullable `full_name` alongside `name` and deploying code that dual-writes both; (2) **Backfill** old rows in throttled batches; (3) switch reads to `full_name`; (4) **Contract** by dropping `name` only after `v1` is gone for good.

good:Rule of zero-downtime schemas: every DB migration MUST be backward-compatible with the currently running previous version of your application.

Expand-and-ContractBackward-Compatible SchemaDual-Write BackfillSafe Rollback
STEP 07 · TECHNIQUEJump to step →

Automated Post-Deploy Smoke Checks & Synthetics

A container returning HTTP 200 on `/health` only proves the web server started—it does not prove checkout, auth, or third-party webhooks work! Immediately after deploying Green (before and after cutover), CD pipelines execute **synthetic smoke transactions**.

Synthetic probes create a test login, query a read endpoint, verify P95 latency and 5xx budgets, and automatically block promotion (or trigger rollback) if any critical journey degrades.

idea:Tag synthetic test accounts cleanly (`synthetic_canary = true`) so smoke orders never pollute real revenue analytics or trigger warehouse shipments.

Synthetic ProbesSmoke TestsSLO Verification GateAutomated Promotion
STEP 08 · TECHNIQUEJump to step →

Measuring Shipping Health with DORA Metrics

How do elite teams know whether speed is hurting stability? They track the four **DORA Metrics**: **Deployment Frequency** and **Lead Time for Changes** (velocity), balanced directly against **Change Failure Rate (CFR)** and **Mean Time to Restore (MTTR)** (stability).

Counterintuitively, shipping **smaller batches more frequently** improves *both* speed and stability: a 30-line deploy is trivial to review, obvious to diagnose, and takes 10 seconds to roll back.

good:Elite DORA benchmarks: Multiple deploys/day, < 1 hour commit-to-prod lead time, < 5% Change Failure Rate, and < 15 minutes MTTR.

DORA MetricsDeployment FrequencyLead TimeCFR & MTTR
STEP 09 · SOLUTIONJump to step →

Emergency 10-Second Rollback & Artifact Pinning

Even with great CI, a subtle production memory leak or traffic-dependent bug will eventually slip onto **Green v2**. Never try to "fix forward" by writing a rushed patch and waiting 15 minutes for CI while users are down!

Instead, click **Rollback** (or let the SLO alarm fire automatically): the Load Balancer flips 100% of traffic back to the warm **Blue v1** fleet in **10 seconds**, restoring service immediately so engineers can debug Green calmly offline.

good:Restore first, root-cause second! Keep Blue warm for 30–60 minutes post-cutover and never delete the last 10 production container digests from your registry.

Instant RollbackRestore FirstMTTR < 1 MinuteWarm Blue Standby
STEP 10 · RECAPJump to step →

Production CI/CD & Blue-Green Architecture

Boring, predictable deploys are a superpower: **fast CI gates** test every small PR, **immutable signed digests** eliminate server drift, **Expand-and-Contract** keeps database schemas backward-compatible, and **Blue-Green cutovers** with automated smoke checks make rollback a 10-second button click.

Next up: learn how **Feature Flags & Canaries** take safe shipping one step further by decoupling code deployment from user-facing feature launches.

good:If deploying on a Friday afternoon feels scary, fix your pipeline—not your calendar!

Immutable DigestBlue-Green CutoverExpand-and-ContractDORA Excellence

Related Production Deep-Dives & Simulators

Included In Free Course
Free · Verifiable Credential

FS-102LLM Systems Foundations

Build a connected mental model from tokens through retrieval evaluation security and operations.

24 concepts~18h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.