Hierarchical rate limiting with Redis sorted sets

· 8 min

Recently at work, we ran into this problem:

We needed to send Slack notifications for specific events but had to enforce rate limits to avoid overwhelming the channel. Here’s how the limits worked:

  • Global limit: Max 100 requests every 30 minutes.
  • Category limit: Each event type (e.g., errors, warnings) capped at 10 requests per 30 minutes.

Now, imagine this:

  1. There are 20 event types.
  2. Each type hits its 10-notification limit in 30 minutes.
  3. That’s 200 requests total, but the global limit only allows 100. So, 100 requests must be dropped - even if some event types still have room under their individual caps.

This created a hierarchy of limits: