CI/CD for Microservices
Per-service pipelines: build, test, scan, containerize, and progressively deploy with rollback.
One service, one pipeline
Independent deployability requires independent pipelines. Each service builds, tests, and deploys on its own cadence — no release trains, no shared freeze calendars. The pipeline is the paved road: fast (<10 min to a deployable image), fully automated, and trusted enough that green means shippable.
Testing without the world
You cannot spin up 40 services to test one. The microservice test pyramid leans on:
- Unit tests — fast, isolated, the bulk of coverage.
- Integration tests — the service against real DB/broker via testcontainers.
- Contract tests (Pact) — consumer defines expectations; provider verifies them in CI. Catches breaking API changes without end-to-end environments.
- A thin layer of smoke/E2E tests on staging for critical journeys only.
Progressive delivery
Deploying is not flipping 100% of traffic. Strategies in increasing sophistication:
- Rolling update — replace pods gradually (Kubernetes default).
- Blue/green — run old and new side by side; switch traffic atomically; instant rollback.
- Canary — route 1% → 10% → 50% → 100% to the new version, watching error rate and latency at each step; auto-rollback on regression (Argo Rollouts, Flagger).
- Feature flags — decouple deploy from release entirely: ship dark, enable per cohort.
GitOps
In GitOps, a git repo holds the desired state of every environment (manifests/Helm values), and an in-cluster agent (Argo CD, Flux) continuously syncs the cluster to match. Deploys become pull requests: reviewed, audited, and revertible with git revert.
name: order-service-ci
on:
push:
paths: ["services/order/**"] # only this service's changes
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test
working-directory: services/order
- run: |
docker build -t $REG/order-service:$GITHUB_SHA services/order
docker push $REG/order-service:$GITHUB_SHA
- name: Update GitOps repo
run: ./scripts/bump-image.sh order-service $GITHUB_SHA # PR to env repoKey takeaways
- Every service owns an independent, fast, fully automated pipeline.
- Contract tests replace mass end-to-end environments for API compatibility.
- Canary + automated rollback turns deploys from events into non-events.
- GitOps: git is the source of truth; agents reconcile clusters; deploys are PRs.
Knowledge check
What do consumer-driven contract tests verify?
What distinguishes a canary deployment?
In GitOps, how does a production deploy happen?