Skip to content

K13.7: rate limits shared across serverless instances - #140

Merged
MFrancis-dev merged 1 commit into
mainfrom
fix/shared-rate-limits
Nov 8, 2026
Merged

MFrancis-dev merged 1 commit into
mainfrom
fix/shared-rate-limits

Conversation

@MFrancis-dev

Copy link
Copy Markdown
Owner

Fix 5 from the pre-launch review (abuse).

Problem: lib/server/rateLimit.ts kept counters in memory. On Vercel each instance has its own memory, so floods spread across instances barely hit the limits (quote requests reached 1Click from our IP), and the map was never cleaned.

Fix:

  • rate_limits table (migration 0004): one fixed window per key
  • One atomic INSERT … ON CONFLICT DO UPDATE … RETURNING count per request: new window → 1, otherwise +1, refused past the limit
  • All five limited routes switched (fund quote, plan preview, onboard, storage check, demo start)
  • cleanupDemo also drops counters older than a day

Tests: 5 new (limit, window reset, per-key, burst of 8 against a limit of 5 gives exactly 5 allowed, cleanup). 146 total.

Docs: README status, ARCHITECTURE §5 and §7, ESSENTIALS, ROADMAP.

Closes #133

Counters lived in each instance's memory, so on the hosted app the limits
barely applied, and the map never shrank.

Closes #133
@MFrancis-dev
MFrancis-dev merged commit f2c16a8 into main Nov 8, 2026
4 checks passed
@MFrancis-dev
MFrancis-dev deleted the fix/shared-rate-limits branch November 8, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

K13.7 Shared rate limits across serverless instances

2 participants