Backend Engineering
Designing an API for apps you cannot update
Mobile apps stay installed for months after a release. Practical rules for API contracts that survive old clients: versioning, additive changes, structured errors, idempotency and pagination.
By Kevin Vavelin, Founder, CodeticsPublished 8 min read
- API design
- OpenAPI
- Mobile
- Backend
- Reliability
When you deploy a new version of a website, every visitor gets it on their next page load. Mobile applications do not work that way. A release goes through store review, then reaches users gradually as their devices update. Some users disable automatic updates; some devices stop receiving OS updates and stay on an old app version for years.
Your backend therefore talks to several generations of the same application at once. The API is not an internal detail between two codebases you control: it is a public contract with clients you cannot fix. Here are the rules we apply when designing one.
Write the contract first, and make it the source of truth
Describe the API in an OpenAPI document before or alongside the implementation, and generate what you can from it: request and response models for Swift and Kotlin, server stubs, documentation and contract tests. A single contract prevents the slow drift where the iOS app, the Android app and the server each hold a slightly different idea of what a field means.
Only make additive changes within a version
Within a major version, treat the following as safe:
- Adding an optional field to a response.
- Adding an optional parameter to a request.
- Adding a new endpoint.
And the following as breaking, requiring a new version:
- Removing or renaming a field, or changing its type.
- Making an optional request field required.
- Changing the meaning of an existing value.
The clients must hold up their side too: they should ignore unknown fields and handle unknown enum values gracefully. In Swift and Kotlin, that means decoding enums with an explicit unknown case rather than failing the whole response when the server introduces a new status.
Version explicitly, and know who is calling
Put the major version in the path (/v1/…) so that it is visible in logs, caches and documentation. Ask clients to send their app version and platform in a header. With that information you can measure how many users are still on an old version before retiring an endpoint, and you can require an update when a version is no longer safe to support.
Return errors the client can act on
A mobile app needs to decide what to show: retry, ask the user to change something, or tell them the action is impossible. A bare 400 or 500 with an English sentence does not allow that. RFC 9457 defines a standard format, Problem Details, with a stable machine-readable type:
HTTP/1.1 409 Conflict
Content-Type: application/problem+json
{
"type": "https://api.example.com/problems/connector-unavailable",
"title": "Connector unavailable",
"status": 409,
"detail": "Connector 2 is already in use.",
"instance": "/v1/sessions"
}The app maps known type values to localized messages and actions, and falls back to a generic message for unknown ones. Human-readable text stays useful for logs and support.
Make retries safe with idempotency keys
Mobile networks drop connections. A request may reach the server, succeed, and the response may still be lost on the way back. If the app retries, the server must not perform the action twice: start a second charging session, create a duplicate order or charge a card again.
The usual solution is an idempotency key: the client generates a unique identifier for each logical operation and sends it with every attempt. The server stores the result of the first successful attempt and returns it again for any retry with the same key.
POST /v1/sessions HTTP/1.1
Idempotency-Key: 4f2c7d1e-8a3b-4c55-9e0f-2b6a1d9c7e31
Content-Type: application/json
{ "stationId": "FR*ABC*E12345", "connectorId": 2 }Paginate with cursors
Offset pagination (?page=3) produces duplicates or gaps when items are inserted while the user scrolls, which is common in activity feeds and histories. Cursor pagination returns an opaque token pointing to the last item seen, so the next page continues exactly where the previous one stopped.
A checklist
| Rule | Why it matters for mobile |
|---|---|
| OpenAPI contract as the source of truth | iOS, Android and server agree on every field |
| Additive changes only within a version | Installed apps keep working |
| Clients ignore unknown fields and enum values | Server can evolve without crashing old apps |
| App version and platform sent in a header | You know when an old version can be retired |
| Problem Details errors | The app can react correctly and in the user's language |
| Idempotency keys on state-changing requests | Retries on unreliable networks are safe |
| Cursor pagination | No duplicates or gaps while scrolling |
These rules cost little when applied from the first endpoint, and a lot when retrofitted onto apps already in users' hands. That is one reason we design the mobile apps and the backend together in our product engineering work.