Skip to content

FaisalDipto/L7-Reverse-Proxy-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

L7 Enterprise API Gateway & Load Balancer

A high-performance, concurrent Layer 7 Reverse Proxy and Load Balancer written entirely in Go from scratch.

This project was built to explore and master hardcore systems engineering concepts, including distributed state management, hardware-level memory locks, dynamic health checking, and container orchestration. It acts as a single, secure point of entry for a microservice architecture.

🚀 Core Architecture & Features

  • Dynamic Round Robin Load Balancing: Distributes incoming HTTP traffic evenly across a fleet of backend microservices.
  • In-Memory Rate Limiting (Token Bucket): Defends against DDoS attacks and botnets using a per-IP Token Bucket algorithm.
  • Active Health Checking (Chaos Resilient): A background heartbeat monitor constantly pings backend nodes. If a server dies, the Gateway dynamically mathematically bypasses the dead node in milliseconds without dropping live traffic.
  • Memory-Safe Garbage Collection: A custom background sweeping routine automatically evicts stale IP addresses from the Rate Limiter map to prevent Out-Of-Memory (OOM) kernel panics.
  • Hardware-Level Concurrency: Utilizes Go's sync/atomic package for lock-free pointer manipulation and sync.RWMutex for Double-Checked Locking to handle thousands of concurrent requests with sub-millisecond latency.
  • Fully Containerized: The entire cluster (Gateway + 3 Backend Nodes) is orchestrated via multi-stage Docker builds and an internal Docker DNS network.

🏗️ System Design

                 [ Public Internet ]
                        │ (HTTP Requests)
                        ▼
      +-----------------------------------------+
      |          L7 API GATEWAY (Port 8080)     |
      |-----------------------------------------|
      |  1. Per-IP Rate Limiter (Token Bucket)  | -> Drops HTTP 429
      |  2. Active Health Monitor (Heartbeat)   |
      |  3. Round-Robin Routing Engine          |
      +-----------------------------------------+
             /          |           \  (Internal Docker Network)
           /            |             \
         ▼              ▼               ▼
   +----------+   +----------+    +----------+
   | Backend 1|   | Backend 2|    | Backend 3|
   | (:8081)  |   | (:8082)  |    | (:8083)  |
   +----------+   +----------+    +----------+

⚙️ Prerequisites

  • Docker & Docker Compose v2
  • (Optional) Go 1.22+ if compiling manually

🛠️ Quick Start

1. Clone the repository

git clone https://github.com/FaisalDipto/L7-Reverse-Proxy-Engine.git
cd L7-Reverse-Proxy-Engine

2. Boot the cluster

docker compose up --build

3. Verify the Load Balancer Open a new terminal and send a burst of traffic to the Gateway. You will see the requests seamlessly distributed across the backend nodes, followed by the Rate Limiter actively shielding the cluster:

for i in {1..10}; do curl -i http://localhost:8080/; echo ""; done

4. Chaos Engineering & Load Testing You can verify the system's resilience by simulating attacks and hardware failures.

Trigger the Rate Limiter Shield: Hold down F5 in your browser or run a heavy bash loop. You will see the first 5 requests succeed (Burst capacity), and subsequent rapid requests instantly blocked with 429 Too Many Requests. Wait 1 second, and exactly 1 token will refill.

The Chaos Monkey Test (Simulate Server Death): While the cluster is running, violently kill one of the backend containers:

docker stop <project_name>-backend2-1

Send traffic through the Gateway again. You will see the Gateway log an alert, instantly fast-forward its routing pointers, and seamlessly distribute traffic only between backend1 and backend3.

About

A high-performance, concurrent Layer 7 Reverse Proxy and API Gateway written from scratch in Go.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors