skip to content

A ride-hailing server adds a ride category that two-year-old rider app builds have never seen; what must those old builds and the server each do?

level: seniorimportance: should knowfreq 36%

answer

  1. parse it, don't fail the response
  2. an explicit unknown case, not a guess
  3. you cannot render what you cannot book
  4. the server knows what each build can show
  5. capabilities say more than version numbers

basics

~20 s

The old build must map the unknown value to an explicit unknown case and hide or generically show it, never crash or guess. The server must not offer the category to builds that cannot book it, judged by version or declared capability.

solid answer

~50 s

On the client, written long ago, the parser should ignore unknown fields and decode an unrecognised category to an explicit `unknown` case, so one new value cannot fail the whole offers response, and the screen should hide that entry or show it generically, never mapped to a known category. But the server cannot rely on that: an old build cannot price, describe or book a category it has never heard of, and its behaviour is fixed. So the server decides per build what to send. It leaves the new category out of the offer list for builds that cannot handle it, judged by build version or, better, by a **capability** the build declares, and it puts generic display fields (title, price text) on anything an old build may still have to show, such as a past ride in the trip history.

code

json · 12 lines
json
{
  "request": {
    "appBuild": "5.8.1",
    "capabilities": ["rideCategory.genericDisplay", "fare.amountObject"]
  },
  "response": {
    "offers": [
      { "category": "standard", "title": "Standard", "priceText": "EUR 18.40" },
      { "category": "eco", "title": "Eco", "priceText": "EUR 16.90" }
    ]
  }
}

go deeper

for a junior

Recall that an old build must not crash on a value it has never seen: unknown fields are ignored and an unknown category becomes an explicit unknown case.

for a middle

Explain why surviving a value is not enough: an old build cannot price or book a category it does not know, so the server filters what it sends.

for a senior

Show the per-build decision: test how each supported build treats unknown values, filter by capability or version, give unfiltered lists generic display fields, and key caches with Vary.

for a principal

Weigh capabilities against version checks across the app portfolio: clearer per-feature truth against a growing list that needs its own retirement policy.

## The two halves of the problem An **enumerated field** is one whose value comes from a fixed list, such as a ride category of `standard`, `xl` or `premium`. When the server adds `eco`, every build released before that day meets a value its code has no name for. Two things then have to be true at once: - **The old build must survive it.** It cannot crash, fail the whole response or mislabel the ride. - **The rider must not be offered what their build cannot handle.** Surviving a value is not the same as being able to price, describe and book it. The first is the client's design, fixed years ago. The second is the server's job now. ## What the old build's parser should already do A build written to live for years treats the server's lists as open-ended: - **Unknown fields are ignored**, so new fields beside the category cause no harm. - **An unknown enumerated value decodes to an explicit `unknown` case**, rather than throwing and losing the whole response, or falling back to the first known value. - **The screen decides what `unknown` means**: hide the offer, or show a generic row if the payload carries display text. JSON parsers differ in what they do with an unexpected value by default, so this is a rule the app's design must state, not something to assume. The schema-driven binary format shows why the fallback matters: with an open enum the unrecognised number is stored as is, while with a closed enum the value goes into the unknown-field set and the accessor returns the enum's default. That is why its style guidance makes the first, zero value `UNSPECIFIED` rather than a meaningful category: an old reader that falls back to the default should land on "unknown", not on `standard`. ## What the server must do anyway The server cannot fix old builds, so it shapes what each build receives: | Option | What an old build sees | When it fits | |---|---|---| | Leave the category out for builds that cannot handle it | Only categories it knows | New offers the build could not book correctly | | Send it with generic display fields the build already renders | A titled row with price text | Builds whose design shows unknown entries generically | | Send it as is and trust the build | Whatever its parser does | Only for builds tested to handle unknown values well | | Raise the hard floor | An update block | When the category is required, which is rare | For the offer list, leaving the category out is usually right: a rider on an old build cannot be shown a price breakdown or a vehicle type their screen does not know. Lists the server cannot filter still need care. A rider who booked an `eco` ride on a new phone may open their trip history on an old tablet; that entry must arrive with a generic title and price text so the old build can show something sensible. ## Deciding per build: version numbers or capabilities The server needs to know which builds can handle the new category. - **Version numbers** are free, because the app already reports its build version. But they are coarse: both platforms may share a number while shipping features at different times, a hotfix build may differ from its neighbour, and a feature may be behind a flag inside one build. - **Capabilities** are explicit. The build sends a list of what it supports, such as `rideCategory.genericDisplay`, at launch or on each request, and the server includes the new category only for builds that declare it. Capabilities cost something too: the list grows, each one must be retired once the minimum supported version passes the builds that lack it, and a response shaped by a request header must list that header in `Vary`, so a cache never serves an `eco` offer list to a build that did not ask for it. ## The order of work 1. Test how each supported build handles an unknown category value. 2. Add the capability (or a version check) on the server and filter the offer list. 3. Add generic display fields wherever a list cannot be filtered. 4. Ship the build that understands `eco` and declares the capability. 5. Launch the category; old builds keep seeing only what they can book.

  • An old build maps any unknown category to its first known value. What breaks?
    The rider sees an `eco` offer labelled as `standard`, possibly with the wrong vehicle, and may book a ride they did not choose. Nothing errors, so nobody notices until complaints arrive. That build's behaviour cannot be changed, so the server must leave the category out for it, which is why the server needs to know, per build, how it handles unknown values.
  • Why must a capability header used to shape responses appear in Vary?
    `Vary` lists the request headers that influenced the response, and a cache must not reuse a stored response for a request whose listed headers differ. Without it, a shared cache could store the offer list built for a capable build and serve it to an old one, putting the new category in front of a build that cannot book it.

  • An unknown enum value always crashes the app's JSON parser.
  • Map an unknown category to the closest known one so riders still see a price.
  • If old builds parse unknown values safely, the server can send anything.
  • The app's version number alone always tells the server what a build supports.
  • Fail the whole response on an unknown value so the problem is visible.