News for hackers. Stuff that matters.
Re:Scaling your API with rate limiters by ptarjan on Thursday March 30, 2017 @06:16PM (#13999385)
In a token bucket algorithm you don't actually have a separate replenish step, it is baked into the next check you do. Similar to how in the example you linked the removal of the old entries is baked into the check step.

Check out my example: https://gist.github.com/ptarjan/e38f45f2dfe601419ca3af937fff... on line 23 with

    local filled_tokens = math.min(capacity, last_tokens+(delta*rate))
that adds in any tokens that should drip into the bucket since the last check.
Re:Scaling your API with rate limiters by bigdubs on Thursday March 30, 2017 @08:11PM (#14000145)
sorry was thinking of something else.

yeah the algo is pretty standard, what we found is some edge cases get super weird, namely if you check on regular intervals you'll get false positives, vs. bursty calls

https://play.golang.org/p/Ujp7yeFQ3L