Distributed Rate Limiter

bucketdist

A high-performance distributed rate limiting library for Go that implements a hybrid token bucket algorithm using both local and remote token storage.

Features

Use Cases

Performance

$ go test -bench=. -benchmem -benchtime=5s
goos: darwin
goarch: arm64
pkg: github.com/yourusername/bucketdist
cpu: Apple M1
BenchmarkRateLimit-8   	24807210	       233.4 ns/op	       0 B/op	       0 allocs/op
PASS

Installation

go get github.com/yourusername/bucketdist
package main

import "github.com/flaticols/bucketdist"

func main() {
    limiter := bucketdist.New(bucketdist.Config{
        Rate:     100,  // requests per second
        Capacity: 200,  // burst capacity
    })
    
    if limiter.Allow("client-123") {
        // Process request
        handleRequest()
    } else {
        // Rate limited
        http.Error(w, "Too Many Requests", 429)
    }
}

Documentation