Api Design hard
Your e-commerce API depends on a Recommendations service. During Black Friday, Recommendations service is overloaded and timing out. What should the main API do?
- A Implement a fail-fast strategy that returns a 503 Service Unavailable error to the user immediately to prevent the accumulation of high-latency requests in the server's thread pool.
- B Adopt a 'Graceful Degradation' policy by serving the core product data while hiding the non-critical recommendations section or replacing it with a cached set of generic items.
- C Establish an aggressive retry-on-timeout policy for the Recommendations service to ensure that every user eventually receives a personalized response during periods of peak load.
- D Switch the entire application to 'Maintenance Mode' until the backend services can be horizontally scaled to handle the current surge in Black Friday traffic successfully.
Answer: B. Adopt a 'Graceful Degradation' policy by serving the core product data while hiding the non-critical recommendations section or replacing it with a cached set of generic items.
**Graceful Degradation** ensures that a system continues to function, perhaps with reduced capabilities, in the presence of faults. If a non-critical dependency (like Recommendations) fails, the main application (Checkout) should catch the error and fall back to a safe default (e.g., empty list), rather than crashing or blocking the user's primary goal.
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?