Spring / Spring Retry Interview Questions
What is the difference between retry and idempotency? Why does it matter?
Retry and idempotency are closely related but distinct concepts that must be understood together when designing resilient systems.
Retry is the mechanism of re-executing a failed operation. Idempotency is the property of an operation that guarantees the same result regardless of how many times it is executed with the same input.
The relationship matters because retrying a non-idempotent operation can cause unintended side effects:
- Double charges: Retrying a payment API call that already succeeded on the server but timed out before returning a response will charge the customer twice.
- Duplicate records: Retrying a database insert may create duplicate rows if the original insert succeeded but the acknowledgment was lost.
- Double emails: Retrying a notification service can send the same email multiple times.
Safe operations to retry (naturally idempotent): HTTP GET, HTTP PUT with full resource replacement, database SELECT, idempotent queue dequeues with unique processing keys.
Risky to retry without idempotency guards: HTTP POST, payment debits, external notifications, non-idempotent database writes.
Solutions: Use idempotency keys (a unique request ID sent with each call so the server can detect and deduplicate retries), optimistic locking, or at-least-once processing with deduplication at the consumer side. When using Spring Retry, limit retries to operations that are safe to re-execute, or ensure the downstream system supports idempotent requests.
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...
