Add rate limiting and retry logic to handle 429 errors#17
Open
robertolosanno-e2x wants to merge 2 commits intolabd:mainfrom
Open
Add rate limiting and retry logic to handle 429 errors#17robertolosanno-e2x wants to merge 2 commits intolabd:mainfrom
robertolosanno-e2x wants to merge 2 commits intolabd:mainfrom
Conversation
- Add configurable rate limiting (RateLimit, RateBurst) - Add automatic retry logic with exponential backoff for 429 responses - Add MaxRetries configuration option - Implement proper 429 error handling in processResponse - Use golang.org/x/time/rate for token bucket rate limiting - Respect server Retry-After headers when provided - Default to conservative 10 req/sec rate limit to comply with API limits - Default to 3 retry attempts with 1s, 2s, 4s, 8s, 16s backoff (capped at 30s) This resolves issues with Terraform and other automation tools that make concurrent requests and frequently hit Contentstack's API rate limits.
Contributor
Author
|
Hi @demeyerthom, And by connecting the TF provider to this SDK locally to check that the rate limit works on a real contenstack project. |
- Remove retry-related fields and functions from client - Move retry logic to terraform provider for better separation - Simplify SDK to focus on rate limiting only
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.
This PR implements rate limiting and automatic retry logic to handle Contentstack's API rate limits (10 requests/second). The current SDK fails immediately when hitting 429 errors, which blocks automation tools like Terraform that make concurrent requests.
Changes implemented:
Rate Limiting Configuration: Added
RateLimit,RateBurst, andMaxRetriesfields toClientConfiggolang.org/x/time/ratefor token bucket rate limitingAutomatic Retry Logic: Added exponential backoff retry mechanism
MaxRetriestimes (default: 3)Retry-Afterheaders when providedEnhanced Error Handling: Improved 429 error handling in
processResponseRationale:
This resolves blocking issues with Terraform and other automation tools that need to make concurrent API requests. Instead of failing immediately on rate limits, the SDK now handles them gracefully with automatic retries, making it much more reliable for production automation workflows.
Fixes #16
Related: terraform-provider-contentstack#3
Retry-AfterheadersThis PR template provides a comprehensive description of the changes, links to the relevant issues, and clearly categorizes the improvements made to the SDK.