Skip to main content

Overview

While global rate limits apply to all requests, per-user rate limits allow you to enforce limits specific to individual users, sessions, teams, or any other identifier.

Using the key Parameter

Pass a key to limit() to create an isolated rate limit for that specific key:
Each unique key gets its own independent rate limit bucket.

Per-User Rate Limiting

The most common pattern is to rate limit actions per authenticated user:

Real Example from Source Code

Here’s the actual example from the Convex Rate Limiter repository:

Per-Session Rate Limiting

For rate limiting based on browser sessions or devices:

Per-Team Rate Limiting

For multi-tenant applications where rate limits apply per team or organization:

Combining with Authentication

Common patterns for authenticated vs anonymous users:

Fallback to Anonymous

Stricter Limits for Anonymous Users

Key Best Practices

Keys should be stable and unique. Good choices:
  • User IDs from your auth system
  • Session IDs
  • Team/organization IDs
  • IP addresses (for anonymous users)
Avoid:
  • Usernames (can change)
  • Email addresses (can change)
  • Display names
If the key comes from user input, validate it:
Each unique key creates a separate rate limit bucket in the database. Be mindful of:
  • How many unique keys you’ll have
  • Whether old keys can be cleaned up
  • Storage implications for high-cardinality keys

Testing Different Keys

From the source code’s test suite:

Next Steps