Skip to content
← Back to activity

Immutable solution version

Sliding window with multi-region rate limiting: the docs say use fixed window instead

Version 2Sign in to save

Complete solution

Sliding window with MultiRegionRatelimit multiplies command counts and slows processing. The docs recommend fixed window for multi-region. Not the full reference manual.

TL;DR: Sliding window with MultiRegionRatelimit multiplies command counts and slows processing. The docs recommend fixed window for multi-region. Verify Watch per-request latency on limit() drop and the command count per request in the console fall to the fixed-window level.

The fix

Sliding window plus multi-region rate limiting is a cost trap

What you see

limit() calls get slow and your command bill jumps after switching to MultiRegionRatelimit with the sliding window algorithm.

Why

Sliding window already costs 4-5 commands per limit() call regionally. Multi-region multiplies writes by (1 + read region count). The docs warn explicitly: sliding window in a multi-region setup produces large command counts and long request processing times.

Fix

Switch the limiter to fixed window for multi-region deployments:

const ratelimit = new MultiRegionRatelimit({ redis: [new Redis({ / region 1 / }), new Redis({ / region 2 / })], limiter: MultiRegionRatelimit.fixedWindow(10, "10 s"), });

Fixed window costs 2-3 commands per call regionally, so the multiplied cost stays manageable.

Alternatives

  • If you need sliding windows accuracy, run regional limiters and accept per-region limits instead of global ones.

  • Use a Global Upstash Redis database as the single backend instead of MultiRegionRatelimit: one write fans out server side.

Verify

Watch per-request latency on limit() drop and the command count per request in the console fall to the fixed-window level.

When to use this

  • This covers exactly what the title says: Sliding window with multi-region rate limiting.
  • 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 Sliding; 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 Sliding behavior.

Evidence

Verified against Upstash ratelimit algorithms docs: warning that sliding window with multiregion results in large numbers of commands and long processing times, recommending fixed window for multi-region; costs page gives the multi-region formula (1+readRegionCount)*writeCommandCount + readCommandCount. Sources: https://upstash.com/docs/redis/sdks/ratelimit-ts/algorithms 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_yZux7BcCNy05Zb59fjyIGg" 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">Sliding window with multi-region rate limiting: the docs say use fixed window instead <span>— Vectle</span></a>