Author Avatar
Anchal Rawat

Rate Limiter Middleware

A production-ready rate limiting middleware in Go that protects APIs from traffic spikes using zero external dependencies.

View on GitHub

Overview

A thread-safe rate limiting middleware built in pure Go that restricts API requests per client using the fixed-window algorithm. Implements proper concurrency patterns with sync.Mutex, automatic memory cleanup, and works as plug-and-play middleware for any HTTP handler—all without external dependencies.


Key Features

FeatureDescription
Thread-Safe ConcurrencyUses sync.Mutex for safe concurrent request handling
Fixed-Window Algorithm5 requests per minute default limit
Automatic Memory CleanupBackground goroutines prevent memory leaks
Zero DependenciesBuilt entirely with Go standard library
Plug-and-Play MiddlewareWorks with any http.Handler
IP-Based TrackingIdentifies and tracks clients by IP address