Grab

Sliding window rate limits in distributed systems

Dec 14, 2023Naveen Kumar Jakuva Premkumar
Sliding window rate limits in distributed systems
SummaryAI, from the source post

This post details the implementation of frequency capping for marketing communications to prevent user information overload and potential spam perception. It addresses two key sub-problems: efficient storage of user segment data and persistent tracking of communications sent per user. For user segment storage, Roaring Bitmaps were chosen over Bloom filters due to better compression, faster set operations, and the ability to handle mixed datasets, with a custom microservice developed to abstract their implementation. For tracking communications, a distributed rate limiter using Redis was implemented. The sliding log rate limiter algorithm was selected for its accuracy, utilizing Redis sorted sets to store request timestamps. Lua scripts were optimized for Redis Cluster mode to ensure atomicity and efficiency of operations like `zcount`, `zadd`, and `zremrangebyscore` for rate limiting decisions and data eviction.

More from the Real-time Personalization Scenarios trail