Security

Token Bucket

Description

An algorithm used in packet switched computer networks and telecommunications networks to check that data transmissions, in the form of packets, conform to defined limits on bandwidth and burstiness.

Where to use

  • Rate limiting.

Real World Example

API Gateway gives each user a bucket of 10 tokens. Each request takes 1.

Code Example

class TokenBucket:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Token Bucket')