This project implements a Content Delivery Network (CDN) system using Go (Golang) with the following stack:
- Gin (HTTP framework)
- MongoDB (Control Panel persistence)
- NATS (messaging bus for events & health checks)
- Monorepo structure with multiple services
.
├── control-panel # Management API + MongoDB persistence + NATS subscriber
├── edge # Edge CDN service (serves cached content, proxies requests)
├── mid # Mid-tier service (cache logic, sync with control panel, health checks)
└── origin-sample # Sample origin server (static files for testing)
- REST API to manage users, CDNs, and snapshots
- Persists data in MongoDB
- Subscribes to health updates from services via NATS
- Receives client requests
- Caches static content (images, CSS, JS, fonts, video, audio)
- Proxies dynamic/non-cacheable requests to origin servers
- Stores cache on disk
- Syncs CDN configurations from control panel (via snapshot API)
- Caches responses locally (on disk + in-memory metadata)
- Publishes service health status via NATS
- Subscribes to snapshot updates from control panel
- Simple static file server (images, JSON, video) for testing CDN flows
git clone https://github.com/AmirAghaee/go-cdn-stack.git
cd go-cdn-stackMake sure MongoDB & NATS are running.
cd control-panel
go run main.gocd mid
go run main.gocd edge
go run main.gocd origin-sample
go run main.go- Cache rules: Only
image/*,font/*,text/css,text/javascript,application/javascript,video/*, andaudio/*responses are cached. - Non-GET requests are proxied directly to origin.
- Each cached item has metadata stored alongside the cached file (headers + expiry time).
- Mid-tier syncs CDNs from Control Panel at startup and also via NATS events.
- Health check messages are published by services and consumed by Control Panel.
- Language: Go 1.25+
- Frameworks: Gin, NATS, MongoDB driver
- Persistence: MongoDB (control panel), Disk-based cache (edge/mid)
- Add Docker Compose for local development (MongoDB + NATS + services)
- Add unit/integration tests
- Implement cache invalidation via NATS
- Add rate limiting and logging middleware