Skip to content

About

a leakybucket rate limitter implementation in go

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

LEAKY BUCKET RATE LIMITER AND THROTTLER

  • Implemented a simple leaky bucket rate limitter and throttler.

Architecture

client → HTTP handler → Submit() → [bucket: buffered chan] → leak() → outputCh → consumer
                ↑                         (capacity N)         (1/tick)
              429 on full                                     202 on accepted

What is a leaky bucket?

  • It is a rate limitting strategy that takes in the requests at any rate but only lets out the requests at a certain rate.
  • It also rejects all the incoming requests once its buffer is full.

How to run?

go run .

How to test?

go test .

  • To test manually:
    • curl -i -X POST localhost:4444/meow -d '{"name":"a","quote":"hi"}'
    • 40 requests in a burst - for i in $(seq 1 40); do curl -s -o /dev/null -w "%{http_code}\n" -X POST localhost:4444/meow -d '{"name":"a","quote":"hi"}'; done

Design decisions I made

  • The requests are dropped when the bucket is full.
  • OutputCh is unbuffered.
  • HTTP handler returns 202 immediately and the work happens async via the drip.

About

a leakybucket rate limitter implementation in go

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages