Plaid API Rate Limit Handling
This document outlines the rate limit handling strategy implemented across the Portfolio Tracker application for Plaid API integration.Rate Limit Context
Plaid enforces two types of rate limits that we need to accommodate:- Per-Item Rate Limit: 5 requests per minute per item
- Global Client Rate Limit: 1,200 requests per minute across all items
Implementation Strategy
Our implementation uses a hybrid approach of proactive prevention and reactive handling to manage rate limits effectively.1. Routes with Rate Limit Protection
Rate limit handling has been implemented in the following routes:/app/api/fetch-balances/route.ts- User-triggered balance updates/app/api/connect-bank/route.ts- Initial bank connection/app/api/relink/route.ts- Account re-authentication/app/api/cron/schedule-portfolio-briefs/process-portfolio-brief/route.ts- Portfolio brief generation/app/api/cron/daily-snapshots/route.ts- End-of-day snapshots/app/api/plaid/webhook/route.ts- Webhook processing
2. Rate Limit Detection
We detect rate limits through multiple signals:3. Prevention Strategies
3.1 Global Delay Between Requests
- 240 requests per minute (60,000ms ÷ 250ms)
- Well below Plaid’s 1,200/minute global limit
3.2 Staleness Checks
Before making API calls, we check if the data is already recent enough:- User-Triggered Updates: Uses client-side Map to track last update time with 60-second window
- Portfolio Brief: Checks if balance was updated in last 30 minutes
- Daily Snapshots: Checks if balance was updated today
4. Reactive Strategies
4.1 Fixed Retry with Backoff (Daily Snapshots)
4.2 Exponential Backoff with Jitter (Portfolio Brief)
5. ITEM_LOGIN_REQUIRED Handling
When we detect an expired item (credentials need updating):Effectiveness
This hybrid approach ensures:- Per-Item Limit: Handled by appropriate delays between retries
- Global Limit: Managed by small delays between all requests
- Expired Items: Properly marked in database for user notification