Interview concept

API Versioning And Backward Compatibility

Asked of: Software Engineer

Last updated

Architecture diagram showing old and new API clients routed through version selection, contract checks, compatible services, and monitored rollout.

What's being tested

The interviewer is testing whether you can evolve a production API without breaking deployed clients, services, or stored data. You should demonstrate a concrete compatibility strategy: contract discovery, additive schema changes, version selection, deprecation, observability, and safe rollout. DoorDash operates many independently deployed services and clients, so the key concern is managing change across deployment boundaries rather than merely choosing a URL format.

Core knowledge

  • Backward compatibility means old clients continue to work against the new server; forward compatibility means newer clients tolerate responses from an older server. Design explicitly for both, especially when mobile clients may remain deployed for weeks.

  • Prefer additive changes: optional request fields, new response fields, new endpoints, and new enum values handled as unknowns. Removing fields, renaming fields, tightening validation, or changing meanings are commonly breaking changes.

  • Choose a versioning mechanism deliberately: URI versions such as /v2/orders, header-based versions such as Accept: application/vnd.company.order+json;version=2, or negotiated media types. URI versions are visible and operationally simple; headers preserve resource identity but are easier to misconfigure and debug.

  • Treat the API description as a contract. Use OpenAPI or protobuf definitions, generated clients, schema-diff checks, and compatibility gates in CI. A change should fail review if it removes a required field, changes a type, narrows accepted values, or alters documented semantics.

  • For JSON, clients should ignore unknown response fields, servers should tolerate omitted optional request fields, and enum parsing should include an UNKNOWN branch. Do not silently reinterpret an existing value; add a new value or version the behavior.

  • For protobuf and gRPC, never reuse field numbers, avoid changing a field’s wire type, reserve deleted field numbers, and use presence-aware fields where “unset” differs from a default value. Compatibility is a wire-format property, not just a source-code property.

  • Separate API versioning from business behavior flags. A version describes a stable contract; a feature flag or capability negotiation selects behavior for a subset of callers. Combining them creates hard-to-reason-about states and makes rollback less reliable.

  • Use capability negotiation when clients evolve independently. A client can advertise supported features or API capabilities, allowing the server to return a compatible representation. This is often better than proliferating versions for every small optional feature.

  • Define a deprecation lifecycle: announce a replacement, measure traffic by client/version, publish a sunset date, notify owners, and remove only after usage reaches an agreed threshold. Include a Deprecation or Sunset response header where supported, but do not rely on headers alone.

  • Make rollout reversible. Deploy server support before client adoption, dual-read or dual-write during storage migrations, canary by caller or percentage, and retain the old path until dashboards show error rate, latency, and semantic correctness are stable.

  • Compatibility includes operational behavior, not only schemas. A new endpoint that changes authorization, idempotency, pagination ordering, error codes, rate limits, or latency can break clients even when its JSON shape appears compatible.

  • Test at multiple boundaries: consumer-driven contract tests, golden request/response fixtures, fuzzing for unknown fields, backward/forward schema checks, and integration tests against old and new client versions. Test retries, duplicate requests, partial failures, and malformed input explicitly.

Worked example

Prompt: Design a backward-compatible evolution strategy for an orders API. In the first 30 seconds, clarify whether callers include mobile clients, internal services, and third parties; whether old clients must work indefinitely; which fields and semantics may change; and the latency, authentication, and rollback requirements. I would organize the answer around four pillars: contract and compatibility rules, version selection, rollout and migration, and observability/deprecation. I would start with additive changes such as an optional delivery_instructions field and a new endpoint for functionality that cannot preserve the old contract. For a breaking change, I would use an explicit version such as /v2/orders, maintain both implementations behind a shared domain layer, and route by authenticated client capability rather than blindly duplicating business logic. A key tradeoff is URI versioning versus header negotiation: URI versioning improves cacheability, logs, and manual debugging, while header negotiation avoids changing resource URLs but increases tooling and routing complexity. I would require schema compatibility checks in CI, consumer contract tests, version-specific dashboards, and a canary before broad adoption. I would close by saying that, with more time, I would inspect real client-version traffic, define the sunset policy with owners, and test authorization, pagination, retries, and error semantics—not just the response schema.

A second angle

Prompt: Migrate a protobuf/gRPC service while older binaries remain deployed. The framing changes from public URL design to wire compatibility, field numbering, and mixed-version behavior during rolling deployment. I would reserve removed field numbers, add new fields rather than repurpose old ones, ensure old readers ignore new fields, and make new readers tolerate absent fields. The main risk is semantic rather than syntactic: a new server may send a value that an old client cannot interpret correctly, so capability checks or an explicitly versioned RPC may be safer than relying on unknown-field handling. I would validate the migration with old-client/new-server and new-client/old-server integration tests.

Common pitfalls

Treating “additive” as automatically safe. Adding a response field is usually compatible, but adding a required request field, changing pagination order, introducing a new enum value, or increasing response size can still break clients. Explain the client parsing and behavioral assumptions, not just the schema diff.

Pitfall: Saying “we will release /v2” without explaining how clients discover it, how traffic migrates, how both versions are tested, or when /v1 is removed.

Ignoring deployed-client reality. A backend engineer may propose updating every caller atomically, but mobile apps, partner integrations, and independently deployed services rarely permit that. State the deployment order, coexistence period, owner notification process, and rollback path.

Pitfall: Focusing deeply on version syntax while missing authentication, authorization, idempotency, rate limits, error codes, observability, and semantic changes—all of which can create production incompatibility.

Connections

The interviewer may pivot to consumer-driven contract testing, schema evolution in protobuf or event systems, database expand-and-contract migrations, and distributed rollout or feature-flag design. They may also ask how retries and idempotency behave when old and new clients coexist.

Further reading

Related concepts