Skip to content

Latest commit

Β 

History

History
47 lines (39 loc) Β· 1.32 KB

File metadata and controls

47 lines (39 loc) Β· 1.32 KB

Distributed Rate Limiter (Go + Redis)

A high-performance, distributed rate limiter built in Go. It uses Redis Lua scripts to ensure atomicity and prevent race conditions in concurrent environments.

Key Features

  • Distributed State: Uses Redis as the backend, allowing multiple API instances to share the same rate limits.
  • Atomic Operations: Implements the "Fixed Window" algorithm via custom Lua scripts to guarantee thread safety.
  • Concurrency Safe: Proven to handle concurrent requests without "leaking" excess traffic.
  • Dockerized: Ready to run with a single command.

Tech Stack

  • Language: Go (Golang)
  • Database: Redis (Alpine)
  • Containerization: Docker & Docker Compose
  • Testing: Custom concurrent load generator

How to Run

  1. Start Redis:

    docker-compose up -d
  2. Run the Server:

    go run main.go

    Server will start on :8080.

  3. Run the Load Test:

    go run load_test/attack.go

Performance Proof

Load test results simulating 20 concurrent requests (Limit: 5/10s):

πŸš€ Starting Load Test...
βœ… Request 10: ALLOWED
βœ… Request 9: ALLOWED
βœ… Request 1: ALLOWED
βœ… Request 6: ALLOWED
βœ… Request 7: ALLOWED
β›” Request 14: BLOCKED
... (All subsequent requests blocked)
Test finished in 19.69ms