A team is implementing a new microservice on Azure Functions. To ensure reliability, they want to limit the impact of failures in downstream dependencies. Specifically, if a particular external API dependency becomes slow or unresponsive, they want to prevent it from causing cascading failures in their Azure Function, while still allowing other parts of the system to function normally. Which design pattern should they apply?
- ASaga Pattern
- BCircuit Breaker
- CLeader Election
- DRetry with Jitter
Show answer & explanationAnswer & explanation
Correct answer: B. Circuit Breaker
The problem describes preventing 'cascading failures' if an 'external API dependency becomes slow or unresponsive'. This is the exact scenario the Circuit Breaker pattern is designed to address. It monitors calls to a service and, if failures or timeouts exceed a threshold, 'opens' the circuit, preventing further calls to the failing service. This allows the failing service to recover and prevents the calling service (Azure Function) from becoming overwhelmed or timing out repeatedly, thus preventing cascading failures. It's about preventing interaction with a known bad dependency.
Why the other options are wrong
- A. The Saga Pattern is for managing distributed transactions and maintaining data consistency across multiple services, not for isolating failing dependencies.
- C. Leader Election is used in distributed systems to select a single instance to perform a specific task, which is unrelated to dependency failure isolation.
- D. Retry with Jitter is for transient failures and retrying, which could exacerbate problems with a slow/unresponsive dependency by repeatedly calling it.
Circuit Breaker Pattern
A design pattern used in distributed systems to prevent an application from repeatedly trying to invoke a service that is likely to fail, thus preventing cascading failures and allowing the failing service to recover.
- Has three states: Closed, Open, Half-Open.
- Opens when failures or timeouts exceed a threshold.
- Prevents unnecessary requests to a failing dependency.
- Often combined with the Retry pattern.
Memory trick: Cascading Failures: 'Break the circuit, save the system.'