Always cap the bucket
transcript
A bucket holds three tokens. A tenant has two left. Then ten seconds pass. How many tokens now?
The bucket starts with two tokens. Ten seconds add ten more. But the cap is three.
With the cap, the bucket holds three. A request of five is refused. Without it, the bucket holds twelve. The request of five gets through.
Refill when a request arrives. Cap the tokens at the burst. Then compare with the cost.
A quiet tenant saves up tokens. Then sends a huge burst. The shared service suffers.
A real service keeps one record per tenant. Each record has two numbers. Every command takes constant work.
Say the cost of each command. Allow, burst and peek are constant. Then write the code.
Test a very long quiet time. Test a cost above the burst. Test a tenant seen first time.
Take the smaller number. Full breakdown in the lecture.