feat(retry): add retry budget to prevent retry storms#172
Merged
Conversation
Add retry budget functionality to limit total retries across all requests,
preventing cascading failures when a downstream service is struggling.
Features:
- RetryBudget trait for pluggable budget implementations
- TokenBucketBudget: simple token-based budget with deposit/withdraw
- AimdBudget: adaptive budget with multiplicative decrease on exhaustion
- RetryBudgetBuilder for ergonomic budget creation
- BudgetExhausted event for observability
- on_budget_exhausted() callback in builder
Usage:
let budget = RetryBudgetBuilder::new()
.token_bucket()
.max_tokens(100)
.initial_tokens(100)
.build();
let layer = RetryLayer::<MyError>::builder()
.max_attempts(5)
.budget(budget)
.build();
The budget is shared across all service clones, providing global
rate limiting for retries. Successful requests deposit tokens back
into the budget, while each retry attempt withdraws a token.
Closes #171
Contributor
Benchmark ResultsComparing PR branch against
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add retry budget functionality to limit total retries across all requests, preventing cascading failures when a downstream service is struggling.
Features
RetryBudgettrait for pluggable budget implementationsTokenBucketBudget: simple token-based budget with deposit/withdrawAimdBudget: adaptive budget with multiplicative decrease on exhaustionRetryBudgetBuilderfor ergonomic budget creationBudgetExhaustedevent for observability.on_budget_exhausted()callback in builderUsage
How It Works
Arc)This prevents "retry storms" where a failing service gets hammered with retries from many concurrent requests.
Budget Types
Token Bucket
Simple token-based budget. Good for most use cases.
AIMD (Additive Increase Multiplicative Decrease)
Adaptive budget that shrinks when exhausted.
References