Api Design hard
Service A depends on Service B's API. B team wants to change a field. How do you prevent B from accidentally breaking A?
- A Implement Consumer-Driven Contract Testing (e.g., Pact), where the consumer defines its expectations as a suite of tests that the provider must satisfy during its own CI/CD pipeline.
- B Utilize a centralized version-control repository where every API schema change must be manually reviewed and approved by the lead architects of every dependent microservice.
- C Enforce a 'Non-Destructive' schema evolution policy that strictly forbids any modification to existing fields, requiring all updates to be implemented as entirely new endpoints.
- D Rely on an automated regression suite that performs end-to-end integration tests between the two services in a shared staging environment before every production release.
Answer: A. Implement Consumer-Driven Contract Testing (e.g., Pact), where the consumer defines its expectations as a suite of tests that the provider must satisfy during its own CI/CD pipeline.
**Consumer-Driven Contract Testing** (e.g., Pact) reverses the testing dependency. Consumers define the exact API surface they use (the contract). The Provider (service) then runs these contracts as part of their CI pipeline. If a change in the Provider breaks a Consumer's contract, the build fails, preventing the breaking change from reaching production.
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?