Rate Limiter

Motivation

Design

Locations where the rate limiter can live:

Rate limiting could just be done with API gateway but if you were creating it from scratch it might look a bit like this:

Redis
Redis
Limiter Rules
Limiter Rules
Lambda
Lambda
S3
S3
Lambda
Lambda

429 
429 
API
API

SQS 
SQS...
Text is not SVG - cannot display

Implementation

Lots of different algorithms e.g. TokenBucket. When implementing also consider whether to use:

Where to store counters?

Rate Limiting

Reject throttled requests with HTTP 429 too-many-reqests

Headers

Provide information to client via headers:

  • X-Ratelimit-Remaining number of remaining requests in window
  • X-Ratelimit-Limit total number of requests allowed in a window
  • X-Ratelimit-Retry-After when current throttling stops

Algorithms