skip to content

After adding a new fare field beside the old one in a ride-hailing app's API, when may the server stop sending the old field?

level: middleimportance: must knowfreq 42%

answer

  1. readers of a response are invisible
  2. the release that switched is the marker
  3. one source feeds both fields
  4. the floor must pass the last reader
  5. never repurpose the old name

basics

~20 s

Only once no supported build reads it: the minimum supported version must sit above the last release whose code reads the old field. Until then the server fills both fields from one source and never changes the old one's meaning.

solid answer

~40 s

A server cannot see which response fields a client reads, so the evidence comes from the app's own history: note the first release that reads the new fare field, and count traffic by build version to see how many rides still come from builds below it. While any supported build reads the old field, the server sends both, filled from one source so they always agree, and never changes the old field's units or meaning. The old field goes only after the **minimum supported version** has been raised above the last build that reads it, which turns "rename" into "add, wait for the floor, then remove". Requests are the mirror image: while old builds send the old name, the server accepts both names.

code

json · 8 lines
json
{
  "rideId": "r_81c2",
  "fareTotal": "18.40",
  "fareAmount": {
    "value": "18.40",
    "currency": "EUR"
  }
}

go deeper

for a junior

Recall that a rename on an API old builds read means adding the new field and keeping the old one, filled with the same value, for a long time.

for a middle

Explain the trigger for removal: the minimum supported version passing the last release that reads the old field, and why the server cannot see field reads directly.

for a senior

Show the traps: two code paths drifting, a meaning changed in place giving silent wrong fares, and old builds erasing fields they do not know on full writes.

for a principal

Treat the contract step as a priced decision: the cost of carrying old fields against the riders a floor raise blocks, batched so one raise retires several.

## Why a rename is really an add, a wait and a remove On a server-only system, renaming a field is a refactor. On an API that installed apps read, the old name is part of a contract frozen inside every build that shipped with it. A rider app from two years ago will look for `fareTotal` for as long as it runs; if the response stops carrying it, that build shows a blank fare, a zero, or an error, depending on how its parser treats a missing field. So a rename becomes three steps: 1. **Expand.** The server adds the new field (`fareAmount`, say) and keeps sending the old one, both computed from the same value. 2. **Migrate.** A new app release reads the new field. Its version number is the marker that matters: every build from that one on is free of the old field. 3. **Contract.** The server stops sending the old field once no supported build reads it. The general shape is expand-and-contract. What is specific to an installed client is the trigger for step 3: it is not a date and not the newest build, it is the **minimum supported version** passing the last build that reads the old field. ## Why the server cannot measure who reads a field A plain JSON response is sent whole; the request does not say which fields the client will use. Server logs show that build 4.9 called the ride-quote endpoint, not that it read `fareTotal`. The evidence therefore comes from two places: - **The app's own code history:** the release that switched to the new field, so every build below it is known to read the old one. - **Traffic by build version:** the app sends its build version with each request, so the server can count requests, riders and rides per build and see how much of the business still runs on builds below the marker. In this scenario the switch happened in release 5.4, and 3% of fare-quote requests still come from builds below 5.4. The old field stays. ## The rules while both fields live | Rule | Why it matters for old builds | |---|---| | Fill both fields from one source | Two code paths drift, and old and new builds then show different fares for the same ride | | Never change the old field's units, type or meaning | An old build keeps parsing it happily and shows a wrong price with no error | | Never reuse the old name later for something else | A build that still reads that name would treat new data as the old value | | Accept both names in requests | Old builds keep sending the old name; new builds send the new one | | Prefer the new name when a request carries both | Keeps one rule when a build in between sends both | Of these, the silent one is the most dangerous. Removing a field produces a visible failure on old builds; changing its meaning in place produces wrong fares that nobody notices until riders complain. ## Turning the wait into a decision Waiting forever is also a cost: every field kept for old builds is code someone maintains. The decision to contract is made with numbers: - What share of riders and completed rides come from builds below the marker this month. - Whether those builds are already below another planned floor, so one raise retires several old fields at once. - What raising the floor would cost: those riders see an update block, and some will not update. When the cost of carrying the old field exceeds the cost of blocking the builds that read it, the server team raises the floor, waits until the block has taken effect, confirms the traffic from those builds has fallen to what it accepts, and then removes the field. ## Writes from old builds Fields flow both ways. An old build may also hold a field it has never heard of and send it back. If the app's model drops unknown fields and the write is a full replacement (an HTTP `PUT` asks for the target's state to be replaced with what the request carries), the old build silently erases the newer field on the server. A schema-driven binary format keeps unknown fields and writes them back out, but serialising such a message to JSON loses them, so the safe defences are design rules: - Old builds send partial updates of only what the user changed. - Or the server treats a field missing from an old build's write as "unchanged" rather than "cleared".

  • Old builds also send the old field name in requests. What does the server do?
    It accepts both names for as long as any supported build sends the old one, and prefers the new name when a request carries both. Rejecting the old name would fail every request from those builds, and they cannot learn to send anything else. Removing the old name from requests follows the same rule as responses: only after the minimum supported version passes the last build that sends it.
  • How can an old build erase data it has never heard of?
    If its model drops unknown fields and it writes the whole object back as a full replacement, the newer field is missing from the write and the server stores it as cleared. Defend with partial updates of only the changed fields, or by treating a field an old build did not send as unchanged. A schema-driven binary format keeps unknown fields on re-serialisation, but JSON conversion loses them.

  • Server logs will show us which clients still read the old field.
  • Once the newest release reads the new field, the old one can go.
  • Changing the old field's units in place is safer than removing it.
  • A Deprecation header will make old builds move to the new field.
  • We can free the old field name for reuse right after the switch.