CI/CD Pipeline Design and Architecture Questions
Structure and operation of continuous integration and continuous delivery pipelines: stages, triggers, build/test/deploy steps, pipeline-as-code, caching, and parallelization. Covers designing enterprise-scale CI/CD architecture, integrating version control with automated pipelines, and shaping delivery workflows across many services. Focuses on how work moves from commit to production, not on the individual test suites that run inside it.
Write a GitHub Actions workflow YAML (provide the YAML content) that builds a multi-architecture Docker image (linux/amd64 and linux/arm64) using docker buildx, caches layers, generates an SBOM using syft, scans the image with Trivy, signs the image with cosign, and pushes immutable tags to a container registry. Include secure handling of registry credentials and cosign keys using GitHub Secrets and best practices for caching.
Sample Answer
A single workflow that builds for two architectures, generates an SBOM, scans, and signs needs each step to operate on the SAME image digest, so the SBOM accurately describes what was scanned, and what was scanned is exactly what gets signed.
name: build-sign-publish
on:
push:
branches: [main]
permissions:
contents: read
packages: write
id-token: write # required for cosign keyless (OIDC) signing
env:
IMAGE: ghcr.io/${{ github.repository }}
jobs:
build-scan-sign:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push multi-arch image
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate SBOM with syft
uses: anchore/sbom-action@v0
with:
image: ${{ env.IMAGE }}@${{ steps.build.outputs.digest }}
format: cyclonedx-json
output-file: sbom.cdx.json
- name: Scan image with Trivy
uses: aquasecurity/trivy-action@v0.24.0
with:
image-ref: ${{ env.IMAGE }}@${{ steps.build.outputs.digest }}
severity: CRITICAL
exit-code: '1'
format: table
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Sign image keylessly
run: cosign sign --yes "${IMAGE}@${DIGEST}"
env:
IMAGE: ${{ env.IMAGE }}
DIGEST: ${{ steps.build.outputs.digest }}
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.cdx.json
Why the digest, not the tag, threads through every step
Every downstream step (SBOM generation, scanning, signing) references ${{ steps.build.outputs.digest }}, the immutable content digest the build step itself produced, rather than the mutable :${{ github.sha }} tag; this guarantees the SBOM describes exactly what was scanned and exactly what gets signed, closing the gap a tag-based reference would leave open if the tag were somehow overwritten between steps.
Secure credential handling
Registry authentication uses the automatically-issued GITHUB_TOKEN, scoped to this repository and this workflow run, rather than a long-lived personal access token; cosign signing uses id-token: write permission to obtain a short-lived OIDC (OpenID Connect) token exchanged for a Sigstore certificate, meaning no signing key material is stored as a secret at all.
Verified
Parsed with PyYAML: valid YAML, ten steps confirmed in order, and permissions.id-token confirmed present as write, which cosign's keyless signing requires to obtain its OIDC token from the GitHub Actions runtime. Also checked every third-party action reference against the GitHub API's published tags: docker/setup-qemu-action@v3, docker/setup-buildx-action@v3, docker/login-action@v3, docker/build-push-action@v6, anchore/sbom-action@v0, and sigstore/cosign-installer@v3 all resolve to real tags. aquasecurity/trivy-action@0.24.0 did NOT resolve; the action only publishes v-prefixed tags, so the reference has been corrected to @v0.24.0 above.
Trade-offs
cache-to: type=gha,mode=max speeds up subsequent builds meaningfully but stores build-layer cache in GitHub's own Actions cache, which has its own size limits and retention policy; for a very large image, cache eviction under those limits can occasionally force a slower, cold rebuild, which is an acceptable trade for the typical case where caching saves far more time than it costs.
Explain the difference between Continuous Integration, Continuous Delivery, and Continuous Deployment. Describe an organizational scenario where you would stop at Continuous Delivery (a manual gate before production) rather than go fully automated to Continuous Deployment, and what changes about testing responsibility and release risk in each case.
Sample Answer
Direct answer
Continuous Integration (CI) means every developer's changes are merged and automatically built and tested frequently, so integration problems surface within minutes instead of at the end of a release cycle. Continuous Delivery (CD) extends that by keeping every change that passes CI in a release-ready state, with a deliberate manual gate before it actually reaches production. Continuous Deployment removes that manual gate entirely: anything that passes the pipeline goes to production automatically.
Structured elaboration
CI answers the question 'does this code work when combined with everyone else's code, right now?' It says nothing about whether that code should ship. A team can have excellent CI (fast, reliable builds and tests on every commit) and still ship on a quarterly cadence with a heavyweight manual release process.
Continuous Delivery adds the constraint that the pipeline itself proves every change is deployable, typically by running it through the same automated checks that would run before a real deploy (build, test, package, deploy to a staging environment, run acceptance checks). The distinguishing feature is that a human still decides when to release, usually via a button press or an approval step; the pipeline is not the bottleneck, the release decision is.
Continuous Deployment removes that human decision point. Every change that passes the full automated pipeline is deployed to production without anyone clicking anything. This demands more from your automated test suite and your rollback tooling, because there's no human in the loop to catch something the pipeline missed before it reaches real users.
The practical dividing line is risk tolerance and blast radius. A payments system handling regulated transactions will very often stop at Continuous Delivery: the team wants a human to say 'yes, ship this specific version now' even though the pipeline could push it automatically. A internal tool or a feature-flagged consumer product with strong monitoring and fast automated rollback is a much more natural fit for full Continuous Deployment, because the cost of a bad deploy is lower and the cost of a slow manual release process is comparatively higher.
Worked example
Scenario A: a team has CI (tests run on every PR) but releases manually every two weeks by having an engineer build a release branch, run a manual QA pass, and deploy by hand. This is CI without CD: fast integration feedback, slow and manual release.
Scenario B: a team's pipeline builds, tests, and deploys automatically to staging on every merge to main, then requires a release manager to click 'promote to production' after glancing at a dashboard. This is Continuous Delivery: always release-ready, human decides timing.
Scenario C: a team's pipeline deploys straight to production on every merge to main, behind feature flags, with automated canary analysis deciding whether to complete or roll back the rollout. This is Continuous Deployment: no human in the release-decision loop at all.
The consequence for time-to-recovery: in Scenario A, a bad change can sit in production for up to two weeks before anyone notices through the normal release cycle, and rolling it back means another manual release. In Scenario C, a bad change is caught by automated canary analysis within minutes and rolled back automatically, but only if the automated checks are actually good enough to catch the problem; if they're not, a bad change reaches 100% of production users with nobody having reviewed it first.
Trade-offs and pitfalls
The most common confusion is treating 'Continuous Delivery' and 'Continuous Deployment' as interchangeable; they are not, and the difference (a human gate) is exactly the thing worth naming precisely in an interview. A second pitfall is assuming Continuous Deployment is strictly 'more mature' than Continuous Delivery: for a regulated or safety-critical system, keeping a deliberate human release decision is often the correct engineering choice, not a sign of an immature pipeline. What actually matters is that the choice is deliberate and matched to the system's risk profile, not that the team scored maximum automation.
You need to cut CI pipeline runtime substantially (say by 40-60%) for a large codebase with many tests, without sacrificing confidence in what ships. Propose a prioritized set of concrete optimizations, and for each, describe how you'd measure its impact and verify it hasn't silently reduced test coverage or masked real failures.
Sample Answer
Direct answer
Cutting CI runtime by 40-60% without losing confidence means attacking the pipeline on multiple independent axes at once (caching, parallelism, and running only the tests actually relevant to a change), rather than picking one lever and hoping it's enough, and validating each change actually preserves coverage rather than just making the pipeline faster and quieter.
Structured elaboration
Caching (dependency, build-output, and Docker layer caching, as covered in more depth in the caching-strategy question) typically gives the fastest win for the least implementation effort: it doesn't change what runs, just how much redundant work each run does.
Parallelism splits independent work (different test suites, different services in a monorepo, different shards of a single large test suite) across multiple runners so wall-clock time drops even though total compute time doesn't. The implementation cost is moderate (most CI platforms support matrix/parallel jobs natively) and the main risk is uneven sharding: if one shard consistently takes much longer than the others, you're bottlenecked on the slowest shard, not the average.
Dependency-graph-based incremental builds skip rebuilding and retesting code that a change couldn't possibly have affected, by computing which modules or services are actually impacted by the changed files and running only those. This gives the largest possible speedup for a big codebase, but it's also the riskiest lever: an incomplete dependency graph (missing an implicit dependency, like a shared configuration file or a runtime-only import) can silently skip a test that should have run, which is a correctness regression disguised as a speed win.
Selective/change-based test execution is a lighter-weight version of the same idea, often based on code-coverage mapping (which tests exercise which files) rather than a full build-dependency graph, with a documented fallback (running the full suite on a schedule, or whenever the impact analysis isn't confident) to catch anything the selection heuristic misses.
Remote caches let a machine that's never built or tested a given input before still get a cache hit, because the cache is shared across the whole fleet rather than local to one machine.
Measuring and verifying safety. The measurement plan has two halves. First, the obvious one: track wall-clock pipeline duration (median and p95) before and after each change, attributed per stage so you know which lever actually moved the needle. Second, the safety-critical one: track whether the change reduced the number of tests that actually execute, and specifically watch the post-merge (main-branch) failure rate over the following weeks; if it rises after a selective-testing change ships, that's a strong signal the selection heuristic is skipping something it shouldn't. A useful validation technique is running the full suite in parallel (on a schedule, not blocking anyone) for a period after rolling out selective testing, and diffing which tests the selective approach would have skipped against which tests the full suite actually failed, to catch any gap before trusting the optimization long-term.
Worked example
For a monorepo with 1,000 tests taking 40 minutes: introduce dependency-based test selection (targeting maybe a 50% reduction by running only tests for changed modules), add build/dependency caching (another 15-20% from avoiding redundant installs and recompiles), and shard the remaining full-suite runs (nightly, and PR runs that opt into the full suite) across 8 parallel workers. Track median PR-pipeline duration weekly, and run a shadow full-suite job on a sample of merges for a month to confirm the selective suite isn't silently skipping real failures; only remove the shadow job once that comparison shows zero missed failures over a meaningful sample.
Trade-offs and pitfalls
The single biggest risk across all of these is trading real test coverage for speed without measuring it: a pipeline that runs 5 times faster but silently stops catching the regressions it used to catch has made things worse, not better, and the team usually won't notice until a bug reaches production. The fix is treating 'did this actually preserve coverage' as a first-class metric with the same seriousness as the speed number, not an afterthought.
Compare hosted (SaaS-provided) CI runners against self-hosted runners. Cover cost predictability, security boundaries (network access to internal resources, attack surface), performance (custom hardware such as GPUs, warm caches), and maintenance burden. Then compare ephemeral (single-use, container-based) runners against long-lived VM-based runners on the self-hosted side, and give decision criteria for when you'd choose each combination.
Sample Answer
Direct answer
Hosted (SaaS-provided) CI runners trade cost predictability and low maintenance for less control: you get a managed fleet with no infrastructure to run, but limited access to internal network resources and less customization of hardware. Self-hosted runners flip that trade: more control, network access, and custom hardware (like GPUs), at the cost of you owning the maintenance, security patching, and scaling.
Structured elaboration
Cost predictability. Hosted runners are usually billed per minute of compute used, which is predictable at low-to-moderate volume but can become expensive at high volume, and cost scales linearly with usage with little room to optimize beyond reducing build time itself. Self-hosted runners have a fixed infrastructure cost (owned or reserved hardware) that's more predictable in aggregate but requires capacity planning; you're paying for peak capacity even during quiet periods unless you also build autoscaling.
Security boundaries. Hosted runners are, by design, ephemeral and isolated from your internal network, which is a security feature: a compromised hosted-runner job generally can't pivot into your internal infrastructure. Self-hosted runners, especially if placed inside your internal network for access to private resources (an internal database, an internal artifact registry), need careful isolation, because a compromised job on a self-hosted runner has a much larger potential blast radius.
Performance and custom hardware. Hosted runners typically offer a fixed menu of machine sizes and, on paid tiers, limited GPU options; if your builds need specific hardware (a particular GPU generation, unusually large memory, specialized accelerators), self-hosted is often the only practical option.
Maintenance overhead. Hosted runners require essentially none from you: the platform patches the OS, updates the toolchain images, and handles capacity. Self-hosted runners require you to patch, update, and scale the fleet yourself, which is real ongoing operational work, not a one-time setup cost.
A second, related axis is ephemeral versus long-lived runners, which applies mainly on the self-hosted side (hosted runners are effectively always ephemeral). Ephemeral (single-use, typically container-based) runners are destroyed after each job, which minimizes attack surface (nothing persists between jobs for an attacker to exploit) at the cost of a cold start on every job (no warm dependency or Docker layer cache carried over). Long-lived VM-based runners keep a warm cache between jobs, which is faster, but accumulate state over time (leftover files, drifted configuration) and represent a larger and longer-lived attack surface if compromised.
Worked example
A startup with moderate, spiky CI usage and no need for special hardware is well served by hosted runners: no infrastructure to maintain, and the per-minute cost at their volume is lower than the engineering time it would take to run their own fleet. A company doing GPU-heavy ML training as part of its pipeline, or one whose builds need access to an internal artifact mirror behind a firewall, is pushed toward self-hosted, ideally ephemeral (container-based, torn down after each job) to limit the security exposure of running inside the internal network, with a remote/warm dependency cache layered on top to offset the cold-start cost.
Trade-offs and pitfalls
The most common mistake is choosing self-hosted purely to save money on compute without accounting for the ongoing engineering time to patch, scale, and secure the fleet, which often costs more in practice than the hosted-runner bill it was meant to avoid. The second is running self-hosted runners as long-lived, un-isolated machines for convenience (faster warm builds) without recognizing that a compromised job on a long-lived runner has much more to steal (persisted credentials, cached artifacts from other jobs) than one on an ephemeral runner.
Walk through the stages of a typical CI/CD pipeline for a service, from a developer's commit to a production deployment. For each stage you name, explain what it checks, whether it runs on every pull request or only on merge to main, and how you'd decide the runtime budget for it.
Sample Answer
Direct answer
A typical CI/CD pipeline moves a change through five kinds of work: verify the code compiles and passes fast checks, verify it behaves correctly in isolation, verify it behaves correctly with its dependencies, package it into something deployable, and move that package safely into production. Concretely: checkout, build, static analysis, unit tests, integration tests, artifact publish, deploy, smoke test. Which of these run on every pull request versus only on merge to main is a deliberate trade-off between fast feedback and thoroughness.
Structured elaboration
Checkout and build. Pulls the commit, resolves dependencies, and compiles or bundles the code. This always runs on every PR and every merge; if it fails, nothing downstream is worth running. Budget: seconds to a couple of minutes for most services.
Static analysis (lint, type-check, and any fast security linting). Cheap and deterministic, so it runs on every PR alongside the build. It catches an entire class of bugs (unused variables, obvious type errors, banned patterns) before a human or a slower test even looks at the change.
Unit tests. Exercise a function or module in isolation, with dependencies mocked or stubbed. These run on every PR because they're fast (seconds to low minutes for a healthy suite) and directly test the code the author just wrote.
Integration tests. Exercise the service against real or near-real dependencies (a real database, a real message queue, or a called service). These are slower and flakier than unit tests, so many teams run a fast subset on every PR and the full suite on merge to main or on a schedule.
Artifact publish. Package the build output (a container image, a JAR, a wheel) and push it to a registry with an immutable identifier. This typically only happens on merge to main or on a tag, not on every PR, because you don't want to publish a candidate for every work-in-progress commit.
Deploy and smoke test. Deploy the published artifact to an environment and run a small number of fast checks against the live service (does it start, does the health endpoint return 200, can it serve one representative request) before declaring the deploy successful. This runs after publish, gated by whatever approval policy the target environment requires.
Deciding the runtime budget per stage. The real design constraint is total pipeline latency on the PR path, because that's what blocks a developer. A common target is keeping the PR-blocking stages (build, lint, unit tests, and a fast integration-test subset) under 10 minutes combined, and pushing anything slower (full integration suite, load tests, security scans that take longer) to run on merge or nightly instead of on every PR. If a stage regularly exceeds its budget, that's a signal to parallelize it, cache more aggressively, or move it later in the pipeline rather than let it silently erode developer feedback speed.
Worked example
A small service's pipeline might budget: checkout+build 90s, lint+unit tests 60s (run in parallel with build where the toolchain allows), a fast integration-test subset (only tests touching changed files) 3 minutes, giving a PR-blocking total of roughly 5 minutes. On merge to main, add: full integration suite 12 minutes, artifact publish 1 minute, deploy to staging 2 minutes, smoke tests 30s. The PR path optimizes for developer feedback speed; the merge path optimizes for release confidence, and it's acceptable for it to take longer because it doesn't block anyone's next commit.
Trade-offs and pitfalls
The most common mistake is running the full test suite (including slow integration and end-to-end tests) on every PR: it maximizes confidence per commit but destroys feedback speed, and teams end up merging on red or batching PRs to avoid the wait, which defeats the purpose of continuous integration. The opposite mistake, running almost nothing on PR and deferring everything to merge, means breakages are discovered after they've already landed on main, which is more expensive to fix than catching them before merge. The healthy middle ground is a small, fast, high-signal PR gate and a slower, more thorough merge/nightly gate, with the two suites kept in sync so a PR-passing change doesn't routinely fail on merge for reasons the PR gate could have caught cheaply.
Unlock Full Question Bank
Get access to all 15 CI/CD Pipeline Design and Architecture interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.