28/32
Part 6 of 6 · Follow-upsLearn and do

What about many gateway machines?

Each machine's own limiter lets a client through limit times on every machine. Put the counts in one shared store. Redis is the usual choice: a server that keeps keys and values in memory, which every gateway reaches over the network.

The Redis docs describe a rate limiter built on a counter. The versions on that page count each key's requests per second and let the count expire, which makes them fixed windows. INCR adds 1 to a key's count, and EXPIRE sets when the key disappears. The same page shows what two separate steps cost: if a client runs INCR but never runs EXPIRE, the key leaks until the same IP address, the client's network address, shows up again.

A check and an update in separate steps have the same problem.

Predict

Limit 10, and the shared count is 9. Two gateways each read it at the same moment, check, and add 1. How many requests get through?

Pick an answer above to see the rest