# Building a CDN?



## BlackoutIsHere (Jul 24, 2013)

So I was bored and started thinking about building a CDN with cheap VPSes. I was thinking something like latency based routing combined with rsynced nginx machines would make a pretty simple but fast CDN. Has anyone tried this and would anyone be interested in using a service like this? Also does anyone know of a good method of global bandwidth accounting?

Thanks,

Blackout


----------



## manacit (Jul 24, 2013)

An alternative to using rsync would be making an origin-pull based system where each edge instance proxies back to a master node that has the content. On first load, it would need to call home, but after that, it would cache the content for as long as you set, and serve as an edge node.

For bandwidth accounting, you could always reverse proxy nginx to a local app that you run which would account for files accessed and bandwidth used, and periodically call home with totals, etc. Alternatively, log analysis could easily net you a bandwidth total.


----------



## Slownode (Jul 24, 2013)

Making a simple file server CDN is pretty trivial; load balancing, file mirroring, receiving, usage monitoring.
A week's work can make something quite powerful.

Distributed databases on the other hand can be very challenging.


----------



## manacit (Jul 24, 2013)

Something like this: https://github.com/valyala/ybc/tree/master/apps/go/cdn-booster as an incredibly simple example.

My thought was to use golang + redis, but that uses YBC, which is a pretty sweet looking k/v cache: https://github.com/valyala/ybc/blob/master/apps/go/cdn-booster/main.go


----------



## BlackoutIsHere (Jul 24, 2013)

manacit said:


> Something like this: https://github.com/valyala/ybc/tree/master/apps/go/cdn-booster as an incredibly simple example.
> 
> My thought was to use golang + redis, but that uses YBC, which is a pretty sweet looking k/v cache: https://github.com/valyala/ybc/blob/master/apps/go/cdn-booster/main.go


That looks really neat thanks! I might consider learning a little bit of this language and adding a logging function that periodically gets sent back to the master db.


----------



## BlackoutIsHere (Jul 25, 2013)

manacit said:


> Something like this: https://github.com/valyala/ybc/tree/master/apps/go/cdn-booster as an incredibly simple example.
> 
> My thought was to use golang + redis, but that uses YBC, which is a pretty sweet looking k/v cache: https://github.com/valyala/ybc/blob/master/apps/go/cdn-booster/main.go


----------

