5 Essential Tips to Improve Your Magento TTFB

Time to first byte (TTFB) is one of the most important speed metrics of a website. It indicates how much time will pass after a user enters your Magento store URL and the time they get any response, even as small as 1 byte (hence the name, “time to first byte”).

Time to first byte is vital both for humans (they don’t like to wait around) and for search engine robots (Google hates slow websites and ranks them lower ― click here to learn more about first-in-class Magento 2 SEO solution by MageWorx).

But at the same time, there’s convincing evidence from John Mueller, one of Google’s talking heads, that Google doesn’t use TTFB for rankings:

So, our advice is to not obsess over TTFB too much for SEO, but instead, focus on user experience and store performance.

Why TTFB is more important than full page load (called “time to last byte”)? Well, because the sooner you load the first byte, the faster the users will begin to read your content. It doesn’t matter that they can’t see every picture on the page instantly. It’s more important to offer the users something to do while your web server is busy loading the rest of the content.

1. Understand Your Bottlenecks to Eliminate Them

What’s a Good TTFB?

Google states that a TTFB under 200 ms is the goal. Below 200 ms the search engine will rank you highest. Once you go above this value, Google will apply penalties to your website. 600 ms or more means you can’t even pass Google’s own TTFB test.

There are a lot of factors that will affect your TTFB. In no particular order:

web server configuration and resources,

nameserver resolve speed,

on-page code execution times,

implemented backend caching solutions,

network conjecture.

Check your TTFB value either with a third-party service or using Google TTFB test. You can also compare your results with popular websites or with your competition here to get a unique perspective on how your store loads for mobile users.

Another great diagnostics tool is Magento 2 Profiler. With it, you can easily break down every page request into smaller blocks that are fast to visualize and analyze.

In the table, pay special attention to 2 important values, Time and Count. Time is self-explanatory. It’s the actual delay between the user request and the server response. The Cnt row corresponds to how many times this item was called before it created the output.

This is the first step you’d need to take: enable Magento Profiler and look at pages that have the biggest problems with TTFB. While you can use default profiler, we recommend you setup Profiler SQL. It’s free and offers a convenient overview of the number of queries per session.

The Profiler will slice all requests into smaller parts so you can immediately see which sections drag you down.

2. Migrate to a More Suitable Database Engine

Magento 2 store database can easily become the biggest performance bottleneck if it’s inefficient, slow, or uses a storage engine that’s not the best choice for handling Magento.

Why is this important? There’s ample choice of various storage engines for MySQL. We’ve counted at least 10 supported solutions in the official MySQL documentation and there’re even more out there in the wild.

While you can use Magento with the default MyISAM MySQL engine, alternative database engines such as MariaDB Aria storage engine or Percona XtraDB engine can make your store more stable and (sometimes) faster compared to the default setup.

For example, Aria engine uses a smarter approach in cases where Magento forces the storage engine to use a lot of temporary tables.

Percona is another fork of MySQL that has integrated over time a number of performance tweaks to speed up database queries. Compared to MyISAM, it works much faster with a lot of parallel queries and specializes in transactions processing.

Even though the best recommendation for database optimization would be to carefully examine your needs and choose the engine that best suits you, we have a few tips that will be useful for everyone:

3. Match Server Setup to Your Current Traffic Needs

Cheaping out on infrastructure is not a good idea. Over time, a steadily growing business will see more customers, more transactions, and more orders. So, it’s healthy to keep your setup at 80% capacity to adjust for random use spikes and event-generated foot traffic. That 20 % can go a long way to maintain a decent level of performance in all situations.

A hosting team that is worth their salt will tell you, what system requirements you need to operate smoothly. But if you have grown rapidly over a period of time, it becomes your own responsibility to outline a roadmap to upgrade.

There are a number of critical points in your Magento store that will heavily influence your system requirements:

store size (number of store views),

categories and SKUs in the catalog (with attributes and attribute sets),

average traffic numbers (average page views and historical peaks),

transactions per day (digital downloads, payments, and similar operations).

In general, your average traffic will directly influence how much CPU power you need. So, after you find out the optimal CPU setup, match your RAM to your CPU requirements to create a balanced web server profile.

Database storage size depends on your current RAM, so you should pick up just enough to cover all current needs. Create a performance cushion for some breathing space, too. Your goal is to always keep at least 20-25% of spare CPU and RAM to deal with occasional traffic spikes.

4. Setup a Better Caching Solution

Website caching is the next best thing after the invention of french fries. Server cache improves the snappiness of the website making it feel much faster. Caching works by moving frequently used data from SSD or a hard drive to RAM.

Where HDDs can sequentially read data up to 200 MB/sec and SSDs up to 3200, DRAM modules can go as far as up to 20 GB/s. Which gives us the difference of x10 or at least one order of magnitude.

Both Redis and Varnish are one of the most popular upgrades for Magento stores. It’s a recommended caching option for Magento 2. Both solutions work great with Magento 1, too.

Varnish is a challenging tool to configure, but when done right it offers TTFB values in 100-200 ms. For full-page cache configurations, TTFB will range within 250 ms.

Another distinct advantage of Varnish ― it works on more web pages. While FPC doesn’t work for pages with a lot of dynamic content on them, Varnish offers better performance even for these challenging use cases.

5. Get Rid of Useless Extensions

To be honest, disabling unused extensions is the #1 tip for any Magento 2 store but it often gets overlooked. Every extension that runs on your website will use up some of your resources. If they are configured poorly, they could also slow down your TTFB.

Remember: the server needs to execute this code before it sends any feedback to the user.

Cleaning up your extensions list will also speed up Magento. Even if you can’t disable any of them, keep both your Magento store and your third-party extensions up to date to benefit from bug fixes and optimizations that will certainly make your site performance better.

Bonus Tip: Tweak Store and Customer Logging Settings

Make sure to turn off Magento customer logging. This will help you reduce the time spent on database queries. It’s not a huge impact since customer logging is a relatively minor activity. The performance boost will depend on the number of customers currently visiting your store.

We don’t recommend you to turn off store logging. It’s a valuable tool that helps in Magento troubleshooting. But instead of letting store logs take up server time, you can move them to a third-party service, such as Papertrail.

A Constant Battle for Performance

No two Magento stores are the same. Each of them will face different challenges in optimizing their storefronts for speed. This can be especially true for older (and bigger) Magento websites that have a lot of complex third-party extensions, large databases, and multiple stores.

And while we can’t ever “win” this battle for performance, our common goal is to make Magento stores best in class in speed, user experience, and security among all ecommerce websites.

About the author

Vasili Nikolaev is on a permanent treasure hunt to dig up the most effective tips to make the life of store owners a little bit easier. There’s nothing more satisfying than finding a great solution to a challenging problem for him.