CI/CD & Deployment interview question · Most asked
How would you design CI/CD for a microservices architecture?
Design Asked in DevOps Engineer · Site Reliability Engineer (SRE) · QA Engineer / SDET interviews
Summary
Each service gets its own pipeline that builds, tests and deploys independently. Shared libraries are versioned and published as packages, not built inline. Integration testing happens in a shared staging environment or with contract tests.
Longer Answer
Per-service pipelines: Each microservice has its own repository (or directory in a monorepo) with its own pipeline. The pipeline triggers only when that service's code changes, builds its container image, runs its unit and integration tests, and deploys it independently. Services can ship at different cadences without waiting for each other.
Shared code: Common libraries (auth clients, logging, proto definitions) are published as versioned packages (npm, PyPI, Maven). Each service pins the version it uses. Avoid building shared code inline — it creates hidden coupling between pipelines.
Testing strategy:
| Level | Scope | Where it runs |
|---|---|---|
| Unit tests | Single service, mocked dependencies | Service pipeline |
| Contract tests (Pact, Specmatic) | API compatibility between consumer and provider | Both service pipelines |
| Integration tests | Service + its real database | Service pipeline with Testcontainers |
| End-to-end tests | Multiple services together | Shared staging environment, run after deploy |
Contract tests are the key: they verify that service A's expectations of service B's API are still met, without deploying both services together.
Deployment:
- Each service deploys to its own Kubernetes Deployment or ECS service.
- Use rolling updates or canary deployments per service.
- Feature flags decouple deployment from release — ship code dark, enable when ready.
- A shared API gateway or service mesh handles routing and observability.
Challenges:
- Coordinated changes across services: use expand-and-contract (make the new API backwards-compatible, deploy the provider first, then the consumer, then remove the old API).
- Environment parity: staging must reflect production's service topology, or integration tests are meaningless.
Key Points
- Each service has its own pipeline that builds, tests and deploys independently
- Shared libraries are versioned packages, not inline builds
- Contract tests verify API compatibility without deploying services together
- Expand-and-contract handles coordinated changes across services
Explanation
What interviewers look for
Look for independence as the core principle. Weak answers describe one pipeline that builds everything. Strong answers explain contract testing, independent deployment and how to handle cross-service changes.
More CI/CD & Deployment questions
- How do you promote a single build artifact from development through staging to production?
- What stages does a typical CI/CD pipeline contain?
- How do you handle flaky tests in CI?
- What is shift-left testing, and what security scanning belongs in a CI pipeline?
- What's the difference between continuous integration, continuous delivery and continuous deployment?
- What are best practices for writing Dockerfiles?
- Compare rolling, blue-green and canary deployments.
- How do you run database migrations without downtime?