Learnings on cutting TTFB to ~55ms

Last week, I provisioned a new server for Magic Pages and was hit with an unusually high Time to First Byte (TTFB) – sometimes up to 1.5 seconds. It that turned into a bit of an adventure in optimisation. I thought I’d share what I learned in the process, maybe it can help some of you tweaking your own Ghost setups.

While trying to figure out what I can do to improve the TTFB, I dived into different aspects of all the networking that was going on between my browser and the server hosting my Ghost site. Here are my biggest takeaways:

  1. CDN Setup: I realised that a CDN really shines when your traffic is geographically diverse (duhh). For geographically closer requests (e.g. I am located in the north of Austria, my servers are in the south of Germany), directly serving from the server, rather than going through a CDN, was actually quicker.
  2. Cache replication: After setting up BunnyCDN (the standard CDN for Magic Pages sites – wrote about my setup here), I activated Perma Cache for this experiment with replication in all data centers. I excluded certain routes like (/members* and /ghost*) to optimize the caching behavior without affecting dynamic content updates. This was quite a big improvement to just using BunnyCDN without the Perma Cache.
  3. Local Data Center Hosting: Hosting my test site and all related services (like databases and reverse proxies) in a local data center (Hetzner’s Nürnberg center) drastically cut down latency (again, duhh). Now, for a single Ghost site, you probably would have everything on one server anyway, but for Magic Pages, different services have different servers. While I didn’t think a 25ms latency between data centers mattered much, moving all services into the same center cut down TTFB by a lot.
  4. Ghost’s built-in caching is powerful: If your site does not have regular content updates, increasing the built-in cache in Ghost might really be the easiest lever. When I set the frontend cache to 3600s (one hour), it cut TTFB from 250ms to 100ms – without any of the other adjustments.

After all the experiments, TTFB on my test site is now 55-60ms (vs. around 250ms when I started without any optimisations on a fresh installation). Next step: replicating that on scale for all Magic Pages sites.

If you want to know more about the experiments I did and how I measured it, I wrote about it in my personal blog: https://www.jannis.io/i-accidentally-created-the-fastest-ghost-cms-hosting/

5 Likes