Api Design hard
Your API has 3 live versions (v1, v2, v3) with overlapping code paths. Maintenance is expensive. What's a sustainable approach?
- A Deploy three independent containerized microservices, each running a frozen version of the codebase that corresponds to a specific API version's business requirements.
- B Maintain a single 'head' codebase with version-aware transformation proxies that explicitly translate internal business objects into the specific schema shapes required by legacy versions.
- C Enforce a strict 'Latest Version Only' policy that automatically rejects requests to deprecated endpoints, forcing all mobile and third-party clients to upgrade within a zero-day window.
- D Use a shared database schema with version-specific SQL views that hide or reveal new columns based on the 'X-API-Version' header provided by the client application.
Answer: B. Maintain a single 'head' codebase with version-aware transformation proxies that explicitly translate internal business objects into the specific schema shapes required by legacy versions.
Maintaining multiple versioned codebases (A) is unmaintainable. The sustainable pattern (used by Stripe) is to have a single 'head' version of the codebase. Incoming requests are tagged with their version. A middleware layer (or serialization gates) transforms the response from the internal 'head' representation back to the shape expected by the requested version. This centralizes version logic and allows the core system to move forward.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- You're designing a REST API for a blog. Which endpoint best represents 'get all comments for post 123'?
- A client wants to update only the 'status' field of an order, leaving other fields unchanged. Which HTTP method is most appropriate?
- A client calls POST /users with valid data, and the user is created. What status code should the server return?
- A client retries a failed 'POST /payments' request due to network timeout. The server receives the request twice. Without idempotency handling, what can happen?
- An API returns 10,000 products. Returning all in one response is impractical. Which pagination approach is simple and stateless?
- Your API serves both mobile apps and third-party integrations. Which authentication method is most appropriate?