explaingit

uber-go/ratelimit

4,696GoAudience · developerComplexity · 2/5Setup · easy

TLDR

A tiny Go library from Uber that throttles how fast your program runs a loop or makes requests, using a leaky-bucket algorithm to smooth out bursts into a steady, controlled pace.

Mindmap

mindmap
  root((ratelimit))
    What it does
      Rate limiting
      Leaky bucket
      Steady pacing
    API
      Take function
      Per second cap
      Low overhead
    Tech Stack
      Go
    Audience
      Go developers
      API integrators
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Limit an API client loop to a set number of requests per second without writing your own timer logic.

USE CASE 2

Smooth out bursts in a high-throughput Go service by throttling an internal loop with a single Take() call before each operation.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This is a small Go library, written by the engineering team at Uber, that helps developers control how fast their programs make requests or perform operations. The specific technique it uses is called a leaky-bucket algorithm, which is a well-known method for smoothing out bursts of activity into a steady, controlled pace. You tell the library how many operations per second you want to allow, and before each operation you call a single function called Take. If you are within your allowed rate, Take returns immediately and you proceed. If you are going too fast, Take pauses your program just long enough to bring you back within the limit. This makes it straightforward to add rate limiting to any loop or repeated action without managing timers yourself. The library is intentionally minimal. It was built to have a simple API and low overhead for high-throughput situations. The README notes that for more complex rate-limiting needs, such as allowing short bursts above the limit or more fine-grained control, Go's standard extended library includes a more full-featured alternative. This package focuses on the common case where you just want a clean per-second cap with minimal code.

Copy-paste prompts

Prompt 1
Using uber-go/ratelimit, limit my HTTP client to 50 requests per second by calling Take() before each request in my loop.
Prompt 2
How does uber-go/ratelimit's leaky-bucket algorithm differ from Go's standard x/time/rate limiter, and when should I use each one?
Prompt 3
Add uber-go/ratelimit to my existing Go batch processor so it never exceeds 200 database writes per second.
Open on GitHub → Explain another repo

← uber-go on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.