Skip to content

Add rate limiting and retry logic for handling API rate limits #16

@robertolosanno-e2x

Description

@robertolosanno-e2x

Problem

Contentstack has a 10 requests/second rate limit. When using this SDK with Terraform (which makes concurrent requests), we constantly hit 429 errors that cause the whole operation to fail.

The SDK currently just returns "Unhandled StatusCode: 429" instead of handling these errors properly.

This is blocking our Terraform automation. Related issue: labd/terraform-provider-contentstack#3

What we need

  1. Rate limiting - throttle requests to stay under the API limit
  2. Retry logic - automatically retry 429 responses with backoff
  3. Configuration options - let users adjust the limits

Suggested approach

Add these fields to ClientConfig:

RateLimit  float64  // requests per second, default 10
RateBurst  int      // burst size, default 10  
MaxRetries int      // retry attempts, default 3

When a 429 happens, wait and retry with exponential backoff (1s, 2s, 4s, etc).

Example usage

cfg := management.ClientConfig{
    BaseURL:    "https://api.contentstack.io",
    AuthToken:  "token",
    RateLimit:  8.0,  // be conservative
    MaxRetries: 3,
}

This would make the SDK much more reliable for automation tools like Terraform that need to make multiple concurrent requests.

Happy to contribute a PR if this sounds good!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions