Sliding window rate limits in distributed systems

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
- How Grab is accelerating growth with real-time personalization using Customer Data Platform scenarios
- Streamlining Grab's Segmentation Platform with faster creation and lower latency
- Supporting large campaigns at scale
- Automating Multi-Armed Bandit testing during feature rollout
- Trident - Real-time Event Processing at Scale