# Rate Limiting

The controlled restriction of how many operations an actor may perform within a defined scope and time window.

- Type: practice
- Domain: Engineering & architecture
- Level: Intermediate
- Last reviewed: 2026-09-24
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/rate-limiting/>)

## What it means

Rate limiting meters requests or resource use against a rule and delays or rejects activity beyond the allowance. Limits may apply per user, tenant, credential, endpoint, cost unit, or service and can use fixed windows, sliding windows, token buckets, or similar algorithms. Throttling is often used as a broader name for controlling consumption.

## Why it matters

Limits protect shared capacity, preserve fairness, contain accidental loops, and make commercial quotas enforceable. Because limits can block legitimate users and integrations, they are also part of the product contract and need understandable feedback and recovery behavior.

## When to use it

Use rate limits at scarce or expensive boundaries, public APIs, multi-tenant workloads, and abuse-sensitive actions. Choose scope and allowance from capacity and user needs. Rate limiting complements rather than replaces authentication, authorization, autoscaling, and denial-of-service protection.

## How it works

1. Choose the protected resource, accountable actor, unit of cost, and time horizon.
2. Select an algorithm whose burst and fairness behavior matches the product need.
3. Count accepted consumption consistently across the instances enforcing the limit.
4. Allow, delay, or reject the request and return clear limit and retry information.
5. Separate quotas where user value or workload cost differs materially.
6. Monitor rejection rates, saturation, false positives, bypasses, and downstream health.

## A practical example

An analytics API assigns each workspace a sustained query allowance with a small burst capacity. When exceeded, it returns HTTP 429 and a retry delay. Expensive exports consume more cost units than lightweight metadata reads.

## Where it breaks

Distributed counters trade accuracy, latency, and availability. A single coarse limit can punish efficient users or fail to protect the actual bottleneck. Limits can also create synchronized retries and confusing experiences if clients lack visible remaining capacity and retry guidance.

## Common mistakes

- Applying one global request count to operations with very different costs.
- Returning unexplained errors without a stable actor scope or retry guidance.
- Assuming rate limiting alone provides authentication or volumetric attack protection.
- Ignoring bursts and distributed counter behavior when choosing an algorithm.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/rate-limiting/#visualization-rate-limiting>)

## Sources

1. [RFC 6585: Additional HTTP Status Codes](<https://www.rfc-editor.org/rfc/rfc6585.html#section-4>) — Internet Engineering Task Force · Internet standard
2. [Throttling Pattern](<https://learn.microsoft.com/en-us/azure/architecture/patterns/throttling>) — Microsoft Learn · Institutional architecture guide

## Related topics

- [Application Programming Interface \(API\)](<https://wiki.soroush.uk/topic/application-programming-interface/>)
- [API Gateway](<https://wiki.soroush.uk/topic/api-gateway/>)
- [Service-Level Objective](<https://wiki.soroush.uk/topic/service-level-objective/>)
