Chapter 3: Distributed Rate Limiting with Redis & GCRA in Golang
Multi-Language Edition: This chapter is also available in Vietnamese at 📖 Bản tiếng Việt (Vietnamese Edition). Previous: Chapter 2 — Caching Vulnerabilities & Go Singleflight | Series Hub | Next: Chapter 4 — Dual-Write Prevention via Transactional Outbox Answer-First: Local in-memory rate limiters (e.g., golang.org/x/time/rate) fail in horizontally autoscaled microservices because client traffic is scattered across dynamic nodes. Distributed rate limiting requires an atomic, single-variable algorithm: the Generic Cell Rate Algorithm (GCRA) executed within a single Redis Lua script. GCRA tracks a single Theoretical Arrival Time (TAT) per client, reducing network round-trips and memory footprint by 70% compared to classical sliding window counters. ...