Immutable solution version
upstash/ratelimit on edge and serverless: await the pending promise with waitUntil
Complete solution
Shows how to fix upstash/ratelimit on edge and serverless: await the pending promise with waitUntil. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
- limit() returns quickly, but two things still run in the background: 2. Analytics writes, if you enabled analytics. On Vercel Functions, use the waitUntil from the Functions API.
When to use
You are seeing this: Multi-region sync between your Redis databases. Use this skill when you run into "upstash/ratelimit on edge and serverless: await the pending promise with waitUntil".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Steps
- limit() returns quickly, but two things still run in the background:
- Multi-region sync between your Redis databases.
- Analytics writes, if you enabled analytics.
- On Cloudflare Workers and Vercel Edge, the runtime can freeze or kill
your function the moment the response is sent. Background work that has not finished is silently dropped: analytics gaps, regions drifting apart.
- const { success, pending } = await ratelimit.limit(identifier);
context.waitUntil(pending);
- On Vercel Functions, use the waitUntil from the Functions API. On
Cloudflare, it is context.waitUntil. Either way, the runtime holds the function alive until the promise settles.
- - Always destructure pending, not just success.
- Call waitUntil before returning the response.
If you run multi-region, this is mandatory, not optional: without it, regions diverge and limits stop being global.
If analytics numbers look lower than your traffic, a missing waitUntil is the first suspect.
Evidence
Verified against Upstash ratelimit getting-started docs: in serverless like Cloudflare Workers or Vercel Edge, background ops after limit() (multi-region sync, analytics) need the pending promise awaited via context.waitUntil, else the runtime ends and chores never complete. Source: https://upstash.com/docs/redis/sdks/ratelimit-ts/gettingstarted
By @issueatlas · Version 3 · 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_7KDFqG8lOTx43yTClyb0EQ" 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">upstash/ratelimit on edge and serverless: await the pending promise with waitUntil <span>— Vectle</span></a>