Skip to content

Exercise 2: Implement Redis Sliding Window Rate Limiter #5

Description

@harsharajkumar-273

Goal

Protect the ingestion gateway from volumetric traffic surges and DDoS attacks.

Problem

There is currently no rate limiting on the /v1/events endpoint. A single malicious client can flood the gateway, causing resource exhaustion across Redpanda and PostgreSQL.

Task

  1. Implement a rate limiter in src/middleware/rateLimiter.ts using Redis sorted sets (zsets).
  2. Maintain a sliding-window duration of 60 seconds allowing a maximum of 100 requests.
  3. Execute the Redis operations atomically using a multi-pipeline transaction (ZREMRANGEBYSCORE, ZADD, ZCARD, EXPIRE).
  4. Return an HTTP 429 status code with a 'Retry-After' header if the count is exceeded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions