AWS Builder Center
Building a High-Performance Distributed API Gateway & Rate Limiter with Go, Redis, and AWS EC2

Building a High-Performance Distributed API Gateway & Rate Limiter with Go, Redis, and AWS EC2

Learn how I engineered a production-grade distributed API Gateway and Reverse Proxy in Go and Redis, featuring atomic sliding-window rate limiting, AI prompt injection defense, and real-time telemetry deployed live on AWS EC2.

Student

πŸš€ Introduction

In modern microservice architectures, managing incoming traffic, preventing cascading service outages, and safeguarding downstream APIs against brute-force bursts are critical challenges. Traditional in-memory rate limiters often fail in distributed environments due to synchronization race conditions.
To solve this, I built APIGatewayCore β€” a production-grade, distributed API Gateway and Reverse Proxy engineered in Go 1.22 and Redis 7, deployed live on an AWS EC2 instance.

ο»Ώ

πŸ—οΈ Architecture & How It Works

The gateway intercepts all incoming client traffic, verifies authentication and rate limits in sub-millisecond time, and proxies requests to downstream services:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Clients β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ HTTP/HTTPS
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ API GATEWAY CORE (Go 1.22) β”‚
β”‚ β”‚
β”‚ [ CORS & WAF ] ──▢ [ JWT Authentication ] β”‚
β”‚ β”‚ β”‚
β”‚ β–Ό β”‚
β”‚ [ Atomic Rate Limiter ] β”‚
β”‚ β”‚ (Lua script) β”‚
β”‚ β–Ό β”‚
β”‚ [ Prometheus Metrics ] β”‚
β”‚ β”‚ β”‚
β”‚ β–Ό β”‚
β”‚ [ Reverse Proxy / LB ] β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β–Ό β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Redis 7 β”‚ β”‚ User Service β”‚ β”‚ Order Serviceβ”‚
β”‚ (Lua Engine) β”‚ β”‚ (Downstream) β”‚ β”‚ (Downstream) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article