Customers & growth · Developer marketing

Rate limiting framework

Best for Startup to Growth

LIMITSCOMMSUPGRADESFAIR USAGE

Use it when

Your public API is shared by many developers, one heavy caller can slow it for everyone, and you need fair published limits with a clear way to get more.

Skip it when

  • Your own systems call another vendor's API and you must stay inside its limits. Check peak volume against them with Integration architecture framework.
  • You do not yet know calls, errors and latency per endpoint and per app. Run API usage metrics first, since the limits are set from it.
  • Demand is growing across all callers and the service needs more capacity. Use Product scalability monitoring.
  • You want to charge for each call instead of capping calls. Use Usage-based pricing.
  • Developers already hit limits and need help channels and response times. Use Developer support strategy, which this feeds.

What to apply first and what to use instead are listed below.

Approaches

Fixed window

Each key gets a set number of requests per window, such as an hour, and the count resets when the window ends.

  • Pro It is the simplest to build, and developers can read the count and reset time from each response.
  • Con A caller can send a full window's quota at the end of one window and again at the start of the next.

Sliding window

The count covers the last stretch of time up to each request, so the window moves with the traffic.

  • Pro It removes the double burst at window edges.
  • Con It keeps more state per key, which adds cost and latency to each check.

Token bucket

Each key has a bucket that refills at a steady rate, and each request spends a token, so short bursts pass up to the bucket size.

  • Pro It absorbs brief spikes from normal clients while holding the average rate.
  • Con The burst size and refill rate are harder for developers to reason about than a plain count.

Inputs

  • Traffic by key and endpoint
    Requests, concurrent requests and errors per API key, account and endpoint for the last 30 to 90 days, from gateway logs or API usage metrics.
  • Saturation points
    The resource that runs out first behind each endpoint, such as concurrency, database writes or a downstream service's own limit, from load tests and monitoring.
  • Plans and caller types
    Your pricing tiers and the caller types you serve, such as unauthenticated, signed-in users, apps and enterprise accounts, from the pricing page and contracts.
  • Operation cost
    Relative cost of each operation, with reads, writes, searches and large list calls separated, from profiling or latency by endpoint.
  • Contract commitmentsOptional
    Throughput promised to named customers, from sales and legal.

Steps

  1. Name what each limit protects and set it on the dimension that saturates first, as requests per window, concurrent requests in flight, or weighted points where writes cost more than reads.
  2. Choose the key each limit counts against for each caller type, such as IP address for unauthenticated calls and API key or account for signed-in calls, and set a value per plan below the protected capacity.
  3. Run the proposed limits against the logged traffic, list the keys and endpoints that would have been rejected, and raise any limit that would block normal use.
  4. Define the response at the limit. Reject early with 429, add Retry-After, name the limit and scope exceeded, and send limit, remaining and reset headers on every response.
  5. Publish the limits page with values per plan, the headers, how to retry with exponential backoff and jitter, and each route to more capacity, such as a higher plan or an increase request with its notice period.
  6. Store the limits as configuration you can change without a deploy, alert on rejections by key and endpoint, and review the values each quarter against traffic and capacity.

Output

A rate limit policy for the API plus the public limits page that developers read.

  • Limit name and what it protects
  • Dimension (requests, concurrency or points) and window
  • Key counted (IP, user, API key or account)
  • Value per plan or caller type
  • Algorithm (fixed window, sliding window or token bucket)
  • Response at the limit (status, Retry-After, reason, headers)
  • Route to higher limits and its notice period
  • Owner and next review date

Done when

  • Every public endpoint is covered by at least one named limit with a dimension, key and value per plan.
  • The limits were replayed against logged traffic, and every key they would have blocked is listed with a keep or raise decision.
  • Every rejected request returns 429 with Retry-After and names the limit it exceeded.
  • The public page lists every limit value, the response headers, retry guidance and how to get higher limits.
  • Limits can be changed without a deploy, and rejections alert a named owner.

Measure

Track rejected requests by key and plan, p99 latency at peak, support tickets about limits and requests for higher limits, monthly against the quarter before launch. It worked when peak latency stays within target, rejections fall mostly on a few heavy keys, and limit tickets fall. Rising rejections among normal paying keys mean a value is too low or the page is unclear.

Hypothetical example

Parcelhub, a shipping label API, saw one customer's nightly batch slow label creation for everyone. Logs showed label writes saturated the database before reads did. The team set a token bucket per API key, with writes weighted three points and reads one, and higher values for paid plans. A replay of 60 days of logs showed two normal customers would have been blocked, so their plan values went up. Rejections now return 429 with Retry-After and a reason naming the write limit. The limits page lists each plan's values, shows backoff with jitter, and explains how to request an increase four weeks ahead. Peak latency held within target the next month.

Common mistakes

  • Limiting requests per second when the real bottleneck is concurrency or a costly operation. Set the limit on whatever runs out first.
  • Returning a generic error at the limit. Send 429 with Retry-After and name the limit, so clients back off instead of retrying in a storm.
  • Hiding the limits until developers hit them. Publish the values, headers and upgrade routes before launch.
  • Setting values from capacity alone. Replay them against real traffic so normal customers are not blocked.
  • Hard-coding limits in the service. Keep them in configuration you can change during an incident.

Sources

Show all 4 sources

By company stage

  1. Pre-IdeaNot applicableNo API or product usage exists to limit.
  2. IdeaUsefulBasic limits help protect a prototype but traffic is low.
  3. Early StartupUsefulSimple limits are enough while real usage patterns are still emerging.
  4. StartupCriticalGrowing API usage needs clear limits and upgrade paths to protect cost and revenue.
  5. GrowthCriticalThousands of developers make fair usage and tiered limits essential.
  6. ScaleUsefulLimits exist already and need tuning across products.
  7. EnterpriseUsefulMature platform policies are run by established teams.

Apply first

Nothing. You can start here.

Use instead

  • Integration architecture framework

    Your own systems call another vendor's API and you must stay inside its limits. Check peak volume against them with Integration architecture framework.

  • API usage metrics

    You do not yet know calls, errors and latency per endpoint and per app. Run API usage metrics first, since the limits are set from it.

  • Product scalability monitoring

    Demand is growing across all callers and the service needs more capacity. Use Product scalability monitoring.

  • Usage-based pricing

    You want to charge for each call instead of capping calls. Use Usage-based pricing.

  • Developer support strategy

    Developers already hit limits and need help channels and response times. Use Developer support strategy, which this feeds.

Recommended resources

No sponsored resources on this framework yet. Sponsored listings would be labelled here, never in search.

Progress is not saved until you have an account. Create a free account