Rate Limiter 00:00:01 Admit one request and spend one token A reporting API assigns an account a shared allowance. Follow one request from identity verification to the moment a gateway can honestly say how much of that allowance remains. The client sends a request with its key. The load balancer picks one of the gateways. The gateway verifies the caller and finds the rule in its own memory. No call. Redis refills, decides and writes: 42 becomes 41. Allowed. The gateway forwards the request. The answer carries the limit and what is left. Refill, test and decrement belong to one atomic state transition for this key. Only the admitted request goes on to consume the backend's capacity. 00:00:46 Two gateways see the very last place Ninety-nine requests have passed under a limit of one hundred. Two gateways arrive together. Before either saves its result, ask what each gateway believes it has permission to do. One place is left. Two requests arrive at once. Both gateways read 99. Both write 100 and pass. 101 went through. Again one token is left. Both send the script; Redis runs one after the other. A gets the last token. B is refused with a waiting time. Separate reads and writes can admit one hundred and one. Serialize the conditional decision at the shared owner so exactly one concurrent caller spends the last place. 00:01:32 Three gateway counters disagree about the total One caller's requests reach three gateways. Their separate counts are forty, thirty-five and thirty. Predict whether any one gateway can recognize the five requests above the shared allowance. 40, 35 and 30. Each thinks it is far below 100. Each allows 100: three times the limit. With 20 gateways it is 2,000. 33 each. But a caller whose calls all reach gateway 1 is refused after 33. One count in Redis. 40, 35 and 25 pass, the other 5 are refused. A shared atomic counter can enforce the collective hundred in this trace. Independent local slices trade precise allocation for simpler operation and may strand unused capacity. 00:02:23 An expensive write matches two rules A gateway holds rules with explicit priorities. A request may qualify by operation, plan and caller. Work through the matching order before deciding which bucket the gateway should charge. Sorted by priority: 100, 50, 10, 1. The first rule matches: 5 a minute. Not a login, but a write: 100 a minute. 60 a minute. No plan must not match the free plan. The fallback counts by address. Define whether the policy applies the first match or enforces several scopes together. Missing identity and missing plan fields must have deliberate behavior. 00:03:06 The counter stops answering during a busy morning The shared store no longer answers within five milliseconds. Compare a low-risk read under a local fallback with a sensitive operation whose policy requires a current shared decision. Redis answers in a millisecond. The gateway waits 5 ms and stops. After a few failures the breaker opens and it does not even ask. Twice the even share: 2 times 100 divided by 20 equals 10 a minute in this gateway. The login rule says closed: 503 with Retry-After. The breaker tries one call, it works, and the shared count continues. A local allowance can overshoot the global budget when many gateways use it. Surface fallback mode in monitoring and return useful retry guidance when the service must pause.