A13Advanced
Backward Compatibility Thinking
30 minWhen modifying APIs/data structures
Format: Given a change requirement, determine whether it's backward compatible.
Scenario: Your API returns user data in the current format:
{
"name": "Alice",
"email": "alice@example.com"
}
Change Requirement: You need to split the name into first name and last name. Which of the following approaches is backward compatible?
Option A:
{
"first_name": "Alice",
"last_name": "Smith",
"email": "alice@example.com"
}
Option B:
{
"name": "Alice Smith",
"first_name": "Alice",
"last_name": "Smith",
"email": "alice@example.com"
}
Answer Guide: Option B is backward compatible — old fields are preserved, new fields are added. Clients using the old version won't break.
More Exercises:
- Adding a new column to a database table — backward compatible?
- Deleting a column from a database table — backward compatible?
- Adding a new optional parameter to an API — backward compatible?
- Removing a return field from an API — backward compatible?
- Changing an API's URL path — backward compatible?