Video in progress

Strong Junior 🧩 Microservices

You want to remove a field in a service's internal API. In what order do you proceed so you don't break the services that use it?

With "expand and contract": first you add the new variant and keep the old one too, verify the clients have moved to the new one (logs, metrics, contract tests), and only then remove the old field. It all happens in several separate deploys.

📖 Answer

Say the customer-service response has fullName and you want to replace it with firstName + lastName.

deploy 1 (expand):   the response has fullName, firstName, lastName, all three
step 2:              client services move to firstName/lastName (at their own pace)
step 3:              find out who is still using fullName
deploy 4 (contract): fullName is removed

Step 3 is the one most often skipped. The server doesn't know on its own who needs a response field, so:

  • contract tests (Spring Cloud Contract or Pact, for example): each client writes down the fields it expects, and the provider's build checks them;
  • a list of clients and notifying their owners;
  • marking the field deprecated: true in OpenAPI.

The same order applies to a request field, only reversed: the server first accepts both the new field and the old one; clients start sending the new one; at the end the server stops accepting the old one.

It's harder with events: messages in the old format stay in the topic until retention runs out. The consumer must be able to read both formats, or the compatibility rule (BACKWARD) must be enabled in Schema Registry.