_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Rate Limiting algoritmy

20. 06. 2025 1 min read intermediate

Chrání API proti přetížení a zneužití.

Token Bucket

Bucket se plní tokeny konstantně. Request = spotřebuje token. Prázdný = odmítnut. Umožňuje bursty.

Leaky Bucket

Requesty padají do bucketu, zpracovávají se konstantně. Vyhlazuje bursty.

Fixed Window

Počítá requesty v pevných oknech. Problém: double rate na hranici.

Sliding Window

Kombinuje přesnost sliding s efektivitou fixed.

Redis implementace

– Sliding Window Counter local key = KEYS[1] local window = tonumber(ARGV[1]) local limit = tonumber(ARGV[2]) local now = tonumber(ARGV[3]) redis.call(‘ZREMRANGEBYSCORE’, key, 0, now - window) if redis.call(‘ZCARD’, key) < limit then redis.call(‘ZADD’, key, now, now .. math.random()) return 1 end return 0

HTTP hlavičky

X-RateLimit-Limit: 100 X-RateLimit-Remaining: 42 Retry-After: 30

Token Bucket pro většinu

Nejflexibilnější — povoluje bursty, konstantní paměť. Redis pro distribuované.

rate limitingalgoritmyapi
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.