---
title: "The 5-hour CDN"
description: "The post presents a five-hour path to building a functional content delivery network as a distributed caching proxy rather than a Google-scale infrastructure project. It defines the architecture as NGINX instances deployed across cities, with DNS rules or Anycast directing users to regions and hash-based load balancing assigning URLs to cache shards. Health checks and multi-location monitoring detect failed or slow regions, while peer caches, origin-access protection, and request coalescing address redundancy, security, and cache-miss spikes. The design can improve cache ratios and reduce origin load, but cross-region proxying can add latency, and distributed invalidation remains unresolved; app-specific workloads may be better served by distributing the application itself. The conclusion is that existing NGINX features and modest scripting make a simple CDN practical, while advanced capabilities such as image optimization, WAF, rate limiting, and bot detection remain possible extensions."
---

# The 5-hour CDN

[Fly.io](https://yomu.fyi/company/fly-io) · Mar 16, 2021

**Type:** Tutorial

## Summary

The post presents a five-hour path to building a functional content delivery network as a distributed caching proxy rather than a Google-scale infrastructure project. It defines the architecture as NGINX instances deployed across cities, with DNS rules or Anycast directing users to regions and hash-based load balancing assigning URLs to cache shards. Health checks and multi-location monitoring detect failed or slow regions, while peer caches, origin-access protection, and request coalescing address redundancy, security, and cache-miss spikes. The design can improve cache ratios and reduce origin load, but cross-region proxying can add latency, and distributed invalidation remains unresolved; app-specific workloads may be better served by distributing the application itself. The conclusion is that existing NGINX features and modest scripting make a simple CDN practical, while advanced capabilities such as image optimization, WAF, rate limiting, and bot detection remain possible extensions.

## Context

The work is motivated by treating a CDN as a web application and distributed caching proxy that can be assembled from existing tools, while addressing regional routing, server failures, Internet slowdowns, cache ratios, origin load, and latency.

## Approach / What changed

Deploy NGINX caching proxies in multiple cities, direct traffic with DNS or Anycast, use health checks and external monitoring, and cluster regional servers with hash-based URL routing so they act as cache shards. Add request coalescing to prevent concurrent origin floods and use private WireGuard tunnels for origin communication.

## Takeaways

- Hash-based load balancing lets NGINX route the same URL to the same available cache shard, allowing servers to provide both proxying and storage.
- Adding regional redundancy can reduce failure impact but lower cache ratios unless servers share cache responsibility through sharding.
- Request coalescing prevents a cache miss during a traffic surge from turning into many simultaneous origin requests for the same URL.

**Tags:** [Caching](https://yomu.fyi/topic/caching), [Distributed Systems](https://yomu.fyi/topic/distributed-systems), [nginx](https://yomu.fyi/topic/nginx)

- Source: [Fly.io](https://fly.io/blog/the-5-hour-content-delivery-network)
- Source URL: https://fly.io/blog/the-5-hour-content-delivery-network
- Ingested by Yomu: 2026-09-02T11:56:50.615Z

[Read original post](https://fly.io/blog/the-5-hour-content-delivery-network)
