Design a Backward-Compatible Upgrade for a Bus Status API
Add an ETA in seconds, a route UUID and occupancy to a city bus status API while display panels that can never be updated keep getting exactly the answer they get today.
Problem statement
Design the next version of a city's bus status API. Mobile apps, a trip planner and the display panels at bus stops call it to get a bus's status, and the updated clients now need the ETA (estimated time of arrival) in seconds, the bus's route id and how full the bus is.
The panels can never get a software update, so everything they rely on today must keep working.
What exists today. - `GET /v1/buses/{id}` returns the bus's ETA in whole minutes and a field named `routeName`. Despite its name, `routeName` holds the name of the bus's next stop.
What the updated clients need. - The ETA in seconds. - `routeId`: the id of the route the bus is on, as a UUID (a standard 128-bit unique id). - Occupancy: how full the bus is, as `low`, `medium` or `high`.
What to deliver. Compare the ways you could add the new data and pick one. For each option, and for each decision in your design, say what you gain and what you give up.
For this exercise, assume: - Today a v1 response looks like `{"id": "B1042", "eta": 4, "routeName": "Harbor St"}`. `eta` is the number of whole minutes until the bus reaches that next stop, rounded down, so 0 means less than a minute.
- Nobody knows for sure how the panels' software handles JSON fields it does not expect. The city has a few spare panels to test with, but it cannot change their software. - Each bus reports its position about every 20 seconds, and an existing predictor turns positions into an ETA in seconds.
A route catalog already gives every route a UUID. Most buses have a passenger counter whose count the office already turns into low, medium or high; some older buses have none.
Out of scope: how ETAs are predicted, the trip planner's routing, how clients sign in, and the panels' hardware.
What to build
- Every existing client, including every display panel, keeps getting the v1 response it gets today: the same fields, types, units, rounding and error behavior.
- An updated client can get a bus's ETA in seconds, its route's UUID and its occupancy, and can tell when occupancy is unknown.
- Two requests made at the same moment report the same bus status in every version: the same next stop, and an ETA in minutes that is the ETA in seconds rounded down by v1's rule.
- The office can see which clients call which version, move the mobile apps and the trip planner to the new contract, and keep v1 running for the panels' whole lifetime.
At scale
- Three kinds of clients call the API: mobile apps, a trip planner and display panels. The panels can never receive a software update.
- For this exercise, assume about 1,500 buses and 3,000 display panels. At peak the panels, apps and trip planner together send about 5,000 requests per second, mostly about the few hundred buses near busy stops.
- For this exercise, assume that while a bus reports on time, every ETA the API returns must be based on position data no older than 30 seconds.
- For this exercise, assume the panels stay in service for about 10 years, and about 5% of app users are still on an old app version six months after a release.