Home▸Articles▸Cybersecurity

API Gateway Token-Bucket Rate Limiter: Protecting Against Credential Stuffing Attacks

A fundamental concept in cybersecurity, the token-bucket rate limiter ensures that API gateways can handle legitimate requests while mitigating malicious ones.

mysimulator teamUpdated June 2026≈ 3 min read▶ Open the simulation

What the Token-Bucket Rate Limiter Is

A token-bucket rate limiter is a mechanism used in network security, particularly at API gateways, to control the rate of incoming requests. It operates by maintaining a bucket that can hold tokens representing allowed request rates.

The bucket refills over time according to a specified refill rate and drains as each legitimate request consumes one token. This ensures that only a certain number of requests can be processed within any given period.

Why It Happens

Credential stuffing attacks exploit weak or reused passwords by sending large volumes of login attempts to multiple accounts, overwhelming the system and potentially bypassing security measures.

The token-bucket rate limiter prevents such attacks by limiting the number of requests that can be processed in a short period, thereby protecting the backend from being overwhelmed.

live demo · related simulation● LIVE

How It Works

When an attack occurs, tokens are consumed faster than they can be refilled. This leads to a situation where legitimate login attempts may not have enough tokens to proceed, thus limiting the number of successful logins.

By adjusting parameters such as refill rate and backend capacity, system administrators can fine-tune the rate limiter to effectively manage both attack rates and legitimate user traffic.

Real-World Applications

Token-bucket rate limiters are widely used in various applications, including financial services, e-commerce platforms, and social media sites. They help prevent denial-of-service (DoS) attacks and ensure that the system remains responsive to legitimate users.

For instance, a bank might use this mechanism to protect its online banking portal from being flooded with login attempts, ensuring that only genuine customers can access their accounts.

Frequently asked questions

How does the token-bucket rate limiter handle bursts of legitimate traffic?

The bucket refills over time according to a specified refill rate. During periods of high legitimate traffic, tokens are consumed faster but will eventually be replenished as long as the overall request rate remains within the allowed limit.

Can the token-bucket rate limiter distinguish between different types of requests?

No, the token-bucket mechanism treats all incoming requests equally. It does not differentiate between attack traffic and legitimate traffic based on content or origin; it only limits the overall request rate.

What happens if the bucket is empty during an attack?

If the bucket is empty, no more tokens are available for legitimate requests, effectively blocking them until new tokens can be added through refilling. This helps mitigate the impact of the attack on the system.

How does adjusting the refill rate affect the system's performance?

A higher refill rate allows more tokens to be available for legitimate requests, potentially reducing the number of blocked login attempts but may also allow more attack traffic through. Conversely, a lower refill rate can better protect against attacks at the cost of blocking some legitimate users.

Try it live

Everything above runs in your browser — open API Gateway Token-Bucket Rate Limiter (2D) and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open API Gateway Token-Bucket Rate Limiter (2D) simulation

What did you find?

Add reproduction steps (optional)