Cadey is coffee
<Cadey> Hello! Thank you for visiting my website. You seem to be using an ad-blocker. I understand why you do this, but I'd really appreciate if it you would turn it off for my website. These ads help pay for running the website and are done by Ethical Ads. I do not receive detailed analytics on the ads and from what I understand neither does Ethical Ads. If you don't want to disable your ad blocker, please consider donating on Patreon or sending some extra cash to xeiaso.eth or 0xeA223Ca8968Ca59e0Bc79Ba331c2F6f636A3fB82. It helps fund the website's hosting bills and pay for the expensive technical editor that I use for my longer articles. Thanks and be well!

Announcing the glorious advent of XeDN

Read time in minutes: 6

hero image sky-datacentre
Image generated by Stable Diffusion -- A datacentre in the clouds sending down letters and packages, digital painting, matte painting, concept art, greg rutkowski, daytime

Numa is delet
<Numa> For someone that calls themselves an "archmage of infrastructure" you sure don't do much heckin' infrastructure work.

Mara is hmm
<Mara> All those conference talks take a lot of time, effort, and energy to create. Not to mention things have been stable enough that we don't really have to care.

Numa is delet
<Numa> You say this as someone who has a "CDN" domain where the "CDN" doesn't actually cache things correctly.

Mara is sh0rck
<Mara> W...what? I thought that it was taken care of.

Numa is delet
<Numa> Go look at the storage bill lol. Boom. Roasted.

So I made a mistake with how the CDN for my website works. I use a CDN for all the static images on my blog, such as the conversation snippet images and the AI generated "hero" images. This CDN is set up to be a caching layer on top of Backblaze B2, an object storage thing for the cloud.

There's only one major problem though: every time someone loads a page on the website, assets get routed to the CDN. I thought the CDN was configured to cache things. Guess what it hasn't been doing.

Cadey is facepalm
<Cadey> Oh god...

This is roughly what I've intended the flow to look like when I was designing this blog:

I wanted the flow to go from users to the CDN, and the CDN would reach into its cache to make things feel snappy. If it wasn't in the cache, the CDN would just reach out into B2 and grab it, then store that in the cache. This allows normal user behavior to automatically populate the cache and then every future visitor gets things more quickly.

However, because of things that I don't completely understand, when I moved from to something got messed up in one of the page rules and my CDN domain went from almost always caching everything to never caching anything. This is not good.

Numa is delet
<Numa> We need a hero for this fallen land. Everything has gone to ruin and there is only one savior!

Cadey is facepalm
<Cadey> Oh no, what now. Are you going to announce another one of those weird alt-universe Xe-things that makes a horrible pun on a common tech term?

Numa is delet
<Numa> We need...XeDN.

Cadey is facepalm
<Cadey> You are, aren't you.

hero image cyberpunk-hacker
Image generated by Stable Diffusion -- Cyberpunk cyber hacker in the neon city at midnight

So yes, I have my own CDN service now apparently. The overall architecture of how XeDN fits into everything looks something like this:

XeDN is built on top of Go's standard library HTTP server and a few other libraries:

  • groupcache for in-ram Last-Recently-Used caching
  • ln (the natural log function) for the logging stack
  • tsnet to allow me to access the debug routes more securely over Tailscale
  • xff to parse X-Forwarded-For headers for me

Cadey is angy
<Cadey> I wouldn't have had to make XeDN if Varnish and HAProxy didn't force you to pay for the enterprise tier to connect to backend servers over HTTPS. Yes, I could bodge something with Go to just reverse proxy to HTTPS and use Varnish as-is, but at that point it's probably easier to just do the whole thing in Go in the first place.

This allows me to have a caching CDN service in less than 250 lines of Go. I run XeDN on top of in multiple regions, so it's one of the first things I've made for this blog that is actually a redundant service geo-replicated across multiple datacentres. It's pretty nice.

Cadey is enby
<Cadey> Fly really make a great product and I can't suggest it more if you're looking at moving off Heroku.

I switched over my CDN to use XeDN yesterday and nobody noticed at first. The only reason people noticed at all is because I tweeted about it. Either way, things should be very fast now. This should scale to meet my CDN needs a lot better than the previous setup and everything should be a lot more streamlined in the future.

Numa is delet
<Numa> You do know that your blog isn't being cached either, right?

Cadey is percussive-maintenance

This article was posted on M09 04 2022. Facts and circumstances may have changed since publication. Please contact me before jumping to conclusions if something seems wrong or unclear.

This post was not WebMentioned yet. You could be the first!

The art for Mara was drawn by Selicre.

The art for Cadey was drawn by ArtZora Studios.

Some of the art for Aoi was drawn by @Sandra_Thomas01.