Slower builds, faster features: one image for frontend and backend
At a startup, chase how long a feature takes to reach users, not CI minutes; I made our pipeline slower to shorten the first, and would again.
7 min read
In 2023 I made our CI pipeline two to three times slower on purpose. A backend merge used to reach staging in about five minutes; once the frontend build joined it, ten to fifteen. At the time I put it as “one review, one deploy.” The general version is this: at a startup, build minutes are a cost, not the goal. The goal is how long a feature takes from its first pull request to users, and how many people have to coordinate on the way.
Context
At ImpactNexus, a sustainability-reporting SaaS in Berlin, we had a small engineering team and a simple stack: a FastAPI backend with a GraphQL API, a Nuxt frontend generated as static files, Postgres, and Google Cloud Run. When I took over engineering in mid-2023, frontend and backend lived in two repositories with two pipelines. The frontend was hosted on AWS Amplify, with the API’s address as a build setting. The backend’s tests ran in a Cloud Build trigger configured in the cloud console, and migrations were run by hand.
Problem
A feature that touched both the API and the UI meant two pull requests, two reviews and a release order: backend first, then the frontend. Get it wrong and the new page asks the API for a GraphQL field that does not exist yet. I went back through 2023 to see how that played out:
- The order was a race, not a rule. 21 features had backend and frontend pull requests that link to each other. The median gap between the two merges was under three minutes. In 11 of them the frontend went in first or within five minutes of the backend.
- Two reviews, often only one done. 13 of the 21 had both halves reviewed, 5 only one half, and 3 neither.
- The frontend’s types came from whatever API was deployed, not from the backend change it depended on.
None of this shows up on a CI dashboard. Each pipeline could be green while the feature was broken. The cost sat in the gaps between them: waiting, remembering the order, and reviewers seeing half a change.
What I tried
- Fix each pipeline on its own (July–August 2023). The backend got CI in the repository and zero-traffic deploys, promoted only from
main. The frontend got a preview build for every pull request, but each one talked to the same development API, so a change that needed the backend could not be previewed as a whole. Both pipelines got better. The gap between them did not. - Merge the repositories (September 2023), twice. The first attempt went in while frontend work carried on in the old repository, and two weeks later I reverted it. On 28 September I merged again from the latest head of both and switched the deploy the same day.
What worked
There were three ways out, and I picked the one that removed the problem instead of managing it:
| Option | Pros | Cons |
|---|---|---|
| Two repos, every API change backward compatible | Frontend and backend release independently | Every breaking change becomes three releases (expand, switch, contract), and someone tracks them |
| Two repos, one pipeline that deploys both | No repository migration | Two commits to keep in step per feature; a preview still needs two branches |
| One repo, one image | One commit is the whole app: one review, one preview, one rollback | Frontend and backend always release together, and every build includes both |
One image. The build job generates the static frontend, the Docker build copies it into the backend image, and FastAPI serves it next to the API. The frontend calls /graphql on its own origin, so it no longer needs an API address per environment.
One deploy, and a preview of the whole app for every pull request. Every pull request already got a tagged Cloud Run revision with its own URL, posted to the pull request by a bot. Now that revision was the whole app, not just the API. Only main moves traffic:
deploy: needs: [build, test] steps: - run: > gcloud run deploy web --image "$IMAGE:$TAG" --no-traffic --tag "$TAG"
promote: needs: [build, test, deploy] if: github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - run: > gcloud run services update-traffic web --to-tags "$TAG=100"A schema change and the page that uses it became one pull request, one review, one preview and one deploy. Nobody had to remember the order, because there was no order.
What it cost
From August 2023 the pipeline recorded every deploy. This is the time from merging to main until the staging deploy started:
minutes from merge to the staging deploy starting
The frontend build now sat on the path of every deploy, and the time went from about 5 minutes to 13 or 14. I accepted that. Nine more minutes to staging, against a 30-hour lead time per feature, is cheap. A half-reviewed feature is not. Later work won some of it back: pnpm cut the frontend install on my machine from a minute and a half to 16 seconds. Self-hosted runners, tried to save on hosted minutes, made it worse.
Two costs I would name up front next time. A typo fix on a page now redeploys the API. And the frontend’s lint and unit tests, switched off in July 2023 to get the staging build working, never came back into CI.
Did it pay off
The structural part needs no statistics. Before the merge, 8 of the 21 features had a half nobody reviewed. After it, a schema change and its page were one diff: whoever reviewed one reviewed both.
From the first pull request opened to the last one merged (not yet to production; that wait comes next), the 21 two-repository features took a median of 30 hours. After the merge, the 285 pull requests that changed both halves took a median of 24.5. The samples are not identical, so I read that as a direction, not proof. But it is the direction I bet on: a slower pipeline and faster features.
The biggest wait was not in CI at all. Production deploys waited for a human approval. I added that gate on purpose: I had rebuilt the release process and wanted one last check before anything went live. In the worst months, the slowest tenth of merges took up to seven hours to reach production, against about half an hour to reach staging. The gate never got an end date, and that was my miss: once every pull request had a preview, the gate stayed out of habit, not as a safeguard.
What I would do from day one
- Measure lead time per feature: first pull request opened to running in production, across every repository it touches.
- Count human waits apart from machine time. Approvals and reviews hid more delay than any build.
- Give every manual gate an end date. Write down what has to be true to remove it on the day you add it.
- Treat pipeline minutes as a budget, not a goal. Spend them when they buy a shorter path for a feature.
- Run a repository merge as a cutover: pick a day, freeze the old repository, merge from the latest head.
- Check generated types in CI against the schema in the same commit.
A reflection on my time as CTO of ImpactNexus. Drafted with AI from my notes and the project’s history; I proofread it and checked every number.