Video in progress

Which API changes are backward compatible, and which break clients?

Adding a new optional field or a new endpoint is usually backward compatible. Removing a field, renaming it or changing its type, or making an optional field required breaks old clients.

📖 Answer

Backward compatible changes:

  • adding a new field to a response;
  • adding a new endpoint;
  • a new optional request parameter (with a default value);
  • relaxing validation.

Breaking changes:

  • removing or renaming a field (userName -> username);
  • changing a type ("price": "10.50" -> "price": 10.50);
  • requiring a new mandatory field;
  • adding a new value to an enum: an old client that doesn't know it may crash;
  • changing error codes or semantics.

There's a rule on the client side too: tolerate unknown fields. In Spring Boot, Jackson has FAIL_ON_UNKNOWN_PROPERTIES turned off by default, so a new field doesn't cause an error. But if you create an ObjectMapper by hand with new ObjectMapper(), that setting is on, and deserialization fails as soon as a new field arrives.

If you need to remove a field: first announce it as deprecated, wait for clients to move, then remove it.