Rate Limiting

Managing API usage with CrissCross rate limits

Overview

Rate limiting is used to control the number of API requests a merchant can make within a specific period. This ensures system stability, prevents abuse, and maintains high performance across the CrissCross platform. It is essential for merchants to monitor their API usage and implement strategies to manage rate limits effectively.


How Rate Limiting Works

  • Rate Limit Threshold:

    • Exceeding the threshold will result in 429 Too Many Requests responses.
  • Rate Limit Scope:

    • Limits may vary between sandbox and production environments.

Example Rate Limit Error Response

If your requests exceed the rate limit, you will receive a 429 Too Many Requests response. Use the Retry-After header to determine when to retry.

1{
2 "error": {
3 "code": "429",
4 "message": "Too Many Requests",
5 "details": "You have exceeded the allowed rate limit. Please wait before making further requests."
6 }
7}

Handling Rate Limits in Your Integration

  1. Monitor API Usage:

    • Use the CrissCross dashboard to track your API request volume in real-time.
  2. Implement Exponential Backoff:

    • Use exponential backoff when retrying requests to avoid further rate limit violations.
  3. Handle 429 Responses Gracefully:

    • If you encounter a 429 Too Many Requests response, use the Retry-After header to determine when it is safe to retry the request.

Example of Exponential Backoff in JavaScript

1function makeApiCallWithBackoff(url, attempt = 1) {
2 fetch(url)
3 .then(response => {
4 if (response.status === 429) {
5 const retryAfter = response.headers.get('Retry-After') || 1;
6 const waitTime = Math.pow(2, attempt) * 1000; // Exponential backoff
7 console.log(`Rate limit hit. Retrying in ${waitTime / 1000} seconds...`);
8 setTimeout(() => makeApiCallWithBackoff(url, attempt + 1), waitTime);
9 } else {
10 return response.json();
11 }
12 })
13 .then(data => console.log(data))
14 .catch(err => console.error('API call failed:', err));
15}

Best Practices for Managing Rate Limits

  • Batch Requests:

    • Where possible, batch multiple API calls into a single request to minimize usage.
  • Use Caching:

    • Cache responses from the CrissCross API to avoid redundant requests.
  • Monitor Usage Trends:

    • Regularly review your API usage patterns and adjust your implementation to stay within limits.

Conclusion

Rate limiting ensures that CrissCross remains stable and responsive for all merchants. By following best practices, merchants can efficiently manage their API usage, avoid disruptions, and maintain smooth operations across their payment systems.