Most frontend outages caused by APIs are not dramatic. Nobody deletes the database. Someone renames user_name to username, ships it on a Friday, and every customer on an older mobile build sees a blank profile screen.
The backend tests passed. The frontend tests passed. The problem lived in the gap between them: the contract.
We learned most of what follows the hard way, while building an HRMS and a CRM with React and TypeScript. Both apps have dozens of screens reading the same employee and customer records. One careless change to a shared endpoint can break pages nobody thought to retest.
This article covers practical ways to close that gap:
• Which changes are actually breaking (some are less obvious than you'd think)
• Compatibility patterns that let backend and frontend ship independently
• Using OpenAPI as the single source of truth
• Generating TypeScript types and validating responses at runtime
• Contract testing and mock servers
• CI/CD gates that catch breaking changes before they merge
The examples use a REST API with TypeScript on the frontend, but most of the ideas apply to GraphQL and gRPC too.
**What counts as a breaking change?
A change is breaking when a client that worked yesterday can fail today without changing its own code. The direction matters: what is safe in a response is often unsafe in a request, and the other way round.
Change
Response (API → client)
Request (client → API)
Add an optional field
Safe (if clients ignore unknown fields)
Safe
Add a required field
Safe
Breaking
Remove or rename a field
Breaking
Breaking if the API now rejects it
Change a type (number → string)
Breaking
Breaking
Make a field nullable
Breaking
Safe
Make a nullable field non-null
Safe
Breaking
Add an enum value
Often breaking
Safe
Remove an enum value
Safe-ish
Breaking
Change default sort, page size or date format
Behaviourally breaking
n/a
Change an error code or status
Breaking if the UI branches on it
n/a

Two rows surprise people the most.
Nullable fields. Changing avatarUrl: string to avatarUrl: string | null looks harmless on the backend. The field is still there, and the JSON still parses. On the frontend, though, user.avatarUrl.startsWith('https') now throws TypeError: Cannot read properties of null (reading 'startsWith') for every user without an avatar. A single unguarded line like this can blank out a whole profile page or crash a React component tree.
The frontend code was correct for the old contract, and nothing warns anyone that it changed. TypeScript still believes the field is a string, because the hand-written type was never updated. The fix on the client is a guard plus a fallback:
const avatar = user.avatarUrl?.startsWith('https')
? user.avatarUrl
: '/images/default-avatar.png';
The fix on the API side is to treat "can now be null" as a breaking change. Either keep returning a value (an empty string or a default URL) or introduce the nullable field through expand-migrate-contract, covered below.
New enum values. Adding "refunded" to an order status feels additive. But a frontend with an exhaustive switch and no default branch renders nothing, or crashes, for that order.
The last two rows are behavioural breaks. The schema does not change at all, so schema-diff tools miss them. Only tests and communication catch those.
Why this is harder than it looks
If the backend and frontend always deployed together, a breaking change would just be a refactor. In practice they don't, for a few reasons.

  1. Old clients live longer than you think. A web app updates on refresh, but a user can leave a tab open for days. Mobile apps are worse: some users never update. Your API must serve today's code and every version still in the wild.
  2. Deploys are not atomic. Even in a monorepo, the API rolls out pod by pod and the frontend goes through a CDN cache. For a few minutes, new frontend code talks to old API code, and the reverse.
  3. Hand-written types drift. A typical frontend has something like this: // types/user.ts — written by hand six months ago export interface User { id: number; user_name: string; avatarUrl: string; }

const res = await fetch(/api/users/${id});
const user = (await res.json()) as User; // trust me, compiler
That as User is a promise nobody keeps. TypeScript checks your code against the interface, never against the real response. When the API changes, the compiler stays green and the bug ships.

  1. Nobody owns the contract. The backend team owns the server, the frontend team owns the UI, and the shape of the JSON between them belongs to whoever touched it last. The rest of this article tackles these problems one by one: make changes compatible, make the contract explicit, make types come from the contract, and make CI enforce it. Compatibility strategies that actually work Expand, migrate, contract The safest way to make a breaking change is to never make one in a single step. Split it into three releases: 1.Expand: add the new shape next to the old one. Both are served. 2.Migrate: move every client to the new shape. Measure usage of the old one. 3.Contract: remove the old shape once usage reaches zero (or your deprecation deadline passes). Renaming user_name to username looks like this: // Release 1 — expand: both fields present { "id": 42, "user_name": "asha", "username": "asha" }

// Release 2 — frontend switches to username

// Release 3 — contract: old field removed
{ "id": 42, "username": "asha" }
It is slower than a one-line rename. It is also the only version that never pages anyone.
Be a tolerant reader
The frontend has a part to play too. A tolerant reader ignores fields it doesn't know about and handles values it doesn't expect:
function statusLabel(status: string): string {
switch (status) {
case 'pending': return 'Awaiting payment';
case 'paid': return 'Paid';
case 'shipped': return 'On the way';
default:
// New value from the API? Degrade gracefully, and tell someone.
reportUnknownValue('order.status', status);
return 'Processing';
}
}
That default branch turns a crash into a slightly vague label. Pair it with logging so you find out the day it happens, not the day a customer complains.
Version only when you have to
Versioning (/v1/orders, /v2/orders, or a header like Accept: application/vnd.acme.v2+json) is a tool for changes that can't be made additive: a new resource model, a different auth scheme, a redesigned pagination contract.
It is not free. Every live version is code you test, document and patch. A good rule of thumb: prefer additive changes inside a version, and bump the version only for genuine redesigns. Many teams run for years on v1 this way.
Announce deprecations in the response itself
Docs and Slack messages get missed. Headers don't. Mark deprecated endpoints with the Deprecation header (RFC 9745) and a removal date with Sunset (RFC 8594):
HTTP/1.1 200 OK
Deprecation: @1767225600
Sunset: Wed, 30 Jun 2027 23:59:59 GMT
Link: https://api.example.com/docs/migrations/orders-v2; rel="deprecation"
On the frontend, a small fetch wrapper can surface these in development:
export async function apiFetch(input: RequestInfo, init?: RequestInit) {
const res = await fetch(input, init);
if (import.meta.env.DEV && res.headers.has('Deprecation')) {
console.warn(
[api] ${res.url} is deprecated. Sunset: ${res.headers.get('Sunset') ?? 'unknown'}
);
}
return res;
}
On the backend, log every call to a deprecated endpoint with the client version. That log tells you when "contract" is safe.
OpenAPI: make the contract a file, not a feeling
The single biggest improvement most teams can make is to write the contract down in a machine-readable form and keep it in the repo. For REST, that means an OpenAPI spec.

openapi.yaml

openapi: 3.1.0
info:
title: Orders API
version: 1.4.0
paths:
/orders/{id}:
get:
operationId: getOrder
parameters:
- name: id
in: path
required: true
schema: { type: string }
responses:
'200':
description: The order
content:
application/json:
schema: { $ref: '#/components/schemas/Order' }
'404':
description: Not found
components:
schemas:
Order:
type: object
required: [id, status, total]
properties:
id: { type: string }
status: { type: string, enum: [pending, paid, shipped] }
total: { type: number, description: Amount in minor units }
note: { type: [string, 'null'] }
Once the spec exists, it becomes the hub that everything else plugs into:
• Types for the frontend are generated from it (next section).
• Mock servers serve realistic responses from it before the backend is ready.
• Diff tools compare two versions of it and flag breaking changes.
• Linters enforce your API style rules on it.
• Docs render from it, so they can't fall out of date.
Spec-first or code-first?
Both work, as long as the spec is committed and reviewed.
• Spec-first: write the YAML, then implement. Good when the frontend and backend design the API together, because the spec PR is the design review.
• Code-first: generate the spec from annotations or schemas (FastAPI, NestJS, Laravel with Scribe, ASP.NET with Swashbuckle). Good for existing codebases. Commit the generated file, so changes to it show up in code review.
What doesn't work is a spec that is generated at runtime and never committed. If the contract isn't in the diff, nobody reviews it.
Lint the spec
A linter such as Spectral catches problems before they become contracts:

.spectral.yaml

extends: ['spectral:oas']
rules:
operation-operationId: error
oas3-schema: error
no-unbounded-arrays:
description: Arrays must declare maxItems
given: $..[?(@.type == 'array')]
then: { field: maxItems, function: truthy }
severity: warn
npx @stoplight/spectral-cli lint openapi.yaml
TypeScript: generate the types, then verify them at runtime
Stop hand-writing API types
With a spec in place, generate types from it instead of maintaining them by hand. openapi-typescript is a lightweight option:
npm i -D openapi-typescript
npm i openapi-fetch
npx openapi-typescript ./openapi.yaml -o ./src/api/schema.d.ts
Pair it with a typed client and every path, parameter and response is checked by the compiler:
import createClient from 'openapi-fetch';
import type { paths, components } from './api/schema';

export type Order = components['schemas']['Order'];

const api = createClient({ baseUrl: '/api' });

export async function loadOrder(id: string) {
const { data, error } = await api.GET('/orders/{id}', {
params: { path: { id } },
});
if (error) throw new Error('Order not found');
return data; // typed as Order
}
Now the rename from earlier is a compile error, not a production incident. When the backend regenerates the spec without user_name, the frontend build fails on every line that still uses it. You fix them before merging, not after a customer notices.
If you prefer generated hooks or full clients, Orval and OpenAPI Generator produce React Query hooks, Axios clients and more from the same spec.
Let the compiler find unhandled enum values
Generated union types work well with exhaustiveness checks. When a new status is added to the spec and the types are regenerated, this function stops compiling until you handle it:
function assertNever(x: never): never {
throw new Error(Unhandled value: ${x});
}

function badgeColor(status: Order['status']) {
switch (status) {
case 'pending': return 'yellow';
case 'paid': return 'green';
case 'shipped': return 'blue';
default: return assertNever(status); // error if a case is missing
}
}
This protects the next build. Older builds already in users' hands still need the tolerant default branch from earlier, so use both: exhaustive at compile time, forgiving at runtime.
Validate at the boundary
Generated types still describe what the API should return. They cannot stop a misconfigured proxy, a half-deployed backend or a third-party API from returning something else. For responses that matter, validate at runtime with a schema library such as Zod:
import { z } from 'zod';

const OrderSchema = z.object({
id: z.string(),
// Unknown statuses become 'unknown' instead of failing the whole parse
status: z.enum(['pending', 'paid', 'shipped', 'unknown']).catch('unknown'),
total: z.number(),
note: z.string().nullable().optional(),
});

export type ValidOrder = z.infer;

export function parseOrder(json: unknown): ValidOrder {
const result = OrderSchema.safeParse(json);
if (!result.success) {
// Send to Sentry / your logger with the endpoint name
reportContractViolation('GET /orders/{id}', result.error.issues);
throw new Error('Unexpected response from Orders API');
}
return result.data;
}
A few practical notes:
• Don't validate everything. Parsing large lists on every render costs CPU. Focus on critical paths: checkout, auth, anything that writes data.
• Fail loudly in development, softly in production. Throw in dev and CI; in production, log the violation and fall back where it is safe.
• Generate the schemas if you can. Tools like Orval can emit Zod schemas from OpenAPI, so the runtime check and the compile-time types come from the same source.
Testing the contract, not just the code
Unit tests on each side prove that each side works with its own idea of the API. Contract tests prove that the two ideas match. There are three useful layers.

  1. Consumer-driven contract tests (Pact) With Pact, the frontend writes down exactly what it needs from the API. The test runs against a Pact mock server and produces a contract file: import { PactV3, MatchersV3 } from '@pact-foundation/pact'; import { fetchOrder } from '../src/api/orders';

const { like, regex } = MatchersV3;

const provider = new PactV3({ consumer: 'web-app', provider: 'orders-api' });

describe('Orders API contract', () => {
it('returns an order by id', () => {
provider
.given('order 42 exists')
.uponReceiving('a request for order 42')
.withRequest({ method: 'GET', path: '/orders/42' })
.willRespondWith({
status: 200,
headers: { 'Content-Type': 'application/json' },
body: {
id: like('42'),
status: regex('pending|paid|shipped', 'paid'),
total: like(1999),
},
});

return provider.executeTest(async (mockServer) => { const order = await fetchOrder(mockServer.url, '42'); expect(order.total).toBe(1999); }); 

});
});
The backend then replays that contract against the real service in its own pipeline. If someone removes total, the backend build fails, before the change reaches the frontend at all. With a Pact Broker, can-i-deploy answers the question "is this version safe to release against what's live?"
The key idea: the contract only covers fields the frontend actually uses. The backend is free to change everything else.

  1. Schema conformance tests If you have an OpenAPI spec but no Pact setup, test that the real API matches its own spec. Schemathesis generates requests from the spec and checks every response against it: schemathesis run ./openapi.yaml --url https://staging.example.com This catches the classic drift where the code returns null for a field the spec calls required.
  2. Mock servers for frontend development and tests Mocks generated from the spec let the frontend build against a new endpoint before the backend ships it, and keep tests honest because the mocks change when the spec does. • Prism serves a full mock API from the spec: npx @stoplight/prism-cli mock openapi.yaml • MSW intercepts requests in the browser and in Node, which is ideal for component and integration tests. Use mocks to test the unhappy paths too. A good habit is one test per endpoint that returns a value the UI has never seen: import { http, HttpResponse } from 'msw'; import { server } from './mocks/server';

it('renders an order with an unknown status', async () => {
server.use(
http.get('/api/orders/:id', () =>
HttpResponse.json({ id: '42', status: 'refunded', total: 1999 })
)
);

render();
expect(await screen.findByText('Processing')).toBeInTheDocument();
});
That one test is cheap insurance against the "new enum value" outage described at the start.
CI/CD: make breaking changes impossible to merge by accident
Everything above is good practice. CI is what turns it into a rule. A solid pipeline for API changes runs four checks on every pull request that touches the spec:
1.Lint the spec against your style rules.
2.Diff it against the base branch and fail on breaking changes.
3.Regenerate frontend types and run the type checker.
4.Verify consumer contracts against the new backend build.
A GitHub Actions example
oasdiff compares two OpenAPI files and classifies every change. Here it blocks the PR if anything breaking slips in:

.github/workflows/api-contract.yml

name: API contract

on:
pull_request:
paths: ['openapi.yaml']

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npx @stoplight/spectral-cli lint openapi.yaml --fail-severity=error

breaking-changes:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'breaking-change-approved') }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get base spec
run: git show origin/${{ github.base_ref }}:openapi.yaml > base-openapi.yaml
- uses: oasdiff/oasdiff-action/breaking@main
with:
base: base-openapi.yaml
revision: openapi.yaml
fail-on: ERR

frontend-types:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npx openapi-typescript ./openapi.yaml -o ./src/api/schema.d.ts
- run: npx tsc --noEmit
A few details make this work in real teams:
• The escape hatch is explicit. Sometimes a breaking change is intended. Adding the breaking-change-approved label skips the diff gate, so the decision is visible in the PR history instead of hidden in a force-merge.
• The type check is the frontend's vote. If the spec change breaks any frontend code, tsc fails in the backend's PR. In a monorepo this is free; across repos, publish the spec as a package and run the check in the frontend repo on each new version.
• Contract verification runs in the provider pipeline. With Pact, add a job that verifies all consumer contracts against the new build, and run can-i-deploy before each release.
Rolling out safely
CI stops accidents. Deployment order stops the rest.
• Expanding? Ship the backend first. New optional fields and endpoints go live before any frontend code uses them.
• Contracting? Ship the frontend first. Remove usage of the old field, wait until old clients have aged out, then remove it from the API.
• Hide new UI behind a feature flag. The frontend can merge code for an API that isn't live yet, and you turn it on when the backend is ready.
• Watch the right metrics after deploy. Track contract-violation logs from the runtime validation, 4xx rates per endpoint, and frontend error rates by app version. A spike right after an API deploy is a strong signal to roll back.
A checklist for your next API change
Before merging a change to an API that a frontend depends on, run through this list:
• Is the change additive? If not, can it be split into expand, migrate, contract?
• Did any response field become nullable, or gain a new enum value?
• Did defaults change: sort order, page size, date format, error codes?
• Is the OpenAPI spec updated and committed in the same PR?
• Did the breaking-change diff pass, or is the override label justified in the PR?
• Do the regenerated frontend types still compile?
• Are deprecated fields or endpoints marked with Deprecation and Sunset headers?
• Is usage of the old shape being logged, so you know when it's safe to remove?
• Is the deploy order right: backend first to expand, frontend first to contract?
Wrapping up
API changes break frontends when the contract between them is implicit. The fix is not one tool but a chain where each link catches what the previous one missed:
• Compatible design (expand-contract, tolerant readers) avoids most breaks in the first place.
• OpenAPI turns the contract into a reviewable file.
• Generated TypeScript types turn contract changes into compile errors.
• Runtime validation catches what the types can't see.
• Contract tests and mocks prove both sides agree.
You don't need all of it on day one. If you do just one thing this week, commit your OpenAPI spec and add a breaking-change check to CI. It takes about an hour, and it will catch the next user_name rename before it ships.
How does your team handle API changes? I'd love to hear what's worked, or what's burned you, in the comments.