Quick revision
The short answer
I would pick one versioning strategy for the whole company after checking what our gateways, caches and documentation tools handle best, usually a header or a path segment, and use Spring Framework 7's built-in API versioning to map versions to handlers. At the same time I would make new versions rare by preferring backward-compatible changes, publish deprecation and sunset rules with dates and headers, and roll the standard out on new APIs first, migrating old ones only when they change anyway.
What to remember
In this answer, we compared path, header and media type versioning by their effect on gateways, caches and tooling, and chose one company standard based on that. We saw how Spring Framework 7 maps versions to handlers with a configured version source and version attributes such as 2.0+, why backward-compatible changes should keep new versions rare, how Deprecation and Sunset headers plus usage tracking retire old versions, and how to roll the standard out on new APIs first.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would pick one versioning strategy for the whole company after checking what our gateways, caches and documentation tools handle best, usually a header or a path segment, and use Spring Framework 7's built-in API versioning to map versions to handlers. At the same time I would make new versions rare by preferring backward-compatible changes, publish deprecation and sunset rules with dates and headers, and roll the standard out on new APIs first, migrating old ones only when they change anyway.
Background to this question
When every team versions its APIs in its own way, clients pay the price: one service wants /v2 in the path, another wants an X-Api-Version header, a third wants a vendor media type. Gateways need special rules, caches mix up responses, and nobody knows when an old version may be switched off. A senior engineer is expected to turn that into one boring, predictable standard. In this answer, we will compare the three common strategies, see how Spring Framework 7 supports versioning natively, decide how to keep the number of versions small, define deprecation rules, and plan the rollout across existing services.
1A Quick Recap of the Three Strategies
API versioning means that a client says which version of the contract it was written against, and the server answers with that version's behaviour. There are three common places to carry the version. In the path, as in /v2/orders/1, the version is visible everywhere: in logs, in browser links and in every gateway route. In a request header, such as API-Version: 2, the URL of a resource stays the same across versions. In the media type, as in Accept: application/vnd.example.order+json;version=2, the version becomes part of content negotiation.
Each choice has real costs outside the application, and that is where the decision should be made. A cache, for example a CDN, keys responses by URL, so a header-based version only works if the response carries Vary: API-Version and the cache honours it. Path versions are trivial for gateways and caches but make the same resource appear under several URLs. Media type versions are the most precise but the hardest for client developers and for documentation tools.
| Concern | Path /v2/... | Header API-Version | Media type parameter |
|---|---|---|---|
| Gateway routing | simple prefix rules | needs header rules | needs header parsing |
| HTTP caches and CDN | works by URL | needs Vary: API-Version | needs Vary: Accept |
| Logs and debugging | visible in every URL | only if headers are logged | only if headers are logged |
| Docs and client tooling | very well supported | well supported | awkward in many tools |
| Stable resource URL | no | yes | yes |
2Choosing One Strategy for Everyone
I would gather the people who run the gateway, the CDN and the developer portal, list the strategies above, and choose one that every layer supports without special cases. In many companies that is a request header for internal APIs, because resource URLs stay stable and the gateway can route on it, or a path segment for public APIs, because it is the easiest for outside developers. What matters more than the choice is that there is exactly one, written down with the header name and the version format, for example a major number like 2 or a date like 2026-11-01.
The decision record should also say what happens when the client sends no version: either the request fails with 400, or it gets a fixed default. For public APIs a default that never changes is friendlier; for internal ones, requiring the version catches forgotten clients early.
3Using Spring Framework 7 API Versioning
Spring Framework 7 adds first-class API versioning to Spring MVC and WebFlux. We configure once where the version comes from, and the request mappings declare which versions they handle. The exact method names below match the Framework 7 configuration as I know it, but check them against your version.
Notice the 2.0+ form. It says that this handler serves version 2.0 and every newer version until another handler takes over, so a new version 2.1 only needs new handlers for the endpoints that actually changed. That keeps controllers small. In Spring Boot 4 the same settings are also available as properties under spring.mvc.apiversion, and the client side, RestClient and WebClient, can insert the version into outgoing requests the same way, which keeps both ends consistent.
4Making New Versions Rare
The cheapest version is the one we never create. Most changes can be made backward compatible: adding an optional field, adding a new endpoint, accepting a new optional parameter, or adding an enum value that clients are told to tolerate. The standard should say this explicitly and require clients to ignore unknown fields, which Jackson can do with FAIL_ON_UNKNOWN_PROPERTIES turned off.
A new major version is only justified by a breaking change: removing or renaming a field, changing its type or meaning, or changing error behaviour. When a team wants one, a short review with the API guild checks whether an additive change would do instead. In practice this keeps most services on one or two live versions.
5Deprecation and Sunset Rules
Every version needs an end of life that clients can see coming. The standard should fix the minimum support period after a newer version is released, for example 12 months for public APIs and 6 months for internal ones, and how clients are told. The HTTP side has standard headers for this: Deprecation says a version is deprecated and since when, Sunset gives the date after which it stops working, and a Link header with rel=deprecation points to the migration guide. Spring Framework 7 can add these headers for deprecated versions through its deprecation handler (check your version for the class name).
Headers alone are not enough, because people do not read headers. We also record which clients still call the old version, using the gateway's metrics per version and per client id, and contact them directly months before the sunset date.
6Rolling the Standard Out
I would not migrate every service at once. New APIs follow the standard from day one, enforced by an API linter in the build and by a shared starter that configures versioning the same way everywhere. Existing APIs adopt it the next time they need a breaking change, so the migration rides on work that has to happen anyway. Old versioning styles stay supported until their own sunset date. Within a year or two the old styles fade out without a big-bang project, and the gateway rules become simpler with each retired version.
- Decide one strategywith gateway, CDN and portal owners
- Publish the standardheader name, version format, default, sunset rules
- Ship a shared starter and lintersame config in every service
- New API or breaking change?YesAdopt the standard nowNoKeep current style until it changes
- Track usage per versiongateway metrics per client
- Retire old versions on their sunset date
6 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Which strategy would you personally choose?
For a company where most APIs are internal and go through one gateway, I would choose a request header such as API-Version, because resource URLs stay stable and Spring Framework 7 and the gateway both support it. For public developer APIs, I would lean towards a path segment because it is the easiest to discover, cache and document. Either way, I would pick only one per audience and write it down.
How do you test that both versions keep working?
Each supported version gets its own contract tests, run in the build of the provider, so a change for version 2 cannot silently break version 1. MockMvc or a RestClient test sends the version header and compares the response with a stored example. Once a version is retired, its tests are deleted in the same change.
What about versioning events and messages, not only HTTP?
The same thinking applies: prefer additive changes, carry a schema version in the message, and keep consumers tolerant of unknown fields. A schema registry with compatibility checks plays the role that the API linter plays for HTTP.
8Conclusion
In this answer, we compared path, header and media type versioning by their effect on gateways, caches and tooling, and chose one company standard based on that. We saw how Spring Framework 7 maps versions to handlers with a configured version source and version attributes such as 2.0+, why backward-compatible changes should keep new versions rare, how Deprecation and Sunset headers plus usage tracking retire old versions, and how to roll the standard out on new APIs first.
Open with
I would start by making it a company decision rather than a framework one. I would sit down with the owners of the gateway, the CDN and the developer portal and compare path, header and media type versioning by what each layer supports.
Then, if they want more
A path version is easy for caches and docs; a header keeps URLs stable but needs Vary for caches; media types are precise but awkward for clients. Then I would publish one standard with the header name, the version format, and what happens without a version.
Spring Framework 7 helps here, because it has built-in API versioning: we configure the version source once, for example useRequestHeader, and mappings declare a version, including forms like 2.0+ so only changed endpoints need new handlers. I would check the exact configuration for our version and ship it in a shared starter.
The more important rule is to make versions rare, by preferring additive changes and tolerant clients. For retirement, every version gets a minimum support period, Deprecation and Sunset headers and a migration link, plus gateway metrics to see who still calls it. Finally, new APIs adopt the standard immediately and old ones migrate when they next need a breaking change.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 7, Spring Boot 4
- 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.
- Official documentation
- Spring Framework reference, Spring Web MVC
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 "Teams want to version REST APIs differently: path, header, media type. With Spring...": https://scrivio-interview-library.netlify.app/spring-boot/rest-controllers/16ff871ad3/