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.
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.
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 1 · 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>