Quick revision
The short answer
We split the field with expand and contract: first add firstName and lastName next to name and keep filling name, then accept both forms on input with a clear rule when both are sent, then deprecate name, tell consumers and measure who still uses it, and remove it only when usage reaches zero or the published sunset date passes. Contract tests with the known consumers prove they work with both shapes. The whole change typically takes from three to twelve months, most of it waiting for consumers.
What to remember
In this answer, we split name into firstName and lastName without a new major version by using expand and contract. We added the new fields while keeping name filled, accepted both forms on input with a rule for when both are sent, deprecated name in the OpenAPI spec with a sunset date, measured who still used it, verified known consumers with contract tests against both shapes, and removed name only when usage reached zero or the date passed. The coding takes days; the waiting takes months, and planning for that is the real work.
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.
We split the field with expand and contract: first add firstName and lastName next to name and keep filling name, then accept both forms on input with a clear rule when both are sent, then deprecate name, tell consumers and measure who still uses it, and remove it only when usage reaches zero or the published sunset date passes. Contract tests with the known consumers prove they work with both shapes. The whole change typically takes from three to twelve months, most of it waiting for consumers.
Why this question is asked
Changing a widely used API without a new major version is a very common real task, and the field rename is its simplest form. It is harder than it looks because we cannot see all our clients, they deploy on their own schedules, and some of them will not read our announcements. Interviewers ask it to see whether we can run a change safely over months, not just write the new code. In this answer, we will recap the expand and contract approach, walk through each phase with the code and the reason for it, say how long each phase lasts and what ends it, and see how contract tests keep the consumers safe.
1A Quick Recap of Expand and Contract
Expand and contract is a way to make a breaking change out of compatible ones. In the expand step we add the new shape next to the old one, so both work at the same time. Then consumers move from the old shape to the new one at their own pace. In the contract step, once nobody uses the old shape, we remove it.
The key idea is that at every moment in this process, every client, old or new, keeps working. That is why we do not need a new major version: the API is never broken, it just carries some extra fields for a while. The price is time and the discipline to actually finish the contract step.
2Phase 1: Add the New Fields to Responses
We start with responses because reading is where old clients are most fragile. The customer response gains firstName and lastName, and name stays, filled from the new fields so that it is always consistent.
Notice that this needs the data first: the database must store first and last name separately, which usually means a migration that splits existing names. That split is the hardest part of the job, because names like 'Maria del Carmen Lopez' or a single name do not split cleanly. So we also keep the original full name for old records and never invent a split we are unsure of. This phase lasts one release, a few days, and it ends when the new fields are in production and documented.
3Phase 2: Accept Both Forms on Input
Now old clients still send name in their POST and PUT requests, and new clients send firstName and lastName. The server must accept both, and it needs a clear rule for the case where a client sends both, otherwise two pods or two code paths may decide differently.
The rule we chose is that the new fields win when present, and we publish that rule in the API documentation so nobody has to guess. Some teams prefer to reject a request with 400 when both are sent and they disagree; that is stricter and also fine, as long as it is written down. This phase starts in the same release as phase 1 and lasts as long as old clients exist, so it overlaps with everything that follows.
4Phase 3: Deprecate, Announce and Measure
Next we tell the world. In the OpenAPI spec the name property gets deprecated: true and a description that points to the new fields and the sunset date. We announce the change through the channels consumers actually read, and responses can carry a Sunset header with the date, which some clients and gateways log.
Then we measure, because without data the removal date is a guess. Requests are easy: we count requests that send name, tagged by client id from the token or an API key. Reads are harder, because a server cannot see which response fields a client uses. For known internal consumers, contract tests tell us; for the rest, we ask, and we watch for the clients that still send name, because a client that sends the old field almost always reads it too.
| Phase | What we do | Typical length | Ends when |
|---|---|---|---|
| 1 Expand responses | Add firstName, lastName; keep name | One release, days | New fields live and documented |
| 2 Accept both inputs | New fields win when both sent | Until removal | Overlaps all phases |
| 3 Deprecate and measure | deprecated: true, Sunset date, metrics | 3-6 months internal, 6-12 external | Usage zero or date passed |
| 4 Verify consumers | Contract tests on both shapes | During phase 3 | All known consumers green |
| 5 Contract | Remove name from input and output | One release | Field gone, docs updated |
This phase is the long one. For internal consumers, three to six months is typical. For partners and external clients, six to twelve months, and contracts or regulations may require longer.
5Phase 4: Prove It With Contract Tests
Contract tests turn 'we think the billing team is fine' into a fact. In a consumer-driven contract test, written with Pact or Spring Cloud Contract, each consumer records the requests it sends and the fields it reads, and the provider's pipeline replays those expectations against the real service. While both shapes exist, we run them against the current version with both name and the new fields.
Before the removal, we run the provider against a build without name. Any consumer whose contract still reads name fails that build, and we know exactly whom to talk to. When every known consumer passes without name, and the metric for unknown clients has been at zero for a few weeks, we are ready.
6Phase 5: Remove the Old Field
The removal itself is small: delete name from the DTO, remove the legacy branch in resolve(), and update the spec. We remove it when usage reaches zero, or when the published sunset date passes even if a few clients have not moved. In the second case we warn those clients directly beforehand, because the date was public and a promise kept on time is what makes the next deprecation credible.
The contract step is what most teams skip, and every skipped one leaves the API carrying fields nobody dares to remove.
7Follow-up questions
What if usage never reaches zero?
Then the sunset date decides. A small number of clients that ignored months of notice should not keep an API in a transitional state forever. We contact them directly, give a short final window if it is reasonable, and remove the field on the date. For external partners under contract, the contract may set the minimum notice, and we plan the date with that in mind.
Why not just ship a v2 of the endpoint?
A new version forces every consumer to migrate everything at once, and we then run two versions for years. Splitting one field is a small change that expand and contract handles inside the current version; we save major versions for changes that really cannot be made additively.
How do you handle a client that sends both fields and they disagree?
We apply the published rule. Either the new fields win and name is ignored, or the server rejects the request with 400 and a problem detail that explains the conflict. The important thing is that the rule is explicit, documented and the same in every code path.
8Conclusion
In this answer, we split name into firstName and lastName without a new major version by using expand and contract. We added the new fields while keeping name filled, accepted both forms on input with a rule for when both are sent, deprecated name in the OpenAPI spec with a sunset date, measured who still used it, verified known consumers with contract tests against both shapes, and removed name only when usage reached zero or the date passed. The coding takes days; the waiting takes months, and planning for that is the real work.
Open with
I would use expand and contract. In the first release, a matter of days, I add firstName and lastName to the response and keep name populated from them, so old clients see no change.
Then, if they want more
That needs a data migration that splits stored names carefully, keeping the original full name where a split is unclear. In the same release I accept both forms on input, with a documented rule: if the new fields are present they win, otherwise I derive them from name.
Then I mark name as deprecated in the OpenAPI spec, announce a sunset date, add a Sunset header, and measure usage with a counter per client of requests that still send name. That phase is the long one, three to six months for internal consumers and six to twelve for partners.
During it I run consumer-driven contract tests, Pact or Spring Cloud Contract, against both shapes, and before removal against a build without name, which tells me exactly which consumers still depend on it. I remove name only when usage has been zero for a few weeks or the published date passes, after contacting any stragglers directly. The removal release is small and easy to roll back.
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.
- 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 "You need to split the field name into firstName and lastName in a widely used customer...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/9efe254ef1/