Rate limiting is one of the most underrated pieces of infrastructure. Whether you are protecting a public API from abuse, preventing brute-force login attempts, or ensuring fair resource allocation across tenants, a good rate limiter sits between your users and your services — and you want full control over it.
Commercial API gateways charge by the request. Cloud WAFs add rate limiting as a premium feature. But every tool you need to throttle, shape, and police API traffic is available as open-source software you can run on your own hardware.
Why Self-Host Your Rate Limiting
Running your own rate limiting layer gives you advantages that managed services cannot match:
- No per-request pricing — Cloud rate limiting costs scale with your traffic. Self-hosted solutions cost the same whether you handle 1,000 or 10 million requests per day.
- Custom policies — You are not locked into predefined tiers or fixed windows. Write per-endpoint, per-user, per-IP, or even per-header rules that match your exact business logic.
- Data stays on your infrastructure — Rate limiting decisions require inspecting every request. With a self-hosted solution, request metadata never leaves your network.
- Works alongside any backend — Whether your services run on bare metal, kubernetes, or a mix of both, these tools slot in front of them without requiring code changes.
- Defense in depth — Rate limiting is not just about abuse prevention. It protects your database connection pools, prevents cascading failures during traffic spikes, and gives you time to auto-scale before things break.
The four solutions covered here — Nginx, Traefik, Envoy, and Kong — all handle rate limiting, but they approach it differently. Each excels in specific scenarios.
Nginx: The Simple, Battle-Tested Choice
Nginx has been the default reverse proxy for over a decade. Its rate limiting is built on a leaky bucket algorithm backed by a shared memory zone. It is simple, fast, and handles millions of requests per second on modest hardware.
How Nginx Rate Limiting Works
Nginx uses two directives:
limit_req_zone— Defines a shared memory zone and the key to track (usually$binary_remote_addrfor per-IP limiting).limit_req— Applies the rate limit within a location or server block.
The shared memory zone is a fixed-size slab allocated at startup. Each unique key gets an entry with a timestamp. Nginx checks timestamps against the configured rate and either passes the request, delays it, or rejects it with a 503.
docker Setup
| |
Configuration Example
| |
Advanced: Nginx Plus Dynamic Rate Limiting
If you can run Nginx Plus (commercial), you get dynamic zone resizing via the API:
| |
For the open-source version, you must reload Nginx to change rates.
When to Use Nginx for Rate Limiting
- You already run Nginx as your reverse proxy
- You need per-IP or per-header rate limiting with burst support
- Your requirements are straightforward: fixed windows, leaky bucket, simple keying
- You want the lowest possible latency overhead (Nginx adds sub-millisecond latency)
Nginx does not natively support sliding window counters, distributed rate limiting across multiple nodes, or dynamic rules based on upstream response codes. For those, you need something more advanced.
Traefik: Rate Limiting for Dynamic Environments
Traefik is a cloud-native edge router designed for dynamic infrastructure. Its rate limiting is configured as middleware and works seamlessly with Docker, Kubernetes, and service mesh setups.
How Traefik Rate Limiting Works
Traefik uses a fixed-window counter approach with configurable time windows. Unlike Nginx’s per-request delay model, Traefik simply counts requests within each window and rejects anything over the limit. This makes it easier to reason about but less flexible for burst handling.
Traefik supports multiple middleware strategies:
- IPWhiteList / RateLimit — Basic per-IP limiting
- Plugins — Extended rate limiting via community plugins (sliding window, token bucket, etc.)
- ForwardAuth integration — Delegate rate limiting decisions to an external service
Docker Setup
| |
Configuration
traefik.yml (static config):
| |
dynamic.yml (dynamic config with rate limiting):
| |
Kubernetes Ingress Example
| |
When to Use Traefik for Rate Limiting
- You run services in Docker or Kubernetes and want rate limiting that auto-discovers backends
- You prefer configuration via Docker labels or Kubernetes CRDs
- You need Let’s Encrypt TLS automation built in
- Your rate limiting needs are moderate (fixed windows are sufficient)
Traefik’s built-in rate limiting is less granular than Nginx or Kong. The real power comes from its plugin ecosystem, where you can add sliding window algorithms, Redis-backed distributed counters, and more.
Envoy: Distributed Rate Limiting at Scale
Envoy is a high-performance service proxy originally built by Lyft. It is the data plane for Istio service mesh and powers the edge routing at companies like Airbnb, Dropbox, and Stripe. Its rate limiting architecture is fundamentally different from Nginx or Traefik.
How Envoy Rate Limiting Works
Envoy separates the rate limiting decision from the proxy itself. The proxy sends rate limit check requests to a dedicated Rate Limit Service (RLS), which can be any gRPC service that implements the Envoy RLS protocol. The reference implementation is envoyproxy/ratelimit, a Redis-backed service.
This architecture means:
- Rate limiting state is centralized in Redis, so multiple Envoy instances share the same counters
- You can implement arbitrary algorithms (fixed window, sliding window, token bucket) in the RLS
- You can change rate limits at runtime by updating the RLS configuration without touching the proxy
Docker Setup
| |
Envoy Configuration
| |
Rate Limit Service Configuration
Create ratelimit-config/config.yaml:
| |
When to Use Envoy for Rate Limiting
- You run a microservice architecture with multiple proxy instances
- You need distributed, consistent rate limiting across all nodes
- You want sliding window or token bucket algorithms backed by Redis
- You are already using Envoy or Istio
- You need runtime-configurable rate limits without restarts
Envoy’s architecture is the most powerful of the four options but also the most complex. The separation between proxy and RLS means more moving parts to manage. It is the right choice when you are operating at scale with dozens or hundreds of service instances.
Kong: The Full API Management Platform
Kong is built on top of Nginx and Lua, but it adds a plugin ecosystem, a REST API for configuration, and a database-backed configuration store. Its rate limiting plugin is one of the most feature-complete available.
How Kong Rate Limiting Works
Kong provides multiple rate limiting plugins:
- Rate Limiting — Fixed-window counter per consumer, per IP, per service, or per route
- Rate Limiting (Advanced) — Sliding window with configurable time windows, supports Redis cluster for distributed state
- Request Size Limiting — Rejects requests over a maximum body size
- Request Termination — Blocks specific IPs or user agents entirely
All plugins can be applied at three levels: globally, per-service, or per-route. This gives you fine-grained control over which endpoints are rate limited and how.
Docker Setup
| |
Configuration via Admin API
| |
Declarative Configuration (DB-less Mode)
For simpler deployments, Kong can run without a database using a declarative config file:
| |
Start Kong in DB-less mode:
| |
When to Use Kong for Rate Limiting
- You need a full API management platform (rate limiting, authentication, transformation, logging) in one tool
- You want to manage configuration via REST API or declarative YAML
- You need per-consumer rate limiting tied to API keys or JWT tokens
- You want built-in observability with Prometheus metrics
- You need the flexibility of Nginx plus a plugin ecosystem
Kong’s main trade-off is resource usage. Running PostgreSQL for configuration adds overhead compared to Nginx or Traefik. In DB-less mode, this is less of a concern, but you lose dynamic configuration updates.
Feature Comparison
| Feature | Nginx | Traefik | Envoy | Kong |
|---|---|---|---|---|
| Algorithm | Leaky bucket | Fixed window | Any (via RLS) | Fixed / Sliding window |
| Distributed state | No (per-node) | No (per-node) | Yes (Redis-backed) | Yes (Redis cluster) |
| Per-IP limiting | Yes | Yes | Yes | Yes |
| Per-consumer limiting | Manual (via header) | Via middleware | Via RLS descriptor | Native (API key / JWT) |
| Burst handling | Yes (burst + nodelay) | Yes (burst param) | Via RLS logic | Yes (burst param) |
| Runtime config changes | No (reload required) | Yes (hot reload) | Yes (RLS config update) | Yes (Admin API) |
| Custom response codes | Yes (429) | Yes (429) | Yes (configurable) | Yes (429) |
| Dashboard / GUI | No | Built-in | Admin interface | Kong Manager |
| Kubernetes support | Ingress annotations | Native CRDs | Envoy Gateway | Kong Ingress Controller |
| Setup complexity | Low | Low | High | Medium |
| Resource usage | Minimal | Low | Medium | Medium-High |
| Plugin ecosystem | Limited | Growing | Extensive | Extensive |
| Best for | Simple, high-performance | Docker/K8s environments | Microservices at scale | Full API management |
Choosing the Right Solution
The best rate limiter depends on what you are protecting and how you operate.
For a single server or small cluster, Nginx is hard to beat. It adds virtually no latency, the configuration is straightforward, and it handles everything you need for per-IP rate limiting. If you already run Nginx as your reverse proxy, there is zero reason to add another component.
For Docker or Kubernetes environments where services come and go, Traefik’s auto-discovery and label-based configuration save hours of manual setup. The rate limiting is not as sophisticated as Envoy or Kong, but it is more than adequate for most APIs and internal services.
For microservice architectures with many proxy instances, Envoy’s distributed rate limiting is the only choice that gives you globally consistent counters. If you are running Istio or planning to, Envoy is already your data plane — just add the RLS.
For organizations that want a complete API management platform, Kong offers rate limiting alongside authentication, request transformation, response caching, logging, and monitoring. It is the most feature-complete option, and its Admin API makes it easy to integrate rate limiting into CI/CD pipelines or internal tooling.
A practical migration path many teams follow: start with Nginx for basic rate limiting, move to Traefik when container orchestration becomes necessary, adopt Envoy when distributed counters become a requirement, and layer Kong on top when API management needs grow beyond simple rate limiting.
Whichever tool you choose, the most important step is to actually deploy rate limiting before you need it. The time to set up login brute-force protection is not during the brute-force attack.
Frequently Asked Questions (FAQ)
Which one should I choose in 2026?
The best choice depends on your specific requirements:
- For beginners: Start with the simplest option that covers your core use case
- For production: Choose the solution with the most active community and documentation
- For teams: Look for collaboration features and user management
- For privacy: Prefer fully open-source, self-hosted options with no telemetry
Refer to the comparison table above for detailed feature breakdowns.
Can I migrate between these tools?
Most tools support data import/export. Always:
- Backup your current data
- Test the migration on a staging environment
- Check official migration guides in the documentation
Are there free versions available?
All tools in this guide offer free, open-source editions. Some also provide paid plans with additional features, priority support, or managed hosting.
How do I get started?
- Review the comparison table to identify your requirements
- Visit the official documentation (links provided above)
- Start with a Docker Compose setup for easy testing
- Join the community forums for troubleshooting