0PricingLogin
Go Academy · Lesson

golang.org/x/time/rate

Use the rate limiter.

The rate Package

golang.org/x/time/rate provides a production-ready token bucket Limiter. It is the standard choice for rate limiting in Go.

  • Battle-tested implementation
  • Allow, Wait, and Reserve methods
  • Context-aware

Creating a Limiter

rate.NewLimiter takes a rate (tokens per second) and a burst size. rate.Limit is a float64 of events per second.

limiter := rate.NewLimiter(rate.Limit(10), 5)

All lessons in this course

  1. Token Bucket Concept
  2. golang.org/x/time/rate
  3. Throttling Goroutines
  4. Backoff and Retry
← Back to Go Academy