High-performance, lightweight API Gateway written in Go, featuring routing, rate limiting, observability, and resilience mechanisms.
- Performance: Built with
chifor fast, lightweight HTTP routing. - Rate Limiting: Per-IP token-bucket rate limiting to prevent upstream overload.
- Resilience: Integrated Retry and Circuit Breaker patterns for proxying.
- Observability: Native Prometheus metrics and structured logging.
- Security: Request ID propagation and panic recovery middleware.
- Documentation: Built-in OpenAPI specification and Swagger UI.
- Modern: Fully containerized with Docker and Docker Compose.
- Language: Go 1.25
- Router: go-chi/chi
- Metrics: Prometheus
- Monitoring: Grafana
- Documentation: OpenAPI (Swagger)
- Containerization: Docker & Docker Compose
- Go 1.25+ (for local development)
- Docker & Docker Compose (for running the full stack)
To launch the Gateway along with the Auth service, Prometheus, Grafana, and Swagger UI:
docker compose up --build-
Install dependencies:
go mod download
-
Run the server:
go run ./cmd/server
Note: Ensure
AUTH_SERVICE_URLis configured if testing proxying.
The Gateway is configured using environment variables.
| Variable | Description | Default |
|---|---|---|
APP_PORT |
Port for the gateway server | 8080 |
APP_ENV |
Environment (local, docker) |
local |
LOG_LEVEL |
Logging level (debug, info, warn, error) |
info |
AUTH_SERVICE_URL |
Upstream Auth service URL | http://localhost:8081 |
UPSTREAM_TIMEOUT_SECONDS |
Proxy request timeout | 5 |
RATE_LIMIT_RPS |
Allowed requests per second per IP | 10 |
RATE_LIMIT_BURST |
Burst capacity per IP | 20 |
GET /health: Health check endpoint.GET /metrics: Prometheus metrics.GET /api/v1/ping: Simple connectivity test.GET /docs/*: Servesopenapi.yaml.
ANY /api/v1/auth/*: Routed to Auth Service.ANY /api/v1/users/*: Routed to Auth Service.
- Rate Limiting: Rejects excessive traffic with
429 Too Many Requestsand includesRetry-Afterheader. - Retries: Automatically retries failed requests to upstream services.
- Circuit Breaker: Monitors upstream health and "trips" if failures exceed thresholds, preventing cascading failures.
| Service | URL | Credentials |
|---|---|---|
| Gateway | http://localhost:8080 | - |
| Swagger UI | http://localhost:8082 | - |
| Prometheus | http://localhost:9090 | - |
| Grafana | http://localhost:3000 | admin / admin |
This project is licensed under the MIT License - see the LICENSE file for details.