8 min read
anvil - the talk
Hi,
I'm ioan. My website is ioan.dev.
I had to overhaul my presentation this morning because although it was pretty, it didn't get my point across. So, I'm going to freestyle it as much as I can, without losing the thread of discussion. I do have some slides, but I will leave them towards the end of the talk. Which sucks for the visual people, but I'll do my best to tell the story of how I got 20 projects running well on a single server, which has just 2 dedicated cores. In reality it's just one (one core, two threads).
Initially the presentation I wanted to do was about a website that would force developers into good behaviours, such as adding Open Graph images and descriptions to their pages, favicons, sitemaps, google auth, etc - things that every website needs. It was almost as important as this talk, but not quite.
Going back over a decade ago, I heard about a hosting provider called scaleway. They were doing something different: they were selling dedicated servers for 3 euro a month. They were selling small servers, similar to raspberry pis, SoCs (System on Chip). Of course, I got one of those, and it worked great, until they got rid of them.
After a few migrations of my servers, as the ubuntu server versions rolled in, I wanted to learn more about system design. So I developed this huge system around ingesting data coming from the game I play (the article is on my blog). I played around with redundancy and load balancers. I played around with Docker Swarm. And things worked.. great. It was also the first time I had monitoring on the servers and automated phone calls in case anything was failing. And I got plenty of those. AI was still not great at that point, so I was quite involved in the project. Which is good, because it allowed me to learn better. I have worked with big systems before, but making something from scratch, on your own, it's a different story.
Around the same time I had heard about flatcar. Flatcar is an immutable OS which "only" allows running containers. There is no package manager, so you can't install anything potentially malicious or non replicable if your server goes down. Your entire configuration of the server goes into a butane file at first boot, with few changes possible later on. I played around with it, but given the difficulty of the butane file and a few failures with k3s, I returned back to docker swarm.
Then, after a while, I realised I am still spending quite a lot on these servers, ingesting hundreds of thousands of points a day, but just archiving all the data. I had a future project in mind, but I wasn't going to work on it any time soon. So I downsizes all of it. Out with the queues, replicas, backups. Instead, everything was kept mostly in RAM and it was invisible to the end user.
Fast forward a year, I got an alert that my HTTPS certificate from letsencrypt on one of my websites would be expiring soon. And I ignored it, because I thought the auto renewal I had set up would do its job. But, a few days did pass, and I realised most of my websites were affected.
At that point I had a server that was still running ubuntu server, and the configuration I had was hand written. I was running everything in Docker already, but it was running with docker compose and quite a lengthy manual script I was running to do a rolling update with no downtime. Having many containers for the same app meant that there was a fair bit of complexity in all of this. The thing I am most proud of it, though, is that every container was running under its own user and group, so the attack surface area was limited. There were other things in place.
But, I had no monitoring anymore. And the websites being down because of the certificates was a big hit. I got tired of maintaining the old infrastructure. At this point (in November this year), the AI has gotten quite a lot better. We had Opus 5.5. So I gave it a shot. I told it to leave the server as it is, but create a series of scripts with terraform that would deploy a new server using the latest flatcar image for Scaleway. And off it went. It migrated all my configuration files (which were all organised), and it finished in about two and a half hours.
Everything passed. Everything was looking good. No more issues.
In the meantime I had a chat on the internet and heard Cloudflare offers a free plan. So I jumped on that. I gave Claude a key to my cloudflare, and one to my domain registrar, and it set up everything. Now, I know Stackoverflow got hacked once because people found their origin servers and DDOSed them, so I asked for that to be fixed. A firewall rule was added at Scaleway level (outside the instance), which allowed only Cloudflare traffic. But, that was not enough. Anyone could send traffic through Cloudflare to my own server, so I added certificates that only my server and Cloudflare knows for those domains. On top of that, the public IP was rotated.
Now, I had a server that I could bring down and back up with ease, as everything was stored in terraform, and a git repo. The secrets I have are nothing special - they are stored in encrypted files in the git repo with SOPS. As a single tenant/single maintainer, that's enough for me, as it reduces complexity a lot.
At this point I still had no monitoring, and no alerting. And I was afraid to add any, because even though I had 8gb of RAM, it was not enough. I chose to rewrite a couple of services I had. Both of them were very similar in their requirements, but for measurement: one of them was using 600mb of ram at idle. I rewrote it in rust. The end result, under load? 9mb of ram. From 600mb to 9mb. Twice.
My RAM went lower, so I added prometheus and grafana. I also added back in the container the watchdog I had from years past so that it calls me with twilio. And that same night I got some calls. Which was not ideal, for me.
So in went another idea from a youtuber: have AI automatically fix issues, before the watchdog calls you. It can try, and if it fails, it still calls you.
It was running OK for a few days, but there were still blips going on. I was on a 4 vCPU shared machine. What that means is that you get 4 threads, but they are shared with other customers. When the server would be under load, my apps would fail some health checks. I ignored those for about 2 weeks, as there was not a big urgency - they were coming back.
Then I thought a bit about my reputation of bragging about these websites and sharing them with people, but them possibly getting errors right when they visit them. And guess what? It didn't matter too much to me, so I left it. But, this Tuesday I actually got calls continuously somewhere around 6pm. A quick analysis was showing that the CPU on the host was at 100%, which were making my services fail all kind of checks. It was unbearable. I left work, came home, and researched what instance I can move on next. I found one, and upgraded to that. 2vCPUs down from 4vCPUs, but they were dedicated, not shared. And instead of 8gb of ram, I have 16 now. The price increased more than twice, but it was all worth it. I have enough spare room for even more services deployed on the same server, and my CPU is sitting at 40% with over 80 containers running.
Why 40%? Mostly because I added "journeys" right after. This is a collections of scripts that checks every part of each application as though it was an end user. It expects data to load, exactly as it did before, and it doesn't even trust a 200 OK. All of the data produced by journeys is then published to my Grafana.
Demo time! I want to show you my grafana. Here are all the websites running, and here is the CPU usage on the host (my cores only), and here is dozzle which can show the number of containers, how much RAM and CPU each container is using, as well as each container's logs in real time.
As you can see I actually have two servers - but the second one is mostly idle. I wrote a small app that for the next year it's going to collect every market move of bitcoin on binance. They are in an active-active setup, but if primary dies, or fails a healthcheck, then the secondary starts writing what it has in memory to a file. So far it only turned useful in the migration discussed above (it was not a few button clicks to get on a different instance).
This might be the only downside to my setup - no redundancy. Other than this single app. For me to be able to have no downtime I would have to pay more than double what I am paying now for another server matching spec, as well as a load balancer for each of the websites. I'm just not doing it at the moment.
One thing I forgot to mention is that I did test what happens in the case I get a lot of traffic coming in. And I already implement this: caching. On a load test, adding 1s cache in cloudflare increased the number of requests from 900 to three times that. And, for some websites, I set it to a few minutes. The other thing I only experimented with is writing a series of scripts with a latch that, in case a website does become a success overnight (hopefully not), then all of its containers including database are moved to another server created on the fly. This took some tries, but it's pretty solid as it stands.
And here we may wrap the presentation. What I want to share with you is that this project is open sourced and it has the latest updates from my own server as of 2 weeks ago. More updates will be done over the coming days or weeks, including a WAF that can reduce the attack area of your server. Give it a look and leave a star on the repo at ioan.dev/anvil.
I don't know what the person after me has to say about vibe coding, but I hope to inspire more people to build random projects for themselves or their friends. And then deploying them. This is the final step that often gets missed in side projects. A project might work in a good way on the developer's machine, but it never sees the light of day. I think once a project is done, even if it makes no money, it should be published. One day, you'll have a nice portfolio and bring more ideas to the teams you are part of. It's definitely a side project, though.