Continuous integration and delivery pipelines
FTGO's teams change dozens of services every day, and each change must reach production without breaking anyone else's work. This chapter builds the path from commit to production: continuous integration, build pipelines, artifacts you build once, and a code layout that maps cleanly to builds.
key idea / coordinator service / good path in progress / watch out problem / failure neutral
In chapter 20 FTGO decided where each service runs: some as functions, most on the Kubernetes cluster from chapter 19. That left one problem open: whichever platform a service runs on, its code still needs a reliable, repeatable path from a developer's commit to production.
How does a change to Order Service get from a laptop to customers, safely and many times a day? By the end you can tell real CI from owning a CI tool, design a staged pipeline, choose between continuous delivery and continuous deployment, promote one artifact through environments, and pick a repository layout.
Integrating late breaks the build: continuous integration
Three developers work on Order Service. Each keeps changes on their own machine for a week and merges on Friday. The merged code does not compile, and once it does, the tests that call Kitchen Service fail. Nobody knows which of the three changes broke them. The build stays red over the weekend, and Monday starts with untangling it.
The longer changes stay apart, the bigger and riskier the merge. The fix is to integrate all the time, and to let a machine check every integration.
Every developer merges to the shared mainline often. On each commit, a CI server checks the code out, compiles it, runs static checks and tests, and, if all is well, builds an artifact (a deployable package, such as a container image) and stores it for later stages.
Because the build is a versioned script, anyone can rebuild an artifact, and every deployed artifact can be traced back to the exact code that produced it.
Owning a CI tool is not the same as doing CI. Jez Humble's three questions are a quick test:
CI asks for discipline: tests worth trusting, and a team that drops other work when the build turns red. It also asks everyone to merge daily, which collides with how many teams use branches.
Long-lived branches hide the conflicts: trunk-based development
A CI server that builds a branch nobody else sees is not integrating anything.
The Order Service team builds the new "scheduled orders" feature on a branch. The CI server builds the branch on every commit and it stays green. After five weeks the branch is merged, and it conflicts with dozens of changes made on the mainline in the meantime. The merge takes days, and the feature ships late.
Everyone commits to one trunk, in small changes, at least daily. Branches, if used at all, live less than a day. Unfinished work is merged but hidden behind a feature flag, a switch in configuration that keeps the code path off until it is ready.
Feature flags pay off twice: the same switch later lets you turn the feature on for a few customers first, the progressive delivery from chapter 19.
Half-finished code now sits in the trunk, guarded by flags that must be cleaned up later. And with every commit triggering a full build, the build itself becomes the bottleneck.
One slow build blocks everyone: build pipelines
Daily merges mean many builds a day, so each build has to give its answer fast.
Order Service's CI build runs unit tests, then integration and contract tests, then a load test, all in one step. It takes 50 minutes (an illustrative number). A typo that fails the first unit test is reported only after the whole run. Developers stop waiting for results and merge on top of red builds.
Split the build into stages: fast tests first, slower tests after, deployment last. If an early stage fails, later stages do not run. Each commit becomes a release candidate that moves through the stages, so you can always see how far a version has got.
The test layers from chapter 14 map onto the stages: unit tests in the fast stage, integration, contract and component tests after it, and load tests near the end. Once a pipeline exists, the last step is a choice: does a passing build go to production on its own?
| Term | Meaning |
|---|---|
| Continuous delivery | Every check-in is a release candidate, and you know how production-ready each one is. Deploying stays a human decision. |
| Continuous deployment | Every change that passes the automated checks is deployed with no human step. It builds on continuous delivery. |
Pick a tool that models pipelines directly, including manual stages such as user acceptance testing, instead of bending a plain CI tool into one. Human steps on the path to production are usually the bottleneck worth automating next.
A pipeline is more to build and maintain, and splitting tests into stages means deciding which checks may run late. The stages also have to be automated end to end, or a person running commands by hand becomes the slowest stage.
Manual deploys do not scale: scripting the pipeline
A pipeline on a whiteboard does nothing. Each stage has to be a script that a machine runs.
Order Service passes its tests in CI, but one engineer still deploys it by hand: build the image on a laptop, push it, edit the Kubernetes file, run kubectl. The registry password lives on that laptop. When she is on holiday, Order Service does not ship.
Describe the whole path as a workflow that the CI/CD service runs on every push: test, build the image, publish it to the registry, deploy it to the cluster. Keep settings in environment variables and credentials in the CI service's secret store, never in the repository.
The hands-on FlixTube track (chapter 27) does exactly this with GitHub Actions. A push to main starts the workflow, and plain shell scripts do the work in each step:
Values such as the registry address and the image version come from environment variables, and secrets such as registry credentials live in GitHub secrets. The tool envsubst fills those values into the Kubernetes deployment file before it is piped to kubectl, so one template serves every version.
Failures in a cloud runner are harder to debug than on a laptop, so keep deployment scripts simple, and reproduce an error locally by copying the workflow's environment variables. And the workflow still has to decide what exactly travels from stage to stage, and where each stage runs.
Ship what you tested: build once, promote everywhere
A release candidate passes through several environments on its way to users. What moves between them matters as much as the tests.
Order Service build-123 passes every test in pre-production. The production stage then rebuilds the image from the same commit with production settings baked in. A base image changed overnight, so the rebuilt image pulls a newer library version. Orders start failing in production with a bug that no test ever saw.
Environments also differ in what they offer. Early stages want speed; late stages want realism. A laptop gives the fastest feedback but is least like production. A full copy of production is realistic but slow and costly, so some test environments run only a few services, with fakes for the rest. The balance is a choice you revisit, and it is one reason teams also test in production (chapter 15).
Build the artifact once, at the start of the pipeline, and deploy exactly those bytes to every later environment. Store it in a registry (Artifactory, Nexus or a container registry), and keep everything that differs per environment, such as log levels or database addresses, in external configuration.
Container images make this natural. An image is an immutable snapshot, so tests and security checks run against it stay valid wherever it goes. A container is a running instance of an image; many containers can start from one image. Give each build its own tag and bump it for every deployment, rather than overwriting a tag such as latest.
Configuration must live outside the artifact and be managed per environment (the externalized configuration of chapter 16), and the registry becomes one more system to run. One question is still open: which commits trigger which service's pipeline?
Map code to builds: one repository or many
How FTGO lays out its source code decides which builds a commit starts, and who is blocked when one breaks.
FTGO started with one big repository and one build for every service. A flaky test in Kitchen Service turns the build red, so Order Service's urgent fix cannot ship. Worse, because everything is built and released together, teams start to assume that services deploy together, and quietly lose independent deployability.
There are three common layouts:
Whatever the repository layout, give each service its own build, triggered only by changes to that service's code. Then a red build blocks one team, not all of them.
| Giant repo + one build | One repo per service | Monorepo | |
|---|---|---|---|
| Good | Simplest start | Clear commit-to-build map; per-repo ownership | Atomic commits, fine-grained code reuse, visibility |
| Bad | One red build blocks everyone; encourages deploying together | Cross-repo changes are awkward; shared code needs versioned libraries | Needs tooling (such as Bazel) at scale; blurs ownership |
| A common pick | Rarely used beyond day one | Preferred as you scale | Fine for 10 to 20 developers or very large, tool-rich firms |
Giants such as Google and Microsoft make monorepos work by investing heavily in tooling, and small groups of 10 to 20 developers manage too. Organizations in between tend to struggle. Sam Newman, for one, prefers one repository per microservice at scale: the benefits of reuse and atomic commits do not outweigh awkward cross-service changes and blurred ownership. The small FlixTube app in the hands-on track takes the other route that works: one monorepo, with a separate CD workflow file for each microservice.
Per-service repositories make cross-service changes and shared code harder; a monorepo needs build tooling and ownership rules. Either way, FTGO can now ship each service many times a day. Shipping is not the same as coping with load, though: when Saturday lunch brings ten times the usual orders, the services must scale.
Practices in this chapter
| Practice | Problem it solves | What it costs |
|---|---|---|
| Continuous integration | Late, large merges that break the build and hide who broke it | Daily merges, trusted tests, fixing red builds first |
| Trunk-based development with feature flags | Long-lived branches that conflict when finally merged | Unfinished code in trunk; flags to clean up |
| Build pipeline with stages | Slow all-in-one builds give feedback too late | Pipeline to maintain; choosing which checks run late |
| Continuous delivery / deployment | Not knowing whether a build is releasable; manual release gates | Delivery keeps a human step; deployment needs full trust in tests |
| Scripted CD workflow with external secrets | Manual deploys from one person's laptop | Cloud runs are harder to debug; scripts to keep simple |
| Build once, promote the artifact | Rebuilt artifacts that differ from what was tested | Externalized configuration per environment; a registry to run |
| One build per service (repo per service or monorepo) | One red build blocks every team; services drift into deploying together | Awkward cross-repo changes, or monorepo tooling and ownership rules |
Recap
- Continuous integration means merging to mainline at least daily, with tests that check behavior, and fixing a red build before anything else.
- Short-lived branches or trunk-based development with feature flags keep integration small and frequent.
- A build pipeline runs fast stages before slow ones, so every commit is a release candidate; continuous deployment removes the final human gate.
- Script the whole path to production, with settings in environment variables and credentials in the CI service's secret store.
- Build each artifact once, keep it free of environment-specific settings, and promote the same immutable, tagged image through every environment.
- Give every service its own build; one repository per service suits most growing organizations, and an atomic commit is never an atomic deploy.
Quick check
Show answer
The rebuilt image is not the artifact that was tested: a changed base image or dependency slipped in. Build the image once, store it in a registry, and promote those exact bytes through every environment, varying only external configuration.
Show answer
No. CI means integrating with everyone else's work on the mainline at least daily. A green branch only proves the branch works on its own; the conflicts wait for the merge. Merge small changes to trunk daily and hide unfinished work behind a feature flag.
Show answer
Give each service its own build, triggered only by changes to its own code, either by moving to one repository per service or by mapping each folder of the monorepo to a separate build. Then a red Kitchen build blocks only the Kitchen team.
FTGO can now take any service from commit to production quickly and safely. But production load is not constant: a Saturday lunch rush brings many times the usual orders, and each service and its database must grow to meet it.