Problem Statement
Which statement best contrasts Token Bucket and Leaky Bucket?
Explanation
Token Bucket accrues tokens at a steady rate and spends them per request, so brief spikes are allowed as long as tokens exist. This suits user-facing APIs that need snappy feel during small bursts.
Leaky Bucket drains at a fixed pace. It smooths traffic but may queue or drop during spikes. It is common when downstreams demand steady flow.
Code Solution
SolutionRead Only
if(tokens[user]>0){ tokens[user]--; allow(); } else deny();