Tech Interview RoomStudy guides

CI/CD

Design a CI/CD pipeline for a Spring Boot microservice. What stages does it have and why?

Intermediate · 2 min read · Lesson 1 of 6 in CI/CD

Principles

  • Build once, deploy many: one immutable artifact (container image tagged with the commit SHA) is promoted through environments; only configuration changes.
  • Fast feedback: the commit stage should finish in under about 10 minutes; slower suites run later or in parallel.
  • Everything as code: pipeline, infrastructure (Terraform), deployment manifests (Helm/Kustomize).
  • Trunk-based development with short-lived branches and pull requests; main is always releasable.

Stages

  1. Pull request / commit stage: compile, unit tests, static analysis (Checkstyle/SpotBugs/Error Prone, SonarQube quality gate), dependency vulnerability scan (OWASP Dependency-Check, Snyk, GitHub Dependabot), secret scanning. Required to merge.
  2. Build artifact: mvn verify with integration tests (Testcontainers), build the image (Jib, Buildpacks or a multi-stage Dockerfile), scan it (Trivy/Grype), generate an SBOM (Syft/CycloneDX), sign it (cosign), push to the registry tagged with the git SHA.
  3. Deploy to dev/test automatically; run smoke tests and contract tests.
  4. Staging: database migrations (Flyway/Liquibase, backward compatible), end-to-end and performance tests, DAST (OWASP ZAP) where relevant.
  5. Production: progressive delivery (canary or blue-green), automated analysis of error rate and latency, automatic rollback; manual approval only where regulation requires it.
  6. Post-deploy: release markers on dashboards, alerting, change tracking (DORA metrics: deployment frequency, lead time, change failure rate, time to restore).
Developer
Pull request on main
↓trigger
CI
Build and unit testsStatic analysis and SCAIntegration tests with Testcontainers
↓on merge
Package
Build image (Jib)Scan + SBOM + cosign sign
↓push sha-tagged image
Registry
Container registry
↓GitOps promotion
Environments
Dev (auto)Staging (auto + e2e)Production (canary + auto rollback)

Example

yaml
# .github/workflows/ci.yml (simplified)
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with: { distribution: temurin, java-version: 21, cache: maven }
      - run: ./mvnw -B verify                       # unit + integration tests
      - run: ./mvnw -B jib:build -Djib.to.image=$REGISTRY/orders:${{ github.sha }}
      - run: trivy image --exit-code 1 --severity CRITICAL,HIGH $REGISTRY/orders:${{ github.sha }}
      - run: cosign sign --yes $REGISTRY/orders:${{ github.sha }}

Follow-up questions interviewers ask

Try answering each one before you open it.

The pipeline takes 40 minutes. How do you speed it up?

Measure each stage first. Then: cache dependencies (Maven repo, Docker layers, Gradle build cache), run test suites in parallel and shard them, run only affected modules in a monorepo, move slow end-to-end suites out of the merge path into a post-merge or nightly stage, reuse Testcontainers, use bigger or self-hosted runners, and fix or quarantine flaky tests that cause reruns.

Trunk-based development or Gitflow?

Trunk-based development (small changes merged to main daily, behind feature flags if incomplete) minimises merge conflicts and enables continuous delivery, and is what high-performing teams in the DORA research use. Gitflow's long-lived develop and release branches suit products with versioned releases maintained in parallel (installed software, libraries), but slow down feedback for continuously deployed services.