WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

System Design · Intermediate · question 38 of 100

What is a circuit breaker pattern, and how does it help in improving the resilience of a system?

📕 Buy this interview preparation book: 100 System Design questions & answers — PDF + EPUB for $5

The circuit breaker pattern is a design pattern that helps improve the resilience of a system by detecting and handling failures in a graceful manner. The pattern is based on the concept of an electrical circuit breaker, which is designed to prevent damage to an electrical system in the event of a power surge or other overload.

In a software system, the circuit breaker pattern is typically used to detect failures in remote services or APIs that the system relies on, and to prevent cascading failures that could bring down the entire system. When a failure is detected, the circuit breaker trips and stops making requests to the failed service, instead returning a fallback response or error message. This allows the system to continue functioning, even if the failed service is not available.

The circuit breaker pattern typically includes three states:

Closed: In the closed state, the circuit breaker is allowing requests to pass through to the remote service. This is the normal operating state when the remote service is functioning correctly.

Open: In the open state, the circuit breaker has detected a failure in the remote service and is no longer allowing requests to pass through. Instead, it returns a fallback response or error message.

Half-open: In the half-open state, the circuit breaker allows a limited number of requests to pass through to the remote service, to determine whether it has recovered. If the requests are successful, the circuit breaker returns to the closed state. If the requests fail, it returns to the open state.

The circuit breaker pattern can improve the resilience of a system in several ways. First, by detecting failures and preventing cascading failures, it helps ensure that the system remains operational even if one or more components fail. Second, by returning a fallback response or error message, it helps ensure that users are not left waiting for long periods of time or experiencing errors. Finally, by allowing the system to continue functioning even when a remote service is unavailable, it helps ensure that the system can scale horizontally and handle large amounts of traffic.

Example:

Let’s consider an e-commerce application that relies on a payment gateway service to process payments. If the payment gateway service experiences a failure or is overwhelmed with traffic, it could cause the entire application to become unresponsive, resulting in lost sales and dissatisfied customers.

By using the circuit breaker pattern, the e-commerce application can detect when the payment gateway service is unavailable and stop making requests to it. Instead, it can return a fallback response or error message to the user, such as a message that the payment service is currently unavailable and to try again later. This helps ensure that the user is not left waiting for long periods of time or experiencing errors, and that the application remains operational even in the event of a payment gateway failure.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic System Design interview — then scores it.
📞 Practice System Design — free 15 min
📕 Buy this interview preparation book: 100 System Design questions & answers — PDF + EPUB for $5

All 100 System Design questions · All topics