Search⌘ K
AI Features

Design of a Rate Limiter

High-level design

A rate limiter is a dedicated service that sits between the client and the web server. It evaluates incoming requests against defined rules to decide whether to forward them to the server or block them. The figure below illustrates this interaction. Lyft’s rate-limiting service provides a practical example of how these rules are structured.

YAML
domain: messaging
descriptors:
-key: message_type
value: marketing
rate_limit:
unit: day
request_per_unit: 5

In this example, the unit is set to day and request_per_unit is 5. This rule limits the client to five marketing messages per day.

A request with ID 101, received by one of the web servers
1 / 5
A request with ID 101, received by one of the web servers

Detailed design

The high-level design leaves key questions unanswered:

  • Where are the rules stored?

  • How do we handle rate-limited requests?

Let’s expand the architecture to address these components and explain their roles in detail:

The rate limiter accepts or rejects requests based on throttle rules
The rate limiter accepts or rejects requests based on throttle rules

The detailed design consists of the following components:

  • Rule database: Stores rules defined by the service ...