Estimate the scale of the system you are going to design...
100M DAU -> 100k QPS
Redis come with the TTL
client should connect to api gateway(load balancer) the before each service call it should call rate limiter; rate limiteer connect to redis
Redis should use a single leader replication
client should connect to api gateway(load balancer) the before each service call it should call rate limiter; rate limiteer connect to redis
We; will use a sliding window algorithm, for the rate limiter, the service will maintain a doulbly linked list(thread safe) each add will pop out the old entries. Rate limiter service is stateless, so we can partition it by user id/ip address
We must use a thread safe deque.
in the event fail: because we use a single leader redis, if the leader node failed, another node will automatically became the leader node.
In th worst case what we lost is just a data for a few minutes.
We can have a snapshot for redis