gitmyhub

cdn-up-and-running

Lua ★ 3.7k updated 5mo ago

CDN Up and Running - Building a CDN from Scratch to Learn about CDN, Nginx, Lua, Prometheus, Grafana, Load balancing, and Containers.

This repository is a hands-on tutorial for learning how content delivery networks work by building one from the ground up. A CDN (Content Delivery Network) is a system of servers spread across different locations that caches content closer to users, so pages, videos, and files load faster regardless of where the original server is.

The tutorial starts simple: one backend service built with Nginx (a web server) and Lua (a scripting language that can be embedded into Nginx to add custom logic). From that starting point, the project grows step by step into a multi-node setup with simulated geographic latency, load balancing across servers, caching behavior, and monitoring. Each stage is a discrete version tagged in the repository so you can check out exactly the state being discussed.

The stack used includes Docker and Docker Compose to run multiple servers on your own machine in isolated containers, Prometheus to collect performance metrics from the servers, and Grafana to display those metrics as charts. A load testing tool called wrk is also used to simulate traffic so you can see caching behavior and performance numbers in action.

The README reads as a long tutorial with explanations at each step. It covers how Nginx configuration files work, how Lua code runs inside Nginx request handlers, how a caching layer decides whether to serve a stored response or forward the request to the origin server, how traffic gets routed across multiple CDN nodes, and how to observe all of this through dashboards. Each major topic includes code samples with line-by-line commentary.

This project is aimed at developers and engineers who want to understand CDN internals, not just use one. It assumes some comfort with the command line and running Docker containers, but does not assume prior knowledge of Nginx, Lua, or CDN architecture.

The full README is longer than what was shown.