Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

How do you design for backward compatibility across many services that deploy independently, so that rolling deploys and mixed versions never break calls between them?

We assume that two versions of every service, N and N-1, are always running at the same time, and design every change so that any mix of them works. Providers make only additive changes, consumers are tolerant readers, and anything that would break goes through expand and contract. Consumer-driven contract tests in the provider's pipeline prove it before deploy, and feature flags let a provider ship new behaviour before consumers switch to it.

Why this question is asked

With dozens of services deploying several times a day, there is never a moment when the whole system is on one version. A rolling deploy replaces pods one by one, so for a few minutes old and new pods serve traffic side by side; a rollback puts the old version back; events written yesterday are read by code deployed today. Interviewers ask this at senior level because the answer is a set of design rules a whole organisation must follow, not one trick. In this answer, we will see why mixed versions are unavoidable, then go through tolerant reader and additive changes, expand and contract, contract tests in the pipeline, the N and N-1 rule for APIs and events, and feature flags.

1Why Mixed Versions Are Unavoidable

Picture the orders service calling the payments service. Payments runs six pods and starts a rolling deploy from version 41 to version 42. For the next five minutes, each call from orders lands on a 41 pod or a 42 pod depending on the load balancer. Orders itself may be mid-deploy too, so a 41 caller can meet a 42 provider and the other way round.

Then there is rollback. If version 42 misbehaves, we roll payments back to 41, but callers that already started using a new field from 42 are now talking to a service that does not know it. And with messaging, an event published by version 42 may sit in a Kafka topic for a week and be read by a consumer that has been rolled back. So the rule we design for is not 'deploy in the right order'; it is 'every combination of N and N-1 must work, in any order'.

Step throughA rolling deploy mixes versions on every call
Orders v18Payments v41Payments v42
POST /payments (old shape)
201, response without riskScore
POST /payments (old shape)
201, response with new riskScore
GET /payments/9 (pod not yet replaced)
200, still the old shape

6 messages in order. Play them, or step through them one at a time.

During the deploy, the same caller sees both versions within seconds; both answers must be acceptable.

2Tolerant Readers and Additive-Only Changes

The two halves of the rule fit together. On the provider side, we allow only additive changes inside a version: new optional response fields, new optional request fields, new endpoints, new enum values that the contract says clients must tolerate. We never remove, rename or retype a field, and we never make an optional input required.

On the consumer side, every reader is tolerant: it reads only the fields it needs, ignores unknown fields, maps unknown enum values to a default, and does not depend on field order. In Spring Boot, the auto-configured ObjectMapper already ignores unknown properties; the team rule is to never replace it with a strict one and to give every enum an UNKNOWN fallback. With both halves in place, a 42 provider can send more than a 41 consumer expects, and a 41 provider can send less than a 42 consumer would like, provided the new consumer treats the new field as optional until the provider is fully rolled out.

3Expand and Contract for Every Breaking Change

Sometimes we really do need a breaking change, such as replacing a field or changing an identifier format. We never make it in one step. We expand first: add the new form next to the old, and make the provider understand both. Then we migrate consumers one by one. Only when no consumer uses the old form do we contract and remove it.

The same pattern applies to the database behind the service. A rolling deploy means version 41 and version 42 share the same tables, so a column cannot be renamed in one migration. We add the new column, write to both, backfill, switch reads, and drop the old column in a later release, when no running version reads it any more.

Step throughExpand and contract across independent deploys
  1. Expand the provideradd the new field or column, keep the old, accept both
  2. Deploy and roll out fullyN and N-1 both work
  3. Migrate consumers one by oneeach on its own schedule
  4. Does any consumer or running version still use the old form?
    YesWait and measureNoContract: remove the old form
  5. Contract in a later releaseN-1 no longer needs the old form

5 steps in order. Play them, or step through them one at a time.

4Contract Tests in the Provider's Pipeline

Rules only hold if a machine checks them. Consumer-driven contract tests do that. Each consumer writes down the interactions it depends on: the request it sends and the parts of the response it reads. With Pact, these are published to a broker; with Spring Cloud Contract, they are written as contracts that generate tests for the provider. In both cases, the provider's pipeline replays every consumer's expectations against the new build before it can deploy.

Java
// Spring Cloud Contract, owned by the orders team, stored with the payments provider
Contract.make {
request {
method 'GET'
url '/payments/9'
}
response {
status 200
headers { contentType(applicationJson()) }
body(id: 9, status: 'AUTHORIZED', amount: 1250) // only the fields orders reads
}
}
// Payments build: generated test calls the real controller
// PaymentsContractTest > validate_get_payment() PASSED

Notice that the contract lists only the fields the consumer reads. The provider is free to add fields, but if it removes amount, the generated test fails in the payments build, before the change ever reaches a cluster. With Pact, a can-i-deploy check against the broker answers the same question for a specific pair of versions, which is exactly the N and N-1 question.

5Designing for N and N-1, Including Events

We make N and N-1 an explicit rule: every release of a service must work with the previous release of every service it talks to, in both directions. That includes the database schema, which must be readable by both versions, and the configuration, which must not require a key that the old version would reject.

Events need extra care, because they live longer than requests. A message written by version 42 may be read days later, and a consumer that replays a topic from the start may read messages from version 30. So event schemas go into a schema registry with a compatibility mode. BACKWARD means new consumers can read old events, FORWARD means old consumers can read new events, and FULL means both. For independently deployed producers and consumers, FULL, or its transitive form when topics are replayed, is the safe default. The registry rejects a producer's new schema if it would break that rule, which is the event equivalent of a contract test.

6Feature Flags to Separate Deploy From Switch

The last piece lets providers move first. Suppose payments adds a new fraud check that changes the response for some orders. If the new behaviour switched on the moment version 42 deployed, consumers would see it mid-rollout and could not roll back alone. Instead, we deploy the code behind a feature flag that is off. Once version 42 runs on all pods and the consumers have shipped code that understands the new response, we turn the flag on, for a few percent of traffic first. If something goes wrong, we turn it off without a deploy.

So the deploy only moves code, and the flag moves behaviour. That makes every deploy boring, which is the goal: with these rules, the order in which 50 teams deploy stops mattering.

7Follow-up questions

Why N-1 and not N-2?

Because N-1 covers a rolling deploy and a single rollback, which is what happens in practice. Supporting N-2 doubles the combinations to test and keeps old code around longer. If a team deploys rarely or partners lag behind, they can choose a wider window, but N-1 is the minimum every service must meet.

What about clients we do not control, such as mobile apps?

Mobile apps may stay on old versions for a year or more, so for them N-1 is not enough. Public and mobile APIs need a longer support window, usually expressed in calendar time, and a version header or app version that lets us measure who is still on old builds.

8Conclusion

In this answer, we saw that independent deploys always mix versions: rolling deploys, rollbacks and long-lived events make N and N-1 run together. We design for that with additive-only changes on providers and tolerant readers on consumers, expand and contract for any breaking change including database columns, consumer-driven contract tests with Spring Cloud Contract or Pact in the provider pipeline, schema registry compatibility for events, and feature flags so providers can deploy new behaviour before consumers switch to it.

What to say in the interviewAbout 80 seconds aloud

Open with

My starting assumption is that versions N and N-1 of every service are always running together, because rolling deploys, rollbacks and events sitting in a topic make it unavoidable.

Then, if they want more

So the design rule is that any mix must work, in any order. On the provider side, changes within a version are additive only: new optional fields, new endpoints, and enum values the contract says may grow.

On the consumer side, every reader is tolerant, ignoring unknown fields and mapping unknown enums to a default; Spring Boot's ObjectMapper already ignores unknown properties, and we keep it that way.

Any real breaking change goes through expand and contract: add the new form, migrate consumers, and only then remove the old one, and the same for database columns, since both versions share the schema during a deploy.

To make it enforceable, consumers publish contracts with Pact or Spring Cloud Contract, and the provider's pipeline runs them before it can deploy, so removing a field a consumer reads fails the build. For events I use a schema registry with FULL compatibility, transitive if topics get replayed.

And new behaviour goes behind feature flags, so the provider can deploy first and switch on only when consumers are ready, and switch off without a rollback.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How do you design for backward compatibility across many services that deploy...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/25ba4fa7c7/