How APIs Work
Rate Limits and Webhooks: Asking vs. Being Told
They Won't Let You Ask Forever
Most APIs cap how fast you can ask. Go over and you get a 429, often with a Retry-After header telling you how long to wait. Good code listens to it.
Do the math before you build. Say the limit is 60 requests a minute and loading your history takes 450 requests. That's 450 ÷ 60 = 7.5 minutes at best. Fine. If it takes 45,000, that's 12.5 hours, and you need a plan that survives being interrupted.
Two Ways to Get New Data
Polling is asking on a schedule. Every 5 minutes is 12 times an hour, 288 requests a day, even when nothing happened. It's simple, and if one check fails the next one can catch up.
A webhook flips it around. You give the vendor an address, and they send you a message when something happens. It's fast and nothing gets wasted. It also has four traps:
| Trap | What good code does |
|---|---|
| Anyone can send to your address | Verifies the vendor's signature before trusting the message |
| The same event arrives twice | Saves by event ID so the second copy changes nothing |
| Events arrive out of order | Uses the event's own time or version, not arrival order |
| Your side was down and you missed some | Runs a scheduled check that fills the gaps |
The last one is the one that gets skipped. Some vendors resend for a while, then quit. If webhooks are your only source, a bad night leaves a permanent hole.
Only need a daily report? Skip webhooks. Pull once a night. Use webhooks when minutes matter, and back them up with a nightly pull.
Your system receives webhooks and was down for two hours overnight. What protects your data?