Skip to main content

Rate Limiting

To ensure fair API usage and protect system performance, the Riyadh Parking API enforces rate limits. Understanding and managing these limits is essential for maintaining a stable and reliable integration.
Rate limits help prevent excessive API requests, ensuring a fair distribution of resources among users.

1️⃣ Understanding Rate Limits

The API applies different rate limits depending on the endpoint and user role:
Request TypeLimit (Requests per Minute)
Authentication20
Site Management30
Visitor Permits50
Violations20
Ticket Validation40
If an application exceeds these limits, the API will return an HTTP 429 Too Many Requests response.

2️⃣ Handling Rate Limits

Check Remaining Request Quota

Every API response contains headers indicating the current usage:
X-RateLimit-Limit: 50   # Total requests allowed per minute
X-RateLimit-Remaining: 10  # Remaining requests in the current window
X-RateLimit-Reset: 1672531200  # Time (UNIX) when the limit resets

Handling 429 Errors Gracefully

Implement retry logic with exponential backoff:
function fetchWithRetry(url, retries = 3, delay = 1000) {
  return fetch(url).then(response => {
    if (response.status === 429 && retries > 0) {
      const retryAfter = response.headers.get("Retry-After") || delay;
      return new Promise(resolve => 
        setTimeout(() => resolve(fetchWithRetry(url, retries - 1, delay * 2)), retryAfter * 1000)
      );
    }
    return response.json();
  });
}

3️⃣ Best Practices for Rate Limit Optimization

  • Cache API responses: Reduce redundant requests by storing frequently accessed data.
  • Use pagination: When retrieving large datasets, request smaller chunks at a time.
  • Distribute requests: Spread API calls across different time intervals instead of sending them all at once.
For high-traffic applications, consider contacting support for custom rate limit adjustments.