DUG (Distributed Unified Gateway)

A lightweight, production-inspired API Gateway built from scratch in Go.
Build. Learn. Route.
DUG is an API Gateway designed to understand how modern gateways like NGINX, Traefik, Envoy, and Kong work internally by implementing their core building blocks from first principles.
Rather than wrapping existing gateway libraries, DUG focuses on building the networking, reliability, and traffic management components yourself to gain a deeper understanding of production backend infrastructure.
β¨ Features
π¦ Traffic Management
- β
Reverse Proxy
- β
Route-based Routing
- β
YAML Configuration
- β
Graceful Shutdown
- β
WebSocket Proxy
- β
Dynamic Configuration Reload
βοΈ Load Balancing
- β
Round Robin
- β
Smooth Weighted Round Robin (SWRR)
- β
Least Connections
π‘ Reliability
- β
Retry Mechanism
- β
Exponential Backoff
- β
Active Health Checks
- β
Passive Health Checks
- β
Circuit Breaker
- β
Request Timeouts
π Security & Traffic Control
- β
HTTPS / TLS
- β
Per-IP Rate Limiting
- β
CORS
- β
Request Header Manipulation
- β
Response Header Manipulation
π Observability
- β
Prometheus Metrics
- β
Structured Logging (
slog)
- β
Request IDs
π Service Discovery
- β
Static Service Discovery
- β
DNS Service Discovery
βοΈ Configuration
- β
YAML Configuration
- β
Hot Configuration Reload
- β
Atomic Router Reload
π Architecture
Client
β
HTTP / HTTPS
β
βΌ
ββββββββββββββββββββββ
β DUG β
ββββββββββββββββββββββ€
β Reverse Proxy β
β Router β
β Load Balancer β
β Retry Engine β
β Health Checks β
β Circuit Breaker β
β Rate Limiter β
β Header Middleware β
β Service Discovery β
β Metrics β
β Logging β
βββββββββββ¬βββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌ
Backend A Backend B Backend C
π Getting Started
Install
Option 1 β go install (recommended)
go install github.com/khareutkarshk/dug/cmd/dug@latest
Ensure $(go env GOPATH)/bin is on your PATH, then verify:
dug version
Option 2 β Build from source
git clone https://github.com/khareutkarshk/dug.git
cd dug
go mod tidy
make build
./dug version
Option 3 β Docker
docker compose up --build
Generate local TLS certificates
mkdir -p certs
openssl req -x509 \
-newkey rsa:4096 \
-keyout certs/server.key \
-out certs/server.crt \
-days 365 \
-nodes
Start the gateway
dug run -config configs/edge.yaml
Or from source without installing:
go run ./cmd/dug run -config configs/edge.yaml
π§° CLI
DUG ships as a multi-command CLI:
| Command |
Description |
dug run |
Start the gateway |
dug validate |
Validate a configuration file |
dug doctor |
Check config, port availability, TLS files, and upstreams |
dug version |
Print build metadata |
dug help |
Show usage |
# Start gateway
dug run -config configs/edge.yaml
# Validate config before deploy
dug validate -config configs/edge.yaml
dug validate -config configs/edge.yaml -quiet # CI-friendly
dug validate -config configs/edge.yaml -json # machine-readable
# Local diagnostics (non-zero exit if checks fail)
dug doctor -config configs/edge.yaml
dug doctor -config configs/edge.yaml -timeout 2s -json
# Version (human, short, machine-readable)
dug version
dug version -short
dug version -json
Releases
Tagged versions (v*) publish multi-platform binaries via GitHub Releases:
- linux/amd64, linux/arm64
- darwin/amd64, darwin/arm64
- windows/amd64
# Example after a release is published
curl -LO https://github.com/khareutkarshk/dug/releases/latest/download/dug_v0.1.0_linux_amd64.tar.gz
tar -xzf dug_v0.1.0_linux_amd64.tar.gz
./dug_v0.1.0_linux_amd64 version
βοΈ Configuration
DUG is configured using a YAML file.
Configuration supports:
- Routes
- Multiple upstreams
- Load balancing strategy
- Retry policy
- Health checks
- Timeouts
- HTTPS / TLS
- CORS
- Request & Response Headers
- Rate Limiting
- Service Discovery
Example configuration:
server:
port: 8080
routes:
- path: /
upstreams:
- url: http://localhost:3001
weight: 1
Default configuration:
configs/edge.yaml
π Project Structure
.
βββ cmd/
β βββ dug/ # CLI entrypoint (run, validate, doctor, version)
βββ configs/
βββ examples/
β βββ backend/
β βββ backend2/
β βββ websocket/
βββ internal/
β βββ app/
β βββ cli/ # CLI command implementations
β βββ config/
β βββ discovery/
β βββ httpx/
β βββ logger/
β βββ metrics/
β βββ middleware/
β βββ proxy/
β βββ ratelimit/
β βββ router/
β βββ server/
β βββ upstream/
β βββ version/ # Build-time version metadata
βββ test/
βββ README.md
π§ͺ Testing
Run all tests
go test ./...
Run with race detector
go test ./... -race
Generate coverage
go test ./... -cover
π Current Status
DUG currently includes:
- Reverse Proxy
- Route-based Routing
- Multiple Load Balancing Algorithms
- Retry Engine
- Circuit Breaker
- Active & Passive Health Checks
- HTTPS
- WebSocket Proxy
- Dynamic Configuration Reload
- DNS Service Discovery
- Rate Limiting
- Header Manipulation
- Prometheus Metrics
- Structured Logging
- Request IDs
The core gateway functionality is complete and stable. The next milestone focuses on improving developer experience, packaging, and documentation.
π£ Roadmap
v1.0 β Developer Experience
CLI
-
dug run
-
dug validate
-
dug doctor
-
dug version (-short, -json)
Distribution
- Docker Image
- GitHub Releases (tag
v* workflow)
- Pre-built binaries
-
go install support
Documentation
- Installation Guide
- Configuration Reference
- Feature Documentation
- Example Configurations
CI/CD
- GitHub Actions
- Go Race Tests
- golangci-lint
- Automated Releases
Future
- JWT Authentication
- API Keys
- OpenTelemetry
- Response Compression
- Response Caching
- HTTP/2
- HTTP/3
- Kubernetes Service Discovery
- Consul Service Discovery
- Canary Routing
- Blue-Green Deployments
- Plugin System
π‘ Why DUG?
DUG started as a way to learn Go by building production-inspired backend infrastructure instead of another CRUD application.
Every major component is implemented from scratch to understand:
- Reverse proxies
- Load balancing algorithms
- Circuit breakers
- Retry strategies
- Health checking
- Service discovery
- Concurrent programming
- High-performance HTTP servers
- Production networking patterns
The name is inspired by Dug πΆ, the lovable golden retriever from Pixar's Up.
While DUG began as a learning project, it has evolved into a fully functional API Gateway that continues to grow with production-inspired features.
π€ Contributing
Contributions, bug reports, ideas, and discussions are always welcome.
If you'd like to contribute:
- Fork the repository
- Create a feature branch
- Commit your changes
- Open a Pull Request
β Support
If you found DUG useful or interesting, consider giving the repository a Star.
It helps others discover the project and motivates future development.
π License
This project is licensed under the MIT License. See the LICENSE file for details.