---
title: "Distributed API Gateway Rate Limiting: Local vs Redis Counters and Accuracy Trade-offs - API7.ai"
description: "Choose local or shared Redis rate-limit counters by balancing fleet-wide accuracy, latency, dependency risk, and failure behavior."
url: "https://api7.ai/learning-center/api-gateway-guide/distributed-api-gateway-rate-limiting"
---

[Skip to article](#column-content)

Column contentsAPI Gateway Guide

[API Gateway Guide](https://api7.ai/learning-center/api-gateway-guide)

Search this column

01 Gateway Fundamentals

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=fundamentals)[1. What Is an API Gateway? API Gateway Software and Use Cases](https://api7.ai/learning-center/api-gateway-guide/what-is-an-api-gateway)[2. Why Do Modern Architectures Need an API Gateway?](https://api7.ai/learning-center/api-gateway-guide/why-do-modern-architectures-need-api-gateway)[3. Reverse Proxy vs Load Balancer vs API Gateway](https://api7.ai/learning-center/api-gateway-guide/api-gateway-vs-reverse-proxy-vs-load-balancer)[4. API Gateway and Microservices: Decoupling and Traffic Management](https://api7.ai/learning-center/api-gateway-guide/api-gateway-and-microservices)[5. Understanding Core API Gateway Features](https://api7.ai/learning-center/api-gateway-guide/core-api-gateway-features)[6. Open Source vs. Commercial API Gateways: How to Choose the Right One?](https://api7.ai/learning-center/api-gateway-guide/open-source-vs-commercial-api-gateway)[7. API Gateway vs Service Mesh: How to Choose?](https://api7.ai/learning-center/api-gateway-guide/api-gateway-vs-service-mesh)[8. Envoy vs NGINX, Java, and Go for API Gateways](https://api7.ai/learning-center/api-gateway-guide/nginx-vs-envoy-vs-java-vs-go)[9. Core Concepts of API Gateway: Service, Route, Upstream, Plugin, and Consumer](https://api7.ai/learning-center/api-gateway-guide/core-concepts-of-api-gateway)[10. API Gateway Comparison: Apache APISIX vs. Kong vs. Traefik vs. KrakenD vs. Tyk](https://api7.ai/learning-center/api-gateway-guide/api-gateway-comparison-apisix-kong-traefik-krakend-tyk)

02 Gateway Architecture and Design

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=architecture)[11. Deep Dive into API Gateway Architecture: Core Components and Design Principles](https://api7.ai/learning-center/api-gateway-guide/api-gateway-architecture)[12. Choosing the Right API Gateway for Your Architecture](https://api7.ai/learning-center/api-gateway-guide/api-gateway-monolithic-vs-microservices)[13. How to Architect an API Gateway for High Availability (HA)?](https://api7.ai/learning-center/api-gateway-guide/api-gateway-high-availability)[14. API Gateway Plugin Architecture: How to Extend and Customize Your API Gateway](https://api7.ai/learning-center/api-gateway-guide/api-gateway-plugin-system)[15. How Event-Driven Architecture (EDA) Works with API Gateway?](https://api7.ai/learning-center/api-gateway-guide/api-gateway-event-driven-architecture)[16. API Gateway Request Lifecycle Explained](https://api7.ai/learning-center/api-gateway-guide/api-gateway-request-lifecycle-explained)[17. Cloud-Native API Gateway on Kubernetes](https://api7.ai/learning-center/api-gateway-guide/cloud-native-api-gateway-kubernetes)[18. API Gateway Control Plane vs. Data Plane](https://api7.ai/learning-center/api-gateway-guide/api-gateway-control-plane-vs-data-plane)[19. How API Gateways Work with GitOps: Automating API Management](https://api7.ai/learning-center/api-gateway-guide/api-gateway-gitops-integration)[20. How to Perform A/B Testing and Canary Releases with an API Gateway](https://api7.ai/learning-center/api-gateway-guide/ab-testing-canary-release-api-gateway)

03 Gateway Setup and Traffic Handling

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=traffic-protocols)[21. How to Deploy an API Gateway on Kubernetes: Step-by-Step Guide for Engineers](https://api7.ai/learning-center/api-gateway-guide/deploy-api-gateway-on-kubernetes)[22. Hands-on Setup with Apache APISIX API Gateway](https://api7.ai/learning-center/api-gateway-guide/api-gateway-getting-started-guide)[23. API Gateway Auth: OAuth 2.0, JWT & OIDC with APISIX](https://api7.ai/learning-center/api-gateway-guide/api-gateway-authentication-apache-apisix-oauth-jwt-oidc)[24. Mastering Traffic Control: Efficiently Managing API Requests with Gateways](https://api7.ai/learning-center/api-gateway-guide/api-gateway-traffic-control-strategies)[25. Building Reliable API Gateways with Logging and Monitoring](https://api7.ai/learning-center/api-gateway-guide/api-gateway-logging-monitoring-best-practices)[26. Dynamic Routing in API Gateways: Best Practices for Flexible Traffic Management](https://api7.ai/learning-center/api-gateway-guide/api-gateway-dynamic-routing-management)[27. How API Gateways Support WebSocket](https://api7.ai/learning-center/api-gateway-guide/how-api-gateways-support-websocket)[28. API Gateway for GraphQL: Security, Cost, and Caching](https://api7.ai/learning-center/api-gateway-guide/api-gateway-handle-graphql)[29. How API Gateways Handle HTTP/3 QUIC Requests](https://api7.ai/learning-center/api-gateway-guide/api-gateway-http3-quic)[30. How API Gateways Handle MQTT Requests](https://api7.ai/learning-center/api-gateway-guide/api-gateway-mqtt)

04 Gateway Integrations, AI, and MCP

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=ai-mcp)[31. How API Gateways Handle gRPC Requests](https://api7.ai/learning-center/api-gateway-guide/api-gateway-grpc-support)[32. How API Gateways Implement Custom Plugins](https://api7.ai/learning-center/api-gateway-guide/api-gateway-custom-plugins)[33. How API Gateways Integrate with Kafka](https://api7.ai/learning-center/api-gateway-guide/api-gateway-kafka-integration)[34. How to Implement API Aggregation in API Gateways](https://api7.ai/learning-center/api-gateway-guide/api-gateway-api-aggregation)[35. How API Gateways Enable Serverless Architecture](https://api7.ai/learning-center/api-gateway-guide/api-gateway-serverless-architecture)[36. How API Gateways Proxy LLM Requests](https://api7.ai/learning-center/api-gateway-guide/api-gateway-proxy-llm-requests)[37. How API Gateways Enhance MCP Servers](https://api7.ai/learning-center/api-gateway-guide/api-gateway-enhance-mcp-server)[38. MCP Gateway vs MCP Proxy vs AI Gateway vs API Gateway](https://api7.ai/learning-center/api-gateway-guide/ai-gateway-vs-mcp-gateway-vs-api-gateway)[39. What Is an AI Gateway? Architecture and Benefits](https://api7.ai/learning-center/api-gateway-guide/what-is-an-ai-gateway)[40. What Is an MCP Gateway? Architecture, Use Cases & How It Works (2026 Guide)](https://api7.ai/learning-center/api-gateway-guide/what-is-mcp-gateway)

05 Gateway Performance

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=performance)[41. How API Gateway Reduces Latency: Performance Optimization Strategies](https://api7.ai/learning-center/api-gateway-guide/how-api-gateway-reduces-latency)[42. API Gateway Caching Strategy: Comprehensive Analysis and Implementation Guide](https://api7.ai/learning-center/api-gateway-guide/api-gateway-caching-strategy-analysis)[43. How to Optimize API Gateway Load Balancing: Advanced Strategies and Best Practices](https://api7.ai/learning-center/api-gateway-guide/how-to-optimize-api-gateway-load-balancing)[44. How API Gateway Efficiently Handles Large-Scale Traffic: Architecture and Strategies](https://api7.ai/learning-center/api-gateway-guide/how-api-gateway-handles-large-scale-traffic)[45. How to Improve API Gateway QoS: Traffic Classes, Capacity Protection, and SLOs](https://api7.ai/learning-center/api-gateway-guide/api-gateway-quality-of-service)[46. API Gateway Log Storage: Pipelines, Retention, Security, and Cost](https://api7.ai/learning-center/api-gateway-guide/api-gateway-log-storage)[47. API Gateway Timeouts and Retries: Safe Policies and APISIX Configuration](https://api7.ai/learning-center/api-gateway-guide/api-gateway-timeouts-retries)[48. API Gateway Concurrency Control: Capacity Budgets, Backpressure, and Load Shedding](https://api7.ai/learning-center/api-gateway-guide/api-gateway-concurrency-control)[49. Asynchronous API Gateway Patterns: Queues, Callbacks, and Performance Boundaries](https://api7.ai/learning-center/api-gateway-guide/asynchronous-api-gateway-patterns)[50. API Gateway TLS Performance: Handshakes, Session Reuse, and Measurement](https://api7.ai/learning-center/api-gateway-guide/api-gateway-tls-performance)

06 Gateway Security

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=security)[51. DDoS Defense at the API Gateway: Layered Controls and Failure Planning](https://api7.ai/learning-center/api-gateway-guide/api-gateway-ddos-defense)[52. Distributed API Gateway Rate Limiting: Local vs Redis Counters and Accuracy Trade-offs](https://api7.ai/learning-center/api-gateway-guide/distributed-api-gateway-rate-limiting)[53. API Gateway IP Allowlist and Denylist Management: Trust, Proxies, and Operations](https://api7.ai/learning-center/api-gateway-guide/api-gateway-ip-allowlist-denylist-management)[54. API Gateway Security Scanning: What to Test and How to Operationalize Findings](https://api7.ai/learning-center/api-gateway-guide/api-gateway-security-scanning)[55. SQL Injection and XSS at the API Gateway: Detection Limits and Defense in Depth](https://api7.ai/learning-center/api-gateway-guide/sql-injection-xss-api-gateway)[56. API Access Log Auditing: Evidence, Integrity, Retention, and Review](https://api7.ai/learning-center/api-gateway-guide/api-access-log-auditing)[57. Preventing API Scraping and Abuse: Identity, Behavioral Signals, and Rate Controls](https://api7.ai/learning-center/api-gateway-guide/prevent-api-scraping-abuse)[58. API Gateway mTLS: Client Identity, Certificate Rotation, and APISIX Configuration](https://api7.ai/learning-center/api-gateway-guide/api-gateway-mtls)[59. Fine-Grained API Gateway Authorization: RBAC, ABAC, and External Policy Decisions](https://api7.ai/learning-center/api-gateway-guide/fine-grained-api-gateway-authorization)[60. API Gateway and WAF Reference Architecture: Ownership, Header Trust, and Failure Modes](https://api7.ai/learning-center/api-gateway-guide/api-gateway-waf-reference-architecture)

07 Gateway Ecosystem and Comparisons

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=ecosystem)[61. Apache APISIX vs Kong: Migration, Operations, and Team Fit](https://api7.ai/learning-center/api-gateway-guide/apache-apisix-vs-kong)[62. Traefik vs Kong vs APISIX: A Reproducible API Gateway Benchmark Method](https://api7.ai/learning-center/api-gateway-guide/traefik-kong-apisix-benchmark-method)[63. Amazon API Gateway Explained: Deployment Models, Trade-offs, and Use Cases](https://api7.ai/learning-center/api-gateway-guide/amazon-api-gateway-explained)[64. API Gateway and Istio: Clear North-South and East-West Boundaries](https://api7.ai/learning-center/api-gateway-guide/api-gateway-istio)[65. API Gateway with NGINX: Layering, Ownership, and Migration Patterns](https://api7.ai/learning-center/api-gateway-guide/api-gateway-nginx)[66. API Gateway with Envoy: Deployment Patterns and Policy Ownership](https://api7.ai/learning-center/api-gateway-guide/api-gateway-envoy)[67. API Gateway with Cloudflare API Shield: Edge and Origin Security Boundaries](https://api7.ai/learning-center/api-gateway-guide/api-gateway-cloudflare-api-shield)[68. Apigee vs MuleSoft vs Amazon API Gateway: A Decision Framework](https://api7.ai/learning-center/api-gateway-guide/apigee-mulesoft-amazon-api-gateway)[69. Should an API Gateway Connect Directly to a Database? Patterns and Risks](https://api7.ai/learning-center/api-gateway-guide/api-gateway-database-access-patterns)[70. API Gateway Architecture for Large-Scale SaaS Platforms](https://api7.ai/learning-center/api-gateway-guide/api-gateway-large-scale-saas-architecture)

08 Industry Applications and Integrations

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=applications)[71. API Gateway CI/CD: Validation, Promotion, and Safe Rollback](https://api7.ai/learning-center/api-gateway-guide/api-gateway-ci-cd)[72. API Gateways for AI and ML Inference: Traffic, Security, and Observability](https://api7.ai/learning-center/api-gateway-guide/api-gateways-ai-ml-inference)[73. API Gateway Architecture for Financial Services: Controls and Failure Boundaries](https://api7.ai/learning-center/api-gateway-guide/api-gateway-financial-services)[74. API Gateway Architecture for E-Commerce: Checkout Reliability and Traffic Peaks](https://api7.ai/learning-center/api-gateway-guide/api-gateway-ecommerce)[75. API Gateways for Mobile Applications: Authentication, Payloads, and Versioning](https://api7.ai/learning-center/api-gateway-guide/api-gateways-mobile-applications)[76. API Gateways for Web3 Applications: RPC Traffic, Identity, and Abuse Controls](https://api7.ai/learning-center/api-gateway-guide/api-gateways-web3-applications)[77. OpenAPI-Driven API Gateway Operations: Import, Validation, and Drift Control](https://api7.ai/learning-center/api-gateway-guide/openapi-driven-api-gateway-operations)[78. gRPC-Web and gRPC Transcoding Through an API Gateway](https://api7.ai/learning-center/api-gateway-guide/grpc-web-grpc-transcoding-api-gateway)[79. API Gateway Pricing and Cost Optimization: A Workload-Based Model](https://api7.ai/learning-center/api-gateway-guide/api-gateway-pricing-cost-optimization)[80. Evaluating API Gateway Directions: Evidence and Architectural Impact](https://api7.ai/learning-center/api-gateway-guide/api-gateway-trends)

09 Advanced Gateway Applications

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=operations)[81. API Gateways in Zero Trust Architecture: Identity, Policy, and Limits](https://api7.ai/learning-center/api-gateway-guide/api-gateways-zero-trust-architecture)[82. API Gateway Log Analytics: Correlation, Queries, and Operational Signals](https://api7.ai/learning-center/api-gateway-guide/api-gateway-log-analytics)[83. From API Sprawl to Governed Delivery: The Gateway's Role in Modernization](https://api7.ai/learning-center/api-gateway-guide/api-gateway-modernization)[84. API Monetization at the Gateway: Plans, Metering, Entitlements, and Billing Boundaries](https://api7.ai/learning-center/api-gateway-guide/api-monetization-gateway)[85. Safe AI-Assisted API Gateway Optimization: Recommendations, Guardrails, and Approval](https://api7.ai/learning-center/api-gateway-guide/ai-assisted-api-gateway-optimization)[86. API Gateways for Low-Code and No-Code Integration: Governance and Safety](https://api7.ai/learning-center/api-gateway-guide/api-gateways-low-code-no-code-integration)[87. API Gateway and CIAM Integration: Token Validation, Consent, and Identity Context](https://api7.ai/learning-center/api-gateway-guide/api-gateway-ciam-integration)[88. Elastic API Gateway Scaling: Signals, Capacity, and Safe Scale-In](https://api7.ai/learning-center/api-gateway-guide/elastic-api-gateway-scaling)[89. Multi-Tenant SaaS API Gateways: Isolation, Quotas, and Tenant-Aware Policy](https://api7.ai/learning-center/api-gateway-guide/multi-tenant-saas-api-gateway-policy)[90. API Gateway DevSecOps: Policy as Code, Testing, and Runtime Feedback](https://api7.ai/learning-center/api-gateway-guide/api-gateway-devsecops)

10 Platform Engineering and Planning

[View this topic · 10](https://api7.ai/learning-center/api-gateway-guide?topic=platform-governance)[91. API Discovery and Documentation at the Gateway: Inventory, Ownership, and Drift](https://api7.ai/learning-center/api-gateway-guide/api-discovery-documentation-gateway)[92. WebAssembly Plugins for API Gateways: Portability, Isolation, and APISIX Boundaries](https://api7.ai/learning-center/api-gateway-guide/api-gateway-webassembly-plugins)[93. Monitoring API Gateways with Prometheus and Grafana: Metrics, Dashboards, and Alerts](https://api7.ai/learning-center/api-gateway-guide/monitor-api-gateways-prometheus-grafana)[94. API Gateway Reliability Engineering: SLOs, Failure Isolation, and Incident Response](https://api7.ai/learning-center/api-gateway-guide/api-gateway-reliability-engineering)[95. API Gateways for Edge AI Inference: Routing, Constraints, and Observability](https://api7.ai/learning-center/api-gateway-guide/api-gateways-edge-ai-inference)[96. Reducing Cloud Cost with API Gateway Controls: Measurement Before Optimization](https://api7.ai/learning-center/api-gateway-guide/reducing-cloud-cost-api-gateway-controls)[97. Improving API Developer Experience with Gateway Standards and Self-Service](https://api7.ai/learning-center/api-gateway-guide/improving-api-developer-experience-gateway-self-service)[98. API Gateway Change Management: Compatibility, Progressive Delivery, and Rollback](https://api7.ai/learning-center/api-gateway-guide/api-gateway-change-management-rollback)[99. Operating Serverless APIs: Cold Starts, Idempotency, and Asynchronous Handoffs](https://api7.ai/learning-center/api-gateway-guide/operating-serverless-apis-gateway)[100. Planning an API Gateway Roadmap for the Next Five Years](https://api7.ai/learning-center/api-gateway-guide/planning-api-gateway-roadmap-next-five-years)

[API Gateway Guide](https://api7.ai/learning-center/api-gateway-guide)[Gateway Security](https://api7.ai/learning-center/api-gateway-guide?topic=security)

On this page

On this page

- [Key Takeaways](#key-takeaways)

- [Define the Limit You Actually Need](#define-the-limit-you-actually-need)

- [Local and Redis Counters Solve Different Problems](#local-and-redis-counters-solve-different-problems)

  - [Local policy](#local-policy)
  - [Redis policy](#redis-policy)

- [Choose a Stable Key](#choose-a-stable-key)

- [Configure a Shared APISIX Limit](#configure-a-shared-apisix-limit)

- [Decide Failure Behavior Deliberately](#decide-failure-behavior-deliberately)

- [Operate the Shared Counter Safely](#operate-the-shared-counter-safely)

- [Validate Before Production](#validate-before-production)

- [Decision Checklist](#decision-checklist)

- [Summary](#summary)

- [FAQ](#faq)

  - [Does Redis make a distributed rate limit exact?](#does-redis-make-a-distributed-rate-limit-exact)
  - [Can I divide a global limit by the number of gateway nodes?](#can-i-divide-a-global-limit-by-the-number-of-gateway-nodes)
  - [Should rate limiting fail open?](#should-rate-limiting-fail-open)

- [Next Steps](#next-steps)

Article 52

# Distributed API Gateway Rate Limiting: Local vs Redis Counters and Accuracy Trade-offs

API7.ai

September 9, 2026

Use node-local counters when the policy is a fast protective guardrail for each gateway instance and some fleet-level drift is acceptable. Use a shared Redis-backed counter when several gateway instances must enforce one tenant, credential, or route budget. The shared design improves coordination, but it adds a network dependency and forces an explicit decision about what happens when Redis is slow or unavailable.

There is no universally exact distributed limiter. Load-balancer skew, retries, counter windows, clock behavior, autoscaling, and dependency failures all affect what clients observe. Define the business invariant first, then select the counter and failure policy that protect it.

## Key Takeaways

- Local counters are low-latency and failure-isolated, but every gateway instance has independent state.
- Redis counters coordinate a fleet, but Redis latency and availability become part of the request path.
- A stable authenticated identity is usually a fairer key than a source IP.
- Decide fail-open versus fail-closed per route; `allow_degradation` is an availability and security decision, not a tuning shortcut.
- Test scaling, load-balancer skew, counter-store failure, and hot tenants before production.

## Define the Limit You Actually Need

“100 requests per second” is incomplete. Specify all of these:

| Dimension | Example decision                                                          |
| --------- | ------------------------------------------------------------------------- |
| Subject   | Per API credential, consumer, tenant, route, or IP                        |
| Scope     | Per gateway instance, region, or global fleet                             |
| Algorithm | Leaky bucket, token bucket, fixed window, or sliding window               |
| Burst     | Whether short bursts are delayed, accepted, or rejected                   |
| Response  | Status code, response body, and retry guidance                            |
| Failure   | Reject, bypass, or use a local fallback if the counter store fails        |
| Objective | Fairness, cost protection, abuse control, or upstream capacity protection |

A login endpoint may require a conservative, identity-aware abuse limit. A public catalog read may use a local guardrail to keep each gateway healthy. A paid inference endpoint may need a shared tenant quota because accepting requests on every node multiplies spend.

## Local and Redis Counters Solve Different Problems

Apache APISIX's [`limit-req` plugin](https://apisix.apache.org/docs/apisix/plugins/limit-req/) implements a leaky-bucket limiter and documents `local`, `redis`, and `redis-cluster` policies.

### Local policy

With `policy: local`, each APISIX instance maintains its own counters. This avoids a remote lookup and prevents a Redis outage from disabling the limiter. It is a good fit for instance protection and deployments where traffic is predictably partitioned.

The trade-off is scope. If a client is spread evenly across four instances configured for 100 requests per second, the fleet can admit roughly four times the per-instance setting. The exact result depends on distribution and bursts; it is not a guaranteed multiplier. Scaling the fleet also changes aggregate admission unless you recalculate the per-instance rate.

### Redis policy

With `policy: redis`, APISIX instances use shared counter state. This supports a fleet-wide policy for the same key and avoids multiplying a tenant allowance merely because more gateway nodes were added.

Redis is now on the policy path. Network latency, connection limits, authentication, TLS, cluster failover, and hot-key load must be included in the design. A shared counter can improve consistency without becoming mathematically exact under every race and failure condition.

## Choose a Stable Key

The key determines who shares a bucket. Prefer an authenticated API consumer or tenant identifier when the policy represents entitlement. Use source IP only when the trusted proxy chain has already restored the real address and when shared NATs, IPv6 privacy addresses, and mobile networks are acceptable sources of error.

Avoid unbounded attacker-selected keys. A raw query parameter can create high-cardinality counter state and let a caller obtain a new bucket at will. Normalize composite keys, namespace them by environment and route, and define retention or expiration behavior.

## Configure a Shared APISIX Limit

The following illustrative Apache APISIX 3.18 route applies a shared request rate to an authenticated consumer name. Replace the endpoint, credentials, and limits for your environment. Store secrets through your deployment's secret workflow; never commit them.

```
curl "http://127.0.0.1:9180/apisix/admin/routes/report-export" \
  -X PUT \
  -H "X-API-KEY: ${admin_key}" \
  -d '{
    "uri": "/v1/reports/export",
    "plugins": {
      "key-auth": {},
      "limit-req": {
        "rate": 5,
        "burst": 2,
        "key_type": "var",
        "key": "consumer_name",
        "policy": "redis",
        "redis_host": "redis.internal",
        "redis_port": 6379,
        "redis_password": "<managed-secret>",
        "redis_database": 2,
        "redis_timeout": 1000,
        "allow_degradation": false,
        "rejected_code": 429,
        "rejected_msg": "Rate limit exceeded"
      }
    },
    "upstream": {
      "type": "roundrobin",
      "nodes": {"reports.internal:8080": 1}
    }
  }'
```

The example is reviewable configuration, not a production recommendation for the numeric values. The [`limit-req` reference](https://apisix.apache.org/docs/apisix/plugins/limit-req/) is the source of truth for fields supported by your APISIX release. If Redis crosses an untrusted network, configure encryption and certificate verification according to the documented options and your distribution rather than relying on defaults.

## Decide Failure Behavior Deliberately

APISIX documents `allow_degradation: false` as the default. When it is `true`, requests can bypass the plugin if the limiting dependency fails. That can preserve availability, but it removes the intended protection precisely when the policy system is impaired.

Use fail-closed behavior for a hard financial, abuse, or contractual boundary when rejecting is safer than uncontrolled execution. Consider fail-open behavior for a low-risk read path when the limiter is advisory and rejecting all legitimate traffic would cause greater harm. A local emergency fallback may be desirable, but do not assume the plugin automatically provides the fallback semantics you designed; verify the implementation for your release.

Alert on limiter errors separately from ordinary `429` responses. A counter-store outage is an infrastructure incident, while a valid rejection is a policy outcome.

## Operate the Shared Counter Safely

- Isolate counter traffic from unrelated Redis workloads or define explicit capacity and eviction policy.
- Namespace keys by environment, policy, route, and subject to avoid accidental collisions.
- Protect credentials, enable transport security where required, and restrict network access.
- Watch command latency, timeouts, connection saturation, errors, memory, and hot keys.
- Plan Redis maintenance and failover; exercise the configured request behavior during both.
- Version policy changes and roll them out gradually, especially when changing keys or scope.
- Keep response semantics stable so clients know when to slow down.

Do not add retries around every failed counter operation without a budget. Retrying a degraded Redis service can amplify load and increase gateway latency.

## Validate Before Production

The APISIX [rate-limiting tutorial](https://apisix.apache.org/docs/apisix/getting-started/rate-limiting/) demonstrates basic plugin behavior. Extend testing to the topology you will run:

1. Send one identity through one instance and confirm the steady rate and burst behavior.
2. Spread the same identity across all gateway instances and compare local and Redis policies.
3. Add and remove instances while traffic continues.
4. Concentrate traffic on one node to expose load-balancer skew.
5. Stop or delay Redis and verify the chosen fail-open or fail-closed result.
6. Drive many identities plus one hot tenant and observe latency and counter-store saturation.
7. Confirm that rejected requests do not reach the protected upstream.
8. Verify dashboards distinguish `429` policy outcomes from limiter failures.

## Decision Checklist

- Is the limit a per-node safety rail or a fleet-wide business invariant?
- Which authenticated or trusted attribute owns the bucket?
- What burst behavior do legitimate clients require?
- How does scaling change the effective local rate?
- Can the shared store meet the latency and availability budget?
- Should this route fail open or fail closed when counters are unavailable?
- Are secrets, TLS, key namespaces, and store capacity managed?
- Have multi-node, skew, failover, and hot-key tests passed?

## Summary

Local rate limiting is usually the simplest way to protect each API gateway instance. Redis-backed limiting is appropriate when one budget must follow a subject across the fleet. The price of coordination is a new dependency and a more consequential failure policy. Define subject, scope, burst, response, and failure behavior explicitly, then test the whole topology instead of validating one gateway in isolation.

## FAQ

### Does Redis make a distributed rate limit exact?

It provides shared state and improves fleet-wide coordination, but observed behavior can still be affected by algorithm semantics, network failures, races, retries, and topology. Treat it as a defined consistency design, not a universal exactness guarantee.

### Can I divide a global limit by the number of gateway nodes?

Only as an approximation when traffic distribution is predictable. Autoscaling and load-balancer skew change the effective aggregate and per-client experience.

### Should rate limiting fail open?

It depends on the protected operation. Fail closed for hard abuse or cost boundaries when uncontrolled execution is worse; fail open only when availability is the explicit priority and the residual risk is acceptable.

## Next Steps

Use [API gateway concurrency control](https://api7.ai/learning-center/api-gateway-guide/api-gateway-concurrency-control) to bound in-flight work as well as arrival rate. For a managed control plane and enterprise policy workflow, [explore API7 Enterprise](https://api7.ai/enterprise).

[Previous article**DDoS Defense at the API Gateway: Layered Controls and Failure Planning**](https://api7.ai/learning-center/api-gateway-guide/api-gateway-ddos-defense)[Next article**API Gateway IP Allowlist and Denylist Management: Trust, Proxies, and Operations**](https://api7.ai/learning-center/api-gateway-guide/api-gateway-ip-allowlist-denylist-management)

On this page

- [Key Takeaways](#key-takeaways)

- [Define the Limit You Actually Need](#define-the-limit-you-actually-need)

- [Local and Redis Counters Solve Different Problems](#local-and-redis-counters-solve-different-problems)

  - [Local policy](#local-policy)
  - [Redis policy](#redis-policy)

- [Choose a Stable Key](#choose-a-stable-key)

- [Configure a Shared APISIX Limit](#configure-a-shared-apisix-limit)

- [Decide Failure Behavior Deliberately](#decide-failure-behavior-deliberately)

- [Operate the Shared Counter Safely](#operate-the-shared-counter-safely)

- [Validate Before Production](#validate-before-production)

- [Decision Checklist](#decision-checklist)

- [Summary](#summary)

- [FAQ](#faq)

  - [Does Redis make a distributed rate limit exact?](#does-redis-make-a-distributed-rate-limit-exact)
  - [Can I divide a global limit by the number of gateway nodes?](#can-i-divide-a-global-limit-by-the-number-of-gateway-nodes)
  - [Should rate limiting fail open?](#should-rate-limiting-fail-open)

- [Next Steps](#next-steps)
