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 aCODEOWNERSfile. - 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)
- Build and unit tests.
- Lint and static analysis (SonarQube/Semgrep).
- Secret scan (Gitleaks) and dependency scan (Trivy/Snyk).
- Build the Docker image (and scan it).
- Report results on the PR; block merge on failure.
Step 3 — Release pipeline (on merge to main)
- Build the image tagged with the commit SHA / version; scan, sign (Cosign), generate an SBOM.
- Push to the registry (ECR/ACR/GHCR).
- 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.
More on Real-world scenarios
The website is slow. How do you troubleshoot it?IntermediateA deployment to production just failed halfway. What do you do?IntermediateDevelopers complain that the CI pipeline takes 40 minutes. How would you speed it up?IntermediateSomeone accidentally committed an AWS access key to a public GitHub repository. What do you do?IntermediateYour production disk is 95% full and the alert just fired. What do you do?IntermediateYour cloud bill doubled this month. How do you find out why and reduce it?Intermediate