Interview Prep/DevOps Fundamentals/Real-world scenarios

How would you set up CI/CD for a brand-new microservice from scratch?

IntermediateScenarioReal-world scenarios
Answer

In one line: Start with source control and a Dockerfile, build a CI pipeline that tests, scans and produces a versioned image, then add automated deployment to environments with Infrastructure as Code, monitoring and safe rollouts.

Step 1 — Foundations

  • Git repository with branch protection on main (PR reviews + required checks), and a CODEOWNERS file.
  • A production-ready Dockerfile (multi-stage, non-root, small base image) and .dockerignore.
  • Health endpoints (/health/live, /health/ready) and structured logs.

Step 2 — CI pipeline (on pull requests)

  1. Build and unit tests.
  2. Lint and static analysis (SonarQube/Semgrep).
  3. Secret scan (Gitleaks) and dependency scan (Trivy/Snyk).
  4. Build the Docker image (and scan it).
  5. Report results on the PR; block merge on failure.

Step 3 — Release pipeline (on merge to main)

  1. Build the image tagged with the commit SHA / version; scan, sign (Cosign), generate an SBOM.
  2. Push to the registry (ECR/ACR/GHCR).
  3. Update the deployment config (Helm values or Kustomize) for the dev environment.

Step 4 — Infrastructure and deployment

  • Infrastructure (database, queues, IAM roles, DNS) in Terraform, applied through its own pipeline.
  • Kubernetes manifests as a Helm chart with values per environment, resource requests/limits, probes, HPA and a PodDisruptionBudget.
  • GitOps with Argo CD: dev auto-syncs; staging and production are promoted by PR (or with an approval).
  • Secrets via External Secrets Operator from the cloud secret manager.

Step 5 — Safe production releases

  • Canary or blue/green with Argo Rollouts, automatic analysis on error rate and latency, and automatic rollback.
  • Smoke tests after each deployment.

Step 6 — Observability

  • Metrics (Prometheus), logs (Loki/ELK), traces (OpenTelemetry → Tempo/Jaeger).
  • A dashboard with the golden signals, SLO-based alerts with runbooks.

Step 7 — Make it reusable

  • Turn the pipeline and chart into templates (reusable workflows, shared libraries, a Backstage template), so the next service takes minutes, not days.

Tip for interviews: present it in this order — repo → CI → artifact → infra → deploy → release safety → monitoring → templates. It shows end-to-end thinking.

All DevOps Fundamentals questions

More on Real-world scenarios