Skip to main content
Version: 1.1

go-ratelimit

A production-ready rate limiting library for Go with multiple algorithms, distributed support, and HTTP middleware.

go get github.com/KARTIKrocks/go-ratelimit

What you get​

Five algorithmsToken bucket, leaky bucket, fixed window, sliding window log, sliding window counter
Per-key limitingIndependent limits per user, IP, or API key, with idle cleanup and an LRU key cap
DistributedRedis-backed limiters that share one limit across every instance
HTTP middlewarenet/http middleware with X-RateLimit-* and Retry-After headers
Proxy-aware keysSafe RemoteAddr default, opt-in proxy header handling with a trusted-proxy list
Composite limitsSeveral limits checked together; with the built-in limiters, none is consumed unless all allow
ObservabilityInstrumented wrappers and Prometheus counters in the metrics module
Zero dependenciesThe core package uses only the standard library
Thread safeEvery limiter is safe for concurrent use

Modules​

The repository holds three Go modules, so you only pull in the dependencies you use:

ModuleImport pathDepends on
Coregithub.com/KARTIKrocks/go-ratelimitstandard library only
Redisgithub.com/KARTIKrocks/go-ratelimit/redisstoregithub.com/redis/go-redis/v9
Metricsgithub.com/KARTIKrocks/go-ratelimit/metricsgithub.com/prometheus/client_golang

Where to go next​

Documentation layout​

These guides explain concepts, patterns, and configuration. For exact type signatures, method sets, and struct fields, use pkg.go.dev — it is generated from the source and is always authoritative.

Requirements​

Go 1.27 or later.