Video in progress

Old versions of a mobile app stay in use for years. How do you evolve the backend API without breaking them?

You can't force a mobile client to update, so API changes must be additive only: add a new field, never remove an old one or change its meaning. For a breaking change you need a version, monitoring of old-version traffic, and a minimum-version mechanism.

📖 Answer

On the web, front end and back end deploy together. On mobile, besides today's release, version 4.2 from two years ago is still running on someone's phone. You renamed the price field to priceTiyin, and the app crashed for those users.

The rules I set up in a team:

  1. Additive changes only. A new field is fine. Removing, renaming or changing the type is not. The client must ignore unknown fields (in the ObjectMapper configured by Spring Boot FAIL_ON_UNKNOWN_PROPERTIES is off by default, and it must be the same on the mobile side).

  2. Enums are dangerous. A new status = REFUNDED appears on the server, the old client doesn't know it and crashes while parsing. The client has to handle an "unknown value" case from day one, so write that down as an API rule.

  3. Versioning. For a truly breaking change use /v2/orders or Accept: application/vnd.app.v2+json. Inside there is one piece of domain logic, and only the outer DTOs and mappers differ. Every version costs maintenance, so I keep few of them.

  4. Know who uses what. Send X-App-Version and a platform header with every request, and track traffic by version in metrics. When someone asks "can we turn off v1?" you answer with a number: "0.3% of traffic, mostly releases from 3 years ago".

  5. Forced update. When the app starts, GET /config returns the minimum supported version; if the app is older, it shows an "update" screen. You need this when a security hole turns up too, so it should be in the very first release.

  6. Control from the server. A new feature is switched on with a feature flag and isn't sent to old clients; an approach where the server defines screen contents (server-driven UI) also softens this problem.

And tests: real request/response samples from old client versions sit in CI as contract tests. If someone removes a field, the build goes red, not prod.