This project is a high-performance reverse proxy written in Go that supports:
- Dynamic request re-routing via JSON configuration
- API-level rate limiting using configurable algorithms
- Redis-backed distributed rate limiting
- Dockerized deployment for easy setup and scalability
- Fallback-safe and production-ready architecture
- 🚀 Reverse proxy built using Go’s
net/httpprimitives - 🔀 Dynamic routing using regex-based URL matching
- ⏱️ Four rate-limiting algorithms
- Token Bucket
- Leaky Bucket
- Fixed Window Counter
- Sliding Window Log
- 🌐 IP-based and API-based throttling
- 🧠 Redis used as centralized rate-limit store
- 🐳 Fully Dockerized (App + Redis)
- ⚙️ Configurable via JSON (no code changes required)
File: /redirection.json
This file defines URL patterns and their corresponding upstream services.
[
{
"urlPattern": "/index\\.php(?:/|$)",
"NewEndpoint": {
"protocol": "*",
"host": "*",
"port": "8080",
"path": "*"
}
},
{
"urlPattern": "/go/api/hr-apis",
"NewEndpoint": {
"protocol": "*",
"host": "*",
"port": "3008",
"path": "*"
}
}
]Incoming Request: GET http://example.com/go/api/hr-apis/v1/list
Forwarded To: GET http://example.com:3008/go/api/hr-apis/v1/list
/redirection.json
{
"algorithm": "TokenBucket",
"apiList": [
{
"url": "/go/api/hr-apis/v1/fetchrecruiterJobApplication",
"method": "*",
"ipBased": true,
"rateLimits": [
{
"timeWindowSeconds": 5,
"maxRequests": 2,
"burstSize": 2
}
]
}
]
}Supported Rate Limiting Algorithms
The project implements four algorithms, selectable using the algorithm field in JSON.
- Tokens are added at a fixed rate.
- Each request consumes a token.
- Allows short bursts.
- Best for: APIs needing burst tolerance.
- Requests enter a queue.
- Processed at a fixed rate.
- Excess requests are dropped.
- Best for: Smoothing traffic spikes.
- Counts requests in a fixed time window.
- Resets counter when window expires.
- Best for: Simple, low-overhead limits.
- Stores timestamps of requests.
- Counts requests within rolling time window.
- Best for: Precise rate limiting.
| Field | Description |
|---|---|
| algorithm | Algorithm to use (TokenBucket, LeakyBucket, FixedWindow, |
| url | API path to apply limit |
| method | HTTP method (GET, POST, *) |
| ipBased | Apply limits per client IP |
| timeWindowSeconds | Duration of rate window |
| maxRequests | Max allowed requests |
| burstSize | Burst capacity (used by bucket algorithms) |
| userBased | apply limits on the bases on a key |
| keyPath | path of key to acess that key from request(not implemented for post request keys) |
This document explains system requirements, dependencies, and step-by-step instructions to run the Go Reverse Proxy with Redis-backed Rate Limiting using Docker.
The application is OS-agnostic and can run on:
- Linux (recommended for production)
- macOS
- Windows (with Docker Desktop)
Ensure the following tools are installed on your system:
| Software | Minimum Version | Purpose |
|---|---|---|
| Docker | 20.10+ |
Container runtime |
| Docker Compose | v2+ |
Multi-container orchestration |
| Git | Latest | Source code management |
🔍 Verify installation
docker --version
docker compose version
git --version1️⃣ Clone the Repository
git clone go-api-limits
cd go-api-limits2️⃣ Review Docker Configuration
docker-compose.yml
- Starts Go Reverse Proxy
- Starts Redis
- Sets environment variables automatically
services:
router:
build: .
ports:
- "9000:9000"
network_mode: "host"
db:
image: redis
ports:
- "6379:6379"
network_mode: "host"
volumes:
- redis-data:/data
volumes:
redis-data:3️⃣ Build & Start Containers
docker compose up --build📌 This command will:
- Build the Go application image
- Start Redis
- Start the reverse proxy
- Connect proxy to Redis internally