This API design applies to the Admin user:
There are 2 mains flows, from Admin and User perspectives.
User:
Admin:
The main components are:
High QPS and Fast Decision Path: The rate limit decision must happen in under 5ms to not add significant latency. The entire check runs as a Lua script on Redis, making it atomic and avoiding round-trips. The gateway does NOT query the Rules DB per request — rules are cached locally in memory and refreshed every 5 minutes. This means the fast path is: read rule from local memory, execute Lua script on Redis, return allow/reject. No database involved in the hot path.
Burst Traffic and Local Aggregation: Each gateway instance maintains a local in-memory counter per user. If a user has already been rejected in the last N seconds locally, the gateway rejects immediately without consulting Redis. This serves as a first layer that absorbs burst traffic and reduces Redis load by up to 90% for repeat offenders. Only requests that pass the local check reach Redis.
High Availability and Partial Outages: Redis runs in replica mode with Redis Sentinel for automatic failover — if primary fails, a replica promotes within seconds. If Redis is completely unavailable, gateways fail open (allow requests) and alert the operations team, since blocking all traffic is worse than temporarily exceeding rate limits. The Rules DB has read replicas. If the DB is down entirely, gateways continue using their local cache. Cache misses (new user with no cached rule) fall back to a default rate limit until the cache refreshes.
If Redis and Rules DB are completely unavailable, we have the cache of the API gateway with the responses for the requests.
Configuration Rollout Without Downtime: Admin updates write to the Rules DB. Gateways refresh cache every 5 minutes via polling. For urgent changes, the Admin API publishes an invalidation message via Redis Pub/Sub, forcing all gateways to refresh immediately. Rules propagate gradually — no restart or downtime required.
Handling burst traffic at the gateway: Use a local aggregation and handling traffic using the Load Balancer so we can add more instances at ease.
Handle very high QPS and fast decision paths: Adding more API gateway instances, adding more Redis replicas using Redis Sentinel. Fast decision paths will be related to the cache in the API Gateway that will have the rules for the last 5 minutes.