Skip to content

    System Design

    CI/CD Pipelines and Release Strategy for Back-End Services

    Design a back-end pipeline: verify each change, build one immutable artifact, promote it by digest, gate production, migrate databases safely, measure delivery.

    By Published 12 min read

    Share

    Standard lessonintermediateBackend System Design

    Before this: Docker and Containers

    What you'll learn: By the end of this lesson you will be able to separate continuous integration, continuous delivery and continuous deployment, lay out the stages of a back-end pipeline, explain why a service is built once and the same immutable artifact promoted, gate production with environments and approvals, keep deploys from racing each other, ship database changes that work with old and new code, protect the pipeline's credentials, and measure whether the pipeline is helping.

    Think of airport baggage. A bag is checked in once, scanned at each checkpoint, and the same bag, not a repacked copy, is loaded on the plane. If a scan fails the bag is stopped at that point, and everyone can see where it stopped. A pipeline is that conveyor for code: the thing that passed the checks is the thing that reaches production, and a failure stops at a named stage.

    This lesson assumes containers, covered in the Docker lesson. Where the pipeline ends, the strategies for exposing a release to users (rolling, blue-green and canary releases, and feature flags) have their own lessons: the deployment strategies lesson and the feature flags lesson, named here in plain text because they are written alongside this one. Infrastructure that the pipeline may change is the subject of the Terraform lesson.

    Verified on 2026-12-01 against the GitHub Actions, Docker, Spring Boot and Kubernetes documentation, the Twelve-Factor App, the DORA site and articles by Martin Fowler. No workflow was run: there is no CI service, registry or cluster here, so every pipeline file below is shown as not run.

    The core idea

    A pipeline is an automated path from a commit to production that proves, at each stage, that the change is safe to go further, and that moves one immutable artifact the whole way. Three terms are often blurred.

    • Continuous integration (CI). Fowler's article lists the practices: one shared mainline, an automated build that is self-testing, everyone committing to the mainline every day, fixing a broken build immediately (its wording is that nobody has a higher priority), and keeping the build fast, with a ten-minute build described as "perfectly within reason".
    • Continuous delivery (CD). Software is built so it "can be released to production at any time". The deployment pipeline moves executables through "increasingly production-like environments".
    • Continuous deployment. Every change that passes the pipeline goes to production automatically. Fowler notes it requires continuous delivery first; delivery does not require deploying every change.

    Three illustrations run through the lesson, each labelled:

    • Minimal example: a verify-and-package workflow for one service.
    • Realistic example: the ShopStream order service with a gated production deploy.
    • Failure example: a mutable tag that tested one image and shipped another.

    The stages

    A back-end pipeline from commit to productionPull request to Verify (on every change); Verify to Registry (publish once); Registry to Staging (deploy); Staging to Approval (checks pass); Approval to Production (promote); Registry to Production (same digest)Pull request: commitPull requestcommitVerify: build, test, scanVerifybuild, test, scanRegistry: image by digestRegistryimage by digestStaging: same imageStagingsame imageApproval: gateApprovalgateProduction: same imageProductionsame imageon every changepublish oncedeploychecks passpromotesame digest

    Figure 1. The conveyor. How to read this: the change is verified, one image is published, and that same image is deployed to staging and then production. The dashed line is the point: production receives the artifact that was tested, not a new build.

    A typical back-end pipeline has these stages, in order, and stops at the first failure:

    1. Verify: format and static checks, compile, unit tests. Fast, on every pull request.
    2. Package: build the container image once, tag it with the commit identifier, push it, and record its digest.
    3. Integration checks: tests that need a real database or message broker, against the packaged image.
    4. Deploy to staging and run smoke and contract checks.
    5. Gate: an approval, or an automatic rule.
    6. Deploy to production, wait until the new version reports healthy, and verify.

    In a workflow engine each stage is a job and the order comes from dependencies. In GitHub Actions, needs runs jobs sequentially, and if a needed job fails or is skipped, the jobs that need it are skipped.

    Illustration 1: the minimal example

    A workflow that verifies every pull request and packages on the main branch. Permissions are read-only, and the action reference is a placeholder because the documentation recommends pinning an action to a commit SHA. Not run:

    name: verify
    on:
      pull_request:
      push:
        branches: [main]
    permissions:
      contents: read
    jobs:
      verify:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@FULL_COMMIT_SHA_OF_A_RELEASE
          # a Java setup step is omitted here for brevity
          - run: ./gradlew check

    Two details matter. Setting any scope under permissions sets every unlisted scope to none, so the token starts with only what you grant; the hardening guide advises making the default read-only for repository contents. And on: pull_request runs the verify job before merge, which is what keeps the mainline green.

    Build once, promote by digest

    The Twelve-Factor App separates build (code at a commit becomes an executable bundle), release (the build combined with a deploy's configuration) and run. It says a release is immutable, "an append-only ledger", every release should have a unique ID, and rolling back means running an earlier release. For a container service that means: build the image once, give configuration to it at deploy time through environment, and promote the same image.

    An image tag can be moved to different content later. A digest is the content-addressable identifier and "takes the place of the tag when pulling an image", so a digest-pinned reference always means the same bytes. The Docker documentation notes the cost: a digest does not pick up updated base images, so you must change it yourself.

    sequenceDiagram accTitle: One image promoted by digest through environments accDescr: The CI job builds the image once and pushes it, receiving a digest. It deploys that digest to staging and runs checks. After approval it deploys the same digest to production with production configuration. Rollback deploys the previous digest. participant CI as CI job participant R as Registry participant S as Staging participant P as Production CI->>R: push image, receive digest CI->>S: deploy that digest with staging config S-->>CI: smoke checks pass Note over CI: approval gate CI->>P: deploy the same digest with production config Note over P: rollback = deploy the previous digest

    Figure 2. Promotion. How to read this: the digest never changes along the path; only the configuration does. Because every release is a digest, a rollback is a deploy of an earlier digest, not a rebuild.

    Illustration 2: the realistic example

    For the ShopStream order service (the project's grocery marketplace), a deploy job reads the digest produced by the package job, waits for the production environment's rules, and serialises deploys. Not run:

      deploy-production:
        needs: [package, staging-checks]
        runs-on: ubuntu-latest
        environment: production
        concurrency:
          group: deploy-production
          cancel-in-progress: false
        steps:
          # ./deploy.sh is this team's own script: set the image reference to the
          # digest, then wait until the new version reports healthy
          - run: ./deploy.sh production "$IMAGE_DIGEST"
            env:
              IMAGE_DIGEST: ${{ needs.package.outputs.digest }}

    The environment line makes the job wait: all deployment protection rules must pass before the job is sent to a runner. An environment can require reviewers (up to six, one of whom must approve), add a wait timer and limit which branches and tags may deploy; its secrets are available only after the rules pass. Environments are available on private repositories only on paid plans, per the documentation, so check your plan.

    A concurrency group allows at most one running job or workflow in the group at a time. By default a newer pending run replaces an older pending one, and cancel-in-progress: true also cancels the run already in progress. For a deploy that is often unsafe, because it can stop a rollout halfway; this example leaves it false. What the deploy script must wait for is a service-specific signal; Kubernetes, for example, offers kubectl rollout status for a Deployment, whose manual page shows it reporting when "successfully rolled out".

    Changing the database without breaking the old version

    During a deploy, old and new versions of the service run at once, against one database. A migration that only the new code understands breaks the old pods. The pattern is parallel change, also called expand and contract: expand by adding the new structure beside the old so both work, migrate the clients, then contract by removing the old one once nothing uses it. Fowler notes that if the last phase is skipped you can end up worse than you started, so it must be finished on purpose.

    sequenceDiagram accTitle: Expand and contract across three releases accDescr: Release one adds a new column and keeps writing the old one, so both old and new code work. Release two switches reads and writes to the new column. Release three removes the old column once no running version uses it. participant R1 as Release 1 expand participant R2 as Release 2 migrate participant R3 as Release 3 contract R1->>R1: add new column, old code unaffected R2->>R2: code writes both, then reads the new column R3->>R3: drop the old column after no old version runs

    Figure 3. Three releases for one schema change. How to read this: each release is safe to deploy and to roll back on its own. The destructive step comes last and alone. The mechanics of online migrations are in the schema evolution lesson.

    With Flyway, Spring Boot documents that migrations are scripts of the form V<VERSION>__<NAME>.sql, in classpath:db/migration by default, run by Flyway.migrate() at startup. A pipeline can instead run migrations as a separate step before the deploy; whichever you choose, the rule above still applies.

    Trust: what the pipeline can reach

    A pipeline holds the keys to production.

    • No stored cloud keys. With OpenID Connect, GitHub issues a token for the job, and the cloud provider checks its claims, such as the repository and environment in sub, against a trust definition on a role. The page says this means you do not need to duplicate cloud credentials as long-lived GitHub secrets, and the access token is valid for a single job.
    • Least privilege. Read-only token by default, raised per job.
    • Pin third-party actions to a full commit SHA; a tag can move.
    • Untrusted input is data. The hardening guide's preferred fix for injection is to put an expression into an intermediate environment variable rather than into the script text.
    • Secrets are separate values. Do not store a JSON or YAML blob as one secret, and do not rely on log redaction.
    • Self-hosted runners should almost never be used for public repositories.
    A pipeline job obtains short-lived access instead of a stored keyDeploy job to OIDC token (request token); OIDC token to Cloud role (present claims); Deploy job to Cloud role (ask for access); Cloud role to Production resources (short-lived access)Deploy job: environment: productionDeploy jobenvironment:productionOIDC token: claims: repo, environmentOIDC tokenclaims: repo,environmentCloud role: trust conditionsCloud roletrust conditionsProduction resourcesProductionresourcesrequest tokenpresent claimsask for accessshort-lived access

    Figure 4. Federated access. How to read this: no long-lived key is stored. The role grants access only if the token's claims match the conditions set on it, such as the repository and the production environment.

    Illustration 3: a failure

    Staging was tested with order-service:latest. Before the production deploy another build overwrote that tag, and production pulled different content. The tag was never a promise about content; the digest was. Not run: the fix is to deploy order-service@sha256: followed by the digest the package job recorded, and to fail the deploy if the reference has no digest.

    Release strategy and measurement

    A pipeline moves code to an environment; release is exposing it to users, and the two can be separated with feature flags and gradual rollouts. Doing so keeps deploys frequent and small. To tell whether the pipeline helps, the DORA site defines five metrics: three for throughput (change lead time, deployment frequency, failed deployment recovery time) and two for instability (change fail rate, deployment rework rate). Track both groups; speed alone can rise while stability falls.

    The other side of this topic

    The front-end view is in the front-end CI/CD lesson, which covers static assets, CDN ordering and cache effects, and in a lesson on shipping front-end changes with the back end. A back-end service has no CDN to order, but it has a database that front-end output does not.

    Trade-offs

    Choice Gain Cost
    Build once, promote the digest What was tested ships; cheap rollback Config must be runtime, not build-time
    Run every check on every change Early, complete feedback Slow pipelines; Fowler's ten-minute guide is a target
    Required approval on production A human checkpoint Slower releases; rubber-stamping
    Continuous deployment Small, frequent changes Needs strong tests and flags
    Cancel superseded runs Less wasted compute Cancelling a deploy mid-rollout is dangerous
    Pin actions to a SHA A tag cannot change under you Updates are manual
    Expand and contract Safe, reversible migrations Several releases for one change

    Build it

    This lesson has no lab: a CI service, a registry and a cluster are not available here, and a simulation would restate the documentation. The workflow files above are not run; treat them as outlines to test in a scratch repository.

    In practice: the ShopStream order service

    This is a realistic scenario, not a case history.

    The situation

    ShopStream's order service is deployed by a developer running a script from a laptop, about once a week, with a written checklist. Releases are large, and a bad one takes an afternoon to undo. All numbers are illustrative.

    Starting architecture

    A laptop script builds an image, pushes it with a latest tag and restarts the service. Staging and production are built separately.

    Options considered

    Option Gain Cost Wrong when
    A. Keep the script, add a checklist No tooling Human steps drift Releases must be frequent
    B. Pipeline: verify on PR, build once, promote digest, approval for production Repeatable, auditable Pipeline to maintain The tests cannot be trusted yet
    C. Deploy every merge automatically Smallest changes Needs flags and fast rollback Migrations are not expand and contract

    The decision

    Option B first, moving toward C. Verify on every pull request, one image per merge, digests in the registry, a staging deploy with smoke checks, and a production environment with a required reviewer and a serialised deploy job. Cloud access comes from OIDC, not stored keys. Migrations follow expand and contract.

    Rollout and verification

    Run the pipeline beside the old script for two weeks, deploying only to staging. Compare the image digests the pipeline records with what the cluster runs. Practise a rollback by deploying an earlier digest before the first production release.

    The 2 a.m. failure

    A release drops a column in the same deploy that stops using it. Mid-rollout, old instances still read it and fail.

    sequenceDiagram accTitle: A destructive migration overlaps with old instances accDescr: A deploy runs a migration that drops a column and starts replacing old instances with new ones. While old instances are still serving traffic they query the dropped column and return errors, so the error rate rises until the rollout completes or is rolled back. participant D as Deploy participant DB as Database participant O as Old instances participant N as New instances D->>DB: migration drops column D->>N: start new version O->>DB: read dropped column DB-->>O: error Note over O: errors until old instances are gone

    First checks: the deploy's migration step, then the error messages from the old instances. Mitigation: roll back the service to the previous digest, then restore the column in a migration, because rolling the code back does not roll the database back. Follow-up: split the change into expand, migrate and contract releases and add a review rule that a migration may not remove what the running version reads.

    Architect's notes

    • Make the pipeline the only road to production. Anything else is drift.
    • Fast first, slow later. Put the cheap checks at the front; a ten-minute commit build is the target Fowler cites.
    • Treat a migration as a release of its own.
    • Practise rollback before you need it.
    • Review the pipeline like code: permissions, pinned actions, environment rules.

    Common mistakes

    • Rebuilding per environment, so production runs untested bytes.
    • Deploying by mutable tag rather than digest.
    • Cancelling in-progress deploys with a blanket concurrency setting.
    • A destructive migration in the same release as the code change.
    • Long-lived cloud keys in secrets when federated access is available.
    • Measuring only deployment frequency, ignoring change fail rate.

    Key takeaways

    • CI integrates often with a self-testing build; CD keeps software releasable; continuous deployment ships every passing change.
    • Build once, deploy the same digest everywhere, and vary only configuration.
    • Gate production with environments, serialise deploys and keep rollbacks one deploy away.
    • Old and new versions overlap, so schema changes use expand and contract.
    • Give the pipeline short-lived, least-privilege access and treat inputs as data.
    • Track throughput and stability metrics together.

    Practice exercises

    Exercise 1 (30 min). Write the stages for a service you know as a numbered list, stating for each what failure stops the pipeline and who sees it.

    Exercise 2 (45 min). Take a column rename in the ShopStream order table and plan the three releases of expand and contract, saying what is safe to roll back at each.

    Exercise 3 (45 min). Review a workflow file for permissions, unpinned actions, mutable tags and untrusted input in run steps.

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments