Api Design medium
Service A calls Service B, which is failing. Without protection, A keeps sending requests, cascading the failure. What pattern prevents this?
- A Implement a Circuit Breaker that opens after a failure threshold, immediately rejecting subsequent calls until a timeout period allows for a health test.
- B Configure an aggressive retry policy that continues to send requests until Service B responds, ensuring eventual completion of all initiated tasks.
- C Increase the network timeout duration to several minutes to give Service B sufficient time to clear its internal processing queues during high load.
- D Deploy a local cache in Service A that stores the last successful response from Service B and serves it whenever a network failure is detected.
Answer: A. Implement a Circuit Breaker that opens after a failure threshold, immediately rejecting subsequent calls until a timeout period allows for a health test.
The **Circuit Breaker** pattern prevents a service from repeatedly trying to call a failing dependency. After a threshold of failures is reached, the breaker 'opens', immediately failing subsequent calls without attempting the network request. This allows the failing service to recover and prevents resource exhaustion in the calling service.
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?