Token Bucket Algorithm (original) (raw)

Last Updated : 10 Feb, 2026

The Token Bucket Algorithm is a traffic control method where tokens are added to a bucket at a fixed rate (up to a maximum capacity), and packets can be transmitted only if enough tokens are available.

Need for the Token Bucket Algorithm

Token Bucket is needed because fixed-rate limiting forces traffic to move at a constant speed, while real network traffic is naturally bursty. It provides controlled flexibility so short spikes don’t get blocked, while long-term bandwidth limits are still enforced.

Key Terminology and Parameters

Working

one_token_added_per_tick

Steps Involved in Token Bucket Algorithm

**1. Bucket Creation: A logical bucket with a fixed capacity (rate limit) is defined, representing the maximum number of tokens it can hold.
**2. Token Refill: Tokens are added to the bucket at a constant rate until the bucket reaches its capacity.
**3. Request Arrival: When a request (or packet) arrives, the system checks whether tokens are available.
**4. Token Consumption: If tokens are present, one token is removed, and the request is allowed to proceed. The time of consumption is also recorded.
**5. Bucket Empty: If no tokens remain, incoming requests are denied or delayed. This prevents overload and keeps the system within the defined rate limit.

Flow Characteristics

Token Bucket primarily manages bandwidth and traffic rate, but it indirectly influences other flow characteristics that affect overall network performance.

Blank-diagram-(6)

Token Bucket vs Leaky Bucket Algorithm

Token Bucket Algorithm Leaky Bucket Algorithm
It depends on tokens. It does not depend on tokens.
If bucket is full, token is discarded but not the packet. If bucket is full, then packets are discarded.
Packets can only transmit when there are enough tokens. Packets are transmitted continuously.
Allows large bursts to be sent at faster rate. Bucket has maximum capacity. Sends the packet at a constant rate.
The bucket holds tokens generated at regular intervals of time. When the host has to send a packet , packet is thrown in bucket.
If there is a ready packet , a token is removed from Bucket and packet is send. Bursty traffic is converted into uniform traffic by leaky bucket.
If there is no token in the bucket, then the packet cannot be sent. In practice bucket is a finite queue outputs at finite rate.

Advantages

Disadvantages

Applications