Cloud modernization, part Magic

Cloud modernization, part Magic

Today’s Best Band Ever™ is Carsie Blanton. It's the only artist I can choose after this week's midterm elections in the US. The people have spoken.

Difficulty: "I'm too young to die" or "Hurt me plenty" depending on whether you struggle with political messages in music.


The world

Still hard to say if it's related to Ukraine attacking russian data centers, but recent elections in Brazil, Canada and the US hint that "pay ruskies to swing an election" might not be as effective as it used to be.

Supermarket fridges in ten European countries have been attacked, causing millions in losses. Again. I heard there's a subset of cybersecurity that is treated like insurance: potential events are prioritized by probability and damage recovery cost. Here, the probability was 100% and the cost was in millions. Enterprise cybersecurity is surreal.

Access to AI-assisted coding is bringing interesting results. Someone got tired of Adobe's pricing model and now there's now an open-source clone of Adobe suite. People laid off because of AI-efficiency are creating open versions of their ex-employers' products. REA: reverse engineer anything. Something big is happening.


Back to modernizing clouds

Quick recap.

Back in August, I decided to move from Substack to a self-hosted instance of Ghost. Since this blog is at least in part about cloud architecture, I'm using this as an opportunity to see how cost-efficient I can make the setup. Starting with a single VM, modernizing it into containers and eventually going full serverless.

The goal stays the same: run it as cheaply as possible without compromising on quality.

Here's how it's been going

Phase 1. Baseline.

End of August 2026. Single VM. SQLite DB on disk. Terrible reliability. Awkward performance. $18/month cost. 4 hours of work.

Phase 2. Refactor.

Mid-September. Lightsail for containers. Concurrent-write SQLite stored on S3. Scalable and resilient. Tolerable performance. $13/month. About 30% cheaper than VM. 16 hours of work.

Phase 3. Serverless magic.

End of October 2026. AWS sends me a notification that I've used 85% of the Lightsail free tier (thank you!). Time to rumble.

As usual, you are reading this blog entry on the fully serverless setup of Ghost. Here is a short version.

  • SQLite-on-S3 is still the DB.
  • Lightsail is replaced by Lambda functions rendering the static content and serving the dynamic content.
  • Cost: $4/month. 70% cheaper than Lightsail with same reliability and availability. 78% cheaper than the VM baseline.
  • 6 days from start to the last deployment. Minus 2 weekend days and nights. So roughly 30 hours. By far, this was the most laborious modernization.
💡
Did you know?

A 100% available VM-only workload can be optimized by around 30% through reservations. Scheduling gives up 100% availability (so not really applicable to production systems) but can stretch the savings to approximately 50%.

A properly cloud-native decomposed workload can lose up to 90% of its cost. While remaining 100% available and resilient.

Interestingly, Claude Code reports that out of an almost week-long session, only 3 hours were spent calling the API, and the session was auto-compacted 5 times.

Session

Total cost:            $53.95
Total duration (API):  2h 59m 53s
Total duration (wall): 6d 23h 36m
Total code changes:    37 lines added, 5 lines removed
Usage by model:
   claude-sonnet-5-5:  70.0k input, 1.0m output, 306.6m cache read, 3.2m cache write ($53.84)
    claude-haiku-5-5:  178.7k input, 10.9k output, 0 cache read, 0 cache write, 9 web search ($0.1133)
Prompt cache (main):   209 requests · 99% of input tokens from cache · no misses · 1 expected rebuild (compaction or tool-result clearing) · warm (1h TTL, last activity 1m 55s ago)
Main changes to the architecture
  • 16 Lambda functions replace an always-on Lightsail container (1 x 256 MB, 7 x 512 MB, 5 x 1024 MB and 3 x 2048 MB).
  • HTML (including blog posts) is pre-rendered and served statically from S3.
  • SQS manages the rendering queue.
  • API Gateway serves the dynamic content from Lambdas.

A web application in Lambdas?

One might ask: "Are 16 Lambdas enough to serve a web application like Ghost?"

What an excellent question! It's especially fitting since, in my last post, I concluded that the new AWS feature for running web apps in Lambda is not cloud-native.

Indeed, Ghost has approximately 300 registered Express routes.

Theoretically, I could have gone with 300 Lambda functions and routing only once, but the catch is that Ghost is still a "traditional" web application, meaning it expects to start once and then stay serving forever. The main downside of this approach is that startup is usually accepted to be relatively slow: load the configuration, initialize the database and services, run migrations, and so on. A five-second start is tolerable for an always-on container (few users seem to have suffered that), but would be intolerable (and frequent!) if every route were a separate Lambda doing a full initialization on each start.

Thus, I had a choice: rearchitect Ghost's codebase to make functions start fast, or group functions likely to be called in quick succession (saving a draft or uploading an image, for instance) and benefit from the Lambda staying warm.

So far, I have been trying to keep Ghost as pristine as possible to allow for easy upgrades, so rearchitecting the codebase is not on the table. Group functions it is.

Effectively, I implemented the same logic as the Lambda Web Functions that I criticized so happily just a couple of weeks ago.

In the end, sixteen Lambda functions group functionality by category. For example, the heaviest admin-audience, serves 34 routes, preview eight, link redirect one, and so on. This also means that the routing happens twice: first in API Gateway (129 routes) and then via a custom Express route table in each Lambda.

The whole repository is here.

💡
Should I have used the new functionality instead?

I considered that but discarded it for several reasons:

1. It's so new that neither OpenTofu nor Terraform supports it yet. CloudFormation does, but it's something I prefer to avoid.
2. Fixed 2 GB sizing (awkward!)
3. Only the classic event-based Lambda function pricing mentions the monthly free tier. Web Functions charge only for active CPU usage, but a rough estimate put the maximum cost at $19/month. Unlikely, but it would've been awkward to have to pay more for Lambda than for a VM.
4. There's a risk that one CPU-heavy call might block the neighbors (each function can serve up to 128 concurrent requests).

All in all, this might be a future optimization, but even then, I would separate the app into several environments based on colocation safety.

The only drawback so far is that the statically served pages don't reflect the logged-in status of the user. Sorry, Alok, you are the only affected user so far.

And now, AWS optimistically thinks that my monthly cost will stay at $4. This is mostly true except for the occasional domain renewal spike.

Nice.

How cloud-native is it now?

Finally, let's do the cloud-nativeness check.

For our new readers, here's a refresher I proposed to measure it:

A cloud native solution
- runs only parts that are needed at the moment (on demand)
- runs them only for as long as they are needed (just in time)
- runs in the most cost-efficient way (cost centric)

Each point covers 33% of the whole.

Runs only parts that are needed at the moment (on demand)

Partially. 16/300 is about 5%. For Lightsail, I counted S3 ⇾ CloudFront as 5%, so let's say this is now 5% + 5% = 10%.

Runs them only for as long as they are needed (just in time)

Yes. Things only run when explicitly requested. Full 33%.

Runs in the most cost-efficient way (cost centric)

Yes. It's a small solution, but I got as close to zero as I could. Full 33%.

So, interestingly, this solution is "only" 76% cloud-native.

Perfection is hard.

Still, we went from 10% on VM to 36% with containers, and now at 76%.

That's a 66% overall improvement by means of cloud architecture. The remaining 24% is hidden in Ghost's solution architecture.

What's next? Getting to 100% cloud native brings no cost improvements, so let's see.


Stay tuned, stop aggressors and fight Nazis no matter what they pretend to be or the country they come from.


PS. No word of this blog is written by a GPT (I do use it to tell me I missed an article and such).