Skip to content

Implement Token Bucket Algorithm #5

@shalarewicz

Description

@shalarewicz

Implement a Token Bucket algorithm using TDD which limits requests based on a user's IP address and allows developers to provide the desired CAPACITY and REFILL_RATE (in milliseconds).

The algorithm should consider each request to consume exactly 1 token. It should not consider GraphQL query complexity when limiting requests.

The TokenBucket instance of a RateLimiter limits requests based on a unique user ID.
Whenever a user makes a request the following steps are performed:

  1. Refill the bucket based on time elapsed since the previous request
  2. Update the timestamp of the last request.
  3. Allow the request and remove the requested amount of tokens from the bucket if the user has enough.
  4. Otherwise, disallow the request and do not update the token total.

For more information on implementing a Token Bucket Algorithm see the following resources:

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions