0

Rate limiting a public API with Redis in Node.js

CO Chinedu Okafor 91 il y a 4 mois Nigeria

My API gets hammered by scrapers. I want a limit per API key that works across several instances.

Modifiée il y a 1 heure
  • Great answer, the raw body tip saved me hours. · Ngozi Eze · il y a 3 mois
4
KA Kwame Asante 50 · il y a 3 mois Réponse acceptée

Return Retry-After and X-RateLimit-Remaining headers so well-behaved clients can slow down, and apply stricter limits to expensive routes such as search or exports.

1
WK Wanjiru Kamau 25 · il y a 3 mois

A counter per key stored in Redis works across instances. Use INCR on a key like rl:{key}:{minute} and set EXPIRE on the first increment; reject with 429 when the counter exceeds the limit. Libraries such as rate-limiter-flexible implement a sliding window correctly.

Vous connaissez la réponse ? Rejoignez Griot pour aider.

Publier

Poser une question Obtenir de l'aide de la communauté Publier un composant Partager un SDK, un wrapper ou un package Proposer un troc Échanger une heure d'aide contre une autre Créer une prime Récompenser une solution en Mobile Money Organiser un hackathon Lancer un défi pour la communauté
Troc de compétences Primes Hackathons Observatoire