Design a CI/CD System
Understanding the Problem
🚀 What is a CI/CD system? Continuous integration (CI) builds and tests code every time someone pushes, so broken changes are caught in minutes. Continuous delivery or deployment (CD) takes the artifact a successful build produced and rolls it out to production. GitHub Actions, GitLab CI, Jenkins and CircleCI handle the CI half; tools like Spinnaker and Argo CD, or a company's in-house deploy system, handle the CD half.
You'll hear this question in a few forms: "design GitHub Actions," "design Jenkins," "design a system that deploys code to 100,000 servers worldwide," or "design over-the-air (OTA) updates for cars or phones." These are the same pipeline, viewed from different ends. Code becomes an immutable artifact, the artifact is verified, and then it's rolled out gradually to a fleet with health checks and a way back. Servers and devices are just different fleets. We'll design the full pipeline and treat global deploys and OTA updates as deep dives.
Functional Requirements
Core Requirements
- Users should be able to define pipelines in a config file in their repo, and have them run automatically on pushes and pull requests.
- Users should be able to watch a run's status and live logs, and see the result on the commit or pull request.
- Successful builds should produce versioned artifacts (container images, binaries) that are stored and can be deployed.
- Users should be able to deploy an artifact to a fleet of servers across regions, gradually, with automatic rollback if it's unhealthy.
Below the line (out of scope)
- The source control system itself (we receive its webhooks; see GitHub).
- A marketplace of reusable pipeline steps.
- Billing for build minutes.
Non-Functional Requirements
Let's pick numbers for a hosted, multi-tenant service: 2 million pipeline runs per day, averaging 5 jobs each, so 10 million jobs per day. A typical job runs for about 10 minutes.
Core Requirements
- A job should start on a runner within about 30 seconds of being ready, at the 95th percentile.
- Jobs from different customers must be strongly isolated. Builds run arbitrary, often untrusted code (any pull request from a fork).
- Run status must never be lost or wrong: a green check must mean the job actually passed.
- Deploys should reach 100,000 servers in 10 regions within an hour, and a bad release should be stopped before it reaches more than a few percent of the fleet.
- The service should stay available through traffic peaks (weekday mornings in the US and Europe) and runner pool failures.
Below the line (out of scope)
- Build reproducibility guarantees (hermetic builds) beyond caching.
- Compliance certifications for the build environment.
Back-of-the-envelope. 10M jobs/day ÷ 86,400 ≈ 115 job starts per second on average, and work hours concentrate that into maybe 400 per second at peak. The more useful number comes from Little's law: concurrent jobs = arrival rate × duration. At peak, 400/s × 600 s ≈ 240,000 jobs running at the same time. Each one needs its own isolated machine, so the runner fleet, not the control plane, is the expensive and hard part.
Logs: if a job writes about 1 MB of logs, that's 10 TB/day, or about 115 MB/s on average, all of which someone might be watching live.
Little's law is the most useful formula in this interview. Interviewers often give you a rate (jobs per second) and leave you to realize the real constraint is concurrency (machines in use right now). Do the multiplication out loud.