API Rate Limit Exhaustion

The Problem

Your data source integration hits rate limits, causing slow syncs, partial data ingestion, or complete sync failures.

Symptoms

  • ❌ "429 Too Many Requests" errors

  • ❌ Sync takes 10x longer than expected

  • ❌ Only syncs 500 docs before stopping

  • ❌ Works fine for small datasets, fails for large

  • ❌ Other integrations stop working during Twig sync

Real-World Example

Zendesk API rate limit: 700 requests/minute
Your help center: 2,000 articles

Twig sync attempts:
→ Enumerate all categories: 5 requests
→ List articles in each category: 50 requests
→ Fetch full content for each article: 2,000 requests
→ Total: 2,055 requests

At 700/min max: 3 minute minimum

But:
→ Twig makes 50 concurrent requests/sec (3,000/min)
→ After 700 requests: 429 rate limit
→ Twig backs off 60 seconds
→ Resumes, hits limit again
→ Sync takes 45 minutes instead of 3

Deep Technical Analysis

Rate Limit Types and Granularity

APIs implement multiple layers of rate limiting:

Per-User Limits:

Per-App Limits:

Per-Endpoint Limits:

Burst vs Sustained:

Rate Limit Discovery and Headers

APIs communicate limits via HTTP headers:

Standard Headers (RFCs):

But variations exist:

The Reset Timestamp Ambiguity:

Distributed Rate Limiting

Multiple Twig servers must share quota:

Naive Approach (broken):

Centralized Rate Limiter:

The Race Condition:

Retry and Backoff Strategies

Handling 429 responses requires exponential backoff:

Naive Retry (bad):

Exponential Backoff (better):

Jitter to Prevent Thundering Herd:

The Give-Up Point:

Request Batching and Pagination

Reducing API calls through efficient patterns:

The Pagination Efficiency Problem:

But maximum page size limits:

Batching Where Supported:

Quota Pooling and Reservation

Advanced rate limit management:

The Multi-Data-Source Problem:

Priority-Based Scheduling:

The Cold Start Problem:

Cost vs Speed Tradeoffs

Respecting rate limits reduces sync speed:

The Impatience Problem:

Paid Tiers for Higher Limits:


How to Solve

Implement exponential backoff with jitter + respect Retry-After headers + use Redis for distributed rate limiting + batch requests where possible + use largest page sizes + reserve quota for high-priority updates. See Rate Limit Handlingarrow-up-right.

Last updated