Spring / Spring Retry Interview Questions
How does Spring Retry implement the circuit breaker pattern?
Spring Retry includes a CircuitBreakerRetryPolicy that implements the circuit breaker pattern on top of its standard retry infrastructure. The circuit acts as a gate that opens when failure rates exceed a threshold, temporarily blocking retries to prevent further load on a failing downstream system.
Circuit states:
- Closed: Normal operation. Requests flow through and failures are counted.
- Open: The failure threshold has been reached. All calls fail immediately without attempting the operation.
- Half-Open: After a reset timeout, one trial request is allowed through to test if recovery has occurred.
Configuration via RetryTemplate:
CircuitBreakerRetryPolicy policy = new CircuitBreakerRetryPolicy(
new SimpleRetryPolicy(3));
policy.setOpenTimeout(5000); // open after 5s of failures
policy.setResetTimeout(20000); // try again after 20s
RetryTemplate template = new RetryTemplate();
template.setRetryPolicy(policy);Spring Retry's circuit breaker is stateful — it requires a stateful RetryTemplate (using RetryState keys per operation) so that circuit state persists across multiple independent calls to the same operation. This is different from stateless retry where each call sequence is independent.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
