Bird
Raised Fist0
HLDsystem_design~20 mins

Circuit breaker pattern in HLD - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Circuit Breaker Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the Circuit Breaker States
Which of the following correctly describes the three main states of a circuit breaker in system design?
AClosed: Requests flow normally; Open: Requests are blocked; Half-Open: Some requests allowed to test recovery
BClosed: Requests are blocked; Open: Requests flow normally; Half-Open: All requests are retried
CClosed: System is down; Open: System is up; Half-Open: System is restarting
DClosed: Requests are queued; Open: Requests are dropped; Half-Open: Requests are duplicated
Attempts:
2 left
💡 Hint
Think about how a circuit breaker protects a system from failures by controlling request flow.
Architecture
intermediate
2:00remaining
Placing a Circuit Breaker in a Microservices Architecture
Where is the best place to implement a circuit breaker in a microservices architecture to protect a service from downstream failures?
AOn the database server
BInside the downstream service itself
COn the client side before calling the downstream service
DOn the network firewall
Attempts:
2 left
💡 Hint
Consider where you want to stop requests before they reach a failing service.
scaling
advanced
2:30remaining
Scaling Circuit Breaker for High Traffic Systems
In a high traffic distributed system, what is a key challenge when scaling circuit breakers across multiple instances, and how can it be addressed?
AChallenge: Too many retries; Solution: Disable retries globally
BChallenge: Increased latency; Solution: Remove circuit breakers entirely
CChallenge: Overloading the database; Solution: Cache all requests
DChallenge: Inconsistent state across instances; Solution: Use centralized state storage or distributed consensus
Attempts:
2 left
💡 Hint
Think about how multiple instances share information about failures.
tradeoff
advanced
2:00remaining
Tradeoffs of Circuit Breaker Timeout Settings
What is a tradeoff when setting a very short timeout duration for the circuit breaker before it transitions from Open to Half-Open?
AMay cause premature retries leading to repeated failures
BIncreases system downtime by blocking requests too long
CReduces system responsiveness by allowing too many requests
DCauses the circuit breaker to never open
Attempts:
2 left
💡 Hint
Consider what happens if the system tries to recover too quickly.
estimation
expert
3:00remaining
Estimating Capacity for Circuit Breaker State Storage
You have 1000 microservice instances each with 10 downstream services protected by circuit breakers. Each circuit breaker state requires 1KB of memory. Estimate the total memory needed to store all circuit breaker states if centralized storage is used.
AApproximately 1 MB
BApproximately 10 MB
CApproximately 100 MB
DApproximately 1 GB
Attempts:
2 left
💡 Hint
Multiply instances by services and memory per state.

Practice

(1/5)
1. What is the primary purpose of the circuit breaker pattern in system design?
easy
A. To prevent repeated calls to a failing service and improve system stability
B. To increase the number of requests sent to a service
C. To store user session data efficiently
D. To encrypt data during transmission

Solution

  1. Step 1: Understand the circuit breaker pattern role

    The circuit breaker pattern is designed to stop sending requests to a service that is failing repeatedly to avoid wasting resources and cascading failures.
  2. Step 2: Identify the main benefit

    By preventing repeated calls to a failing service, it helps maintain overall system stability and improves user experience by failing fast.
  3. Final Answer:

    To prevent repeated calls to a failing service and improve system stability -> Option A
  4. Quick Check:

    Circuit breaker purpose = prevent repeated failing calls [OK]
Hint: Circuit breaker stops calls to failing services fast [OK]
Common Mistakes:
  • Confusing circuit breaker with caching
  • Thinking it increases request volume
  • Mixing it up with encryption or session management
2. Which of the following correctly describes the open state in a circuit breaker?
easy
A. The circuit breaker allows all requests to pass through
B. The circuit breaker resets all counters to zero
C. The circuit breaker tests a limited number of requests
D. The circuit breaker blocks all requests to the failing service

Solution

  1. Step 1: Recall the circuit breaker states

    The circuit breaker has three states: closed (normal operation), open (blocking requests), and half-open (testing requests).
  2. Step 2: Define the open state behavior

    In the open state, the circuit breaker blocks all requests to the failing service to prevent further failures.
  3. Final Answer:

    The circuit breaker blocks all requests to the failing service -> Option D
  4. Quick Check:

    Open state = block requests [OK]
Hint: Open state means block all requests [OK]
Common Mistakes:
  • Confusing open with closed or half-open states
  • Thinking open state allows requests
  • Assuming counters reset in open state
3. Consider this simplified pseudocode for a circuit breaker:
if failure_count > threshold:
    state = 'open'
if state == 'open':
    return 'fail fast'
else:
    call_service()

What will happen if failure_count exceeds the threshold?
medium
A. The service call will continue normally
B. The circuit breaker will enter half-open state
C. The circuit breaker will return 'fail fast' without calling the service
D. The failure count will reset automatically

Solution

  1. Step 1: Analyze the condition for failure count

    If failure_count is greater than threshold, the state is set to 'open'.
  2. Step 2: Check behavior when state is 'open'

    When state is 'open', the code returns 'fail fast' and does not call the service.
  3. Final Answer:

    The circuit breaker will return 'fail fast' without calling the service -> Option C
  4. Quick Check:

    Failure count > threshold = fail fast [OK]
Hint: Open state returns fail fast, no service call [OK]
Common Mistakes:
  • Assuming service call still happens
  • Confusing open with half-open state
  • Thinking failure count resets automatically
4. A circuit breaker is stuck in the open state and never transitions to half-open. What is the most likely cause?
medium
A. The timeout to reset the circuit breaker is missing or too long
B. The service is always healthy
C. The failure count threshold is set too low
D. The circuit breaker is not counting failures

Solution

  1. Step 1: Understand state transitions in circuit breaker

    The circuit breaker moves from open to half-open after a timeout period to test if the service has recovered.
  2. Step 2: Identify cause of stuck open state

    If the timeout is missing or set too long, the circuit breaker will never try half-open state and remain open indefinitely.
  3. Final Answer:

    The timeout to reset the circuit breaker is missing or too long -> Option A
  4. Quick Check:

    Missing timeout causes stuck open state [OK]
Hint: Timeout missing or too long keeps breaker open [OK]
Common Mistakes:
  • Confusing failure threshold with timeout
  • Assuming service health affects state directly
  • Ignoring the role of failure counting
5. You design a system using the circuit breaker pattern to call a payment service. The service fails intermittently. How should you configure the circuit breaker to balance availability and fault tolerance?
hard
A. Set a high failure threshold and long timeout to avoid blocking the service too soon
B. Set a low failure threshold and short timeout to quickly block and retry the service
C. Disable the circuit breaker to avoid blocking any requests
D. Set failure threshold to zero to block all requests immediately

Solution

  1. Step 1: Understand intermittent failure impact

    Intermittent failures mean the service sometimes works and sometimes fails, so quick detection and retry is important.
  2. Step 2: Choose configuration for balance

    A low failure threshold and short timeout allow the circuit breaker to quickly block failing calls and retry soon, improving fault tolerance and availability.
  3. Final Answer:

    Set a low failure threshold and short timeout to quickly block and retry the service -> Option B
  4. Quick Check:

    Low threshold + short timeout balances availability and fault tolerance [OK]
Hint: Low threshold and short timeout balance retries and blocking [OK]
Common Mistakes:
  • Setting threshold too high delays failure detection
  • Disabling circuit breaker risks cascading failures
  • Setting threshold zero blocks all requests unnecessarily