Skip to content

feat: per-user concurrency limit - #757

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
shinorh247:feature/user-concurrency
Jul 29, 2026
Merged

feat: per-user concurrency limit#757
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
shinorh247:feature/user-concurrency

Conversation

@shinorh247

Copy link
Copy Markdown

Cap the number of in-flight concurrent requests per user/IP across all /api routes to prevent a single identity from exhausting the thread pool or DB connection pool.

Changes:

  • src/middleware/perUserConcurrency.ts (new): createPerUserConcurrencyMiddleware factory + perUserConcurrency singleton. Uses an in-process Map<string,number> counter; decrements on res finish/close; returns HTTP 429 with Retry-After: 1 and standardised error envelope on exceed.
  • src/config/env-schema.ts: MAX_CONCURRENT_REQUESTS_PER_USER env var (default 10)
  • src/index.ts: app.use('/api', perUserConcurrency) before all route handlers
  • .env.example: document MAX_CONCURRENT_REQUESTS_PER_USER
  • README.md: Per-user concurrency limit section
  • tests/perUserConcurrency.test.ts: 22 tests, 100% line coverage, 93% branch

Closes #320

Cap the number of in-flight concurrent requests per user/IP across all
/api routes to prevent a single identity from exhausting the thread pool
or DB connection pool.

Changes:
- src/middleware/perUserConcurrency.ts (new): createPerUserConcurrencyMiddleware
  factory + perUserConcurrency singleton. Uses an in-process Map<string,number>
  counter; decrements on res finish/close; returns HTTP 429 with
  Retry-After: 1 and standardised error envelope on exceed.
- src/config/env-schema.ts: MAX_CONCURRENT_REQUESTS_PER_USER env var (default 10)
- src/index.ts: app.use('/api', perUserConcurrency) before all route handlers
- .env.example: document MAX_CONCURRENT_REQUESTS_PER_USER
- README.md: Per-user concurrency limit section
- tests/perUserConcurrency.test.ts: 22 tests, 100% line coverage, 93% branch

Closes Predictify-org#320
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@shinorh247 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me
greatest0fallt1me merged commit 8272b9a into Predictify-org:main Jul 29, 2026
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

All good — merging. 🚀

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.

Add per-user concurrency limit

2 participants