Immutable solution version
Ratelimit analytics undercounting: the dropped pending promise on serverless
Complete solution
Ratelimit analytics undercount when the pending promise is dropped on serverless. Analytics writes happen after limit() returns. Not the full reference manual.
TL;DR: Ratelimit analytics undercount when the pending promise is dropped on serverless. Analytics writes happen after limit() returns. Check that analytics: true is actually set on the production limiter instance. Check whether the code destructures and awaits pending: const { success, pending } = await ratelimit.limit(id); context.waitUntil(pending); If pending is ignored, that is the cause.
The fix
Diagnosing missing @upstash/ratelimit analytics
Symptom
The Ratelimit dashboard shows far fewer requests than your traffic, or blocked-request counts do not match your 429 logs.
Cause
With analytics: true, every limit() call fires a ZINCRBY after the verdict is returned. On serverless runtimes the function can end before that write lands. The verdict reached the user, the analytics write did not. Result: systematic undercounting, worse on high-churn serverless with short-lived instances.
Confirm
Check that analytics: true is actually set on the production limiter instance.
- Check whether the code destructures and awaits pending:
const { success, pending } = await ratelimit.limit(id); context.waitUntil(pending);
If pending is ignored, that is the cause.
Compare dashboard totals against your edge access logs for the same window. A consistent ratio (like 60% of traffic recorded) points at dropped background writes, not at a filter.
Fix
Wire pending into waitUntil on every platform (Cloudflare context.waitUntil, Vercel Functions waitUntil).
Verify
Dashboard totals converge with access-log totals within a few percent over the next hour of traffic.
When to use this
- This covers exactly what the title says: Ratelimit analytics undercounting.
- You are setting this up for the first time, or auditing an existing setup.
- You want the key gotchas in one place before you start.
When not to use this
- You are doing a different workflow with Ratelimit; these steps are specific to the title above.
- You need the full reference docs; this is the short path, not the manual.
Compatibility
- Not pinned to a specific version; follows current Ratelimit behavior.
Evidence
Verified against Upstash ratelimit docs: analytics enabled adds a ZINCRBY per limit call; in serverless the analytics send happens asynchronously after limit() and needs context.waitUntil(pending); the analytics dashboard shows per-identifier stats. Sources: https://upstash.com/docs/redis/sdks/ratelimit-ts/gettingstarted https://upstash.com/docs/redis/sdks/ratelimit-ts/costs
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_2ITU0-OMiVF4bOLg46q4uQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Ratelimit analytics undercounting: the dropped pending promise on serverless <span>— Vectle</span></a>