5 Backend Optimizations for Quicker Content Delivery
February 6, 2015 | Robert Gibb
- File size means less. How files are delivered means more.
- The Internet’s core infrastructure is improving (faster browsers, LTE/4G, etc.)
- There are now more “cheetah-speed” backend optimizations you can implement.
In this post, we’ll tell you why and how to implement these backend optimizations to take full advantage of the Internet’s backbone. Just keep in mind these tactics do require a systems administrator. (Rest assured though: You can easily find one on a freelance platform, even LinkedIn.)
In the future, we’ll create a similar post on frontend optimizations, but today it’s time to take advantage of that beautiful backbone. You’ll soon discover that these tactics are fairly low effort and carry huge performance payouts. Especially this one ...
Recently, we’ve been talking a lot about boosting the performance of your web server with SPDY. So why did we feel the need to bring it up again? Because the results are simply astounding, almost unbelievable. Consider these three facts:
- Websites that have SPDY enabled see a 28 - 64% speedup.
- SPDY shapes HTTP traffic as it leaves the server, making any modifications to your web application unnecessary.
- Almost all current major browsers support SPDY, and those that don’t will safely revert to the current HTTP standard.
Most SPDY-supported websites use the Nginx web server that has an
ngx_http_spdy_module you can use. For Apache, Google provides the
mod_spdy module. The only requirement for SPDY is that SSL is enabled. Because it’s so easy to install and configure, there’s no reason not to use it.
Keep in Touch
Each time a web browser requests a resource, it creates a new connection to the server. While this is great for websites that only have a handful of resources, modern websites need a bit more flexibility.
The HTTP keep-alive header resolves redundant connections by creating an open connection between the browser and the server. This allows the browser to download multiple resources without adding more overhead by fetching multiple files within a single connection window.
By default, HTTP treats all connections as persistent. The difference lies in how long each connection is kept open. Having a longer keep-alive time reduces bandwidth and lets users download more content faster - at the expense of memory and bandwidth usage on your servers.
Keep in mind that keep-alive can lead to denial of service attacks when a large number of users connect to your service simultaneously. Finding the right balance will depend on the type of website, server resources, and number of users.
Action Step: Enable keep-alive.
Share the Load
The importance of caching is often overlooked in web development. When dealing with lots of static assets, caching can have a huge impact on your website’s performance and your users’ patience.
Caching lets web servers store and serve copies of data from several locations, including the user’s browser. Two primary HTTP headers control caching behavior.
- Cache-Control header: Dictates if any nodes besides the origin server can store a resource. Usually, when connections reach the destination, they are walked through different proxies as well. If you have the ability to cache, all of these will honor cache control headers.
- Expires header: Dictates when cached resources are no longer valid.
Tweaking your cache settings lets you determine how often users access your origin server in order to refresh content.
A lot goes into making a dynamic, database-driven website faster. While static websites serve plain content to each user, most websites provide content that has to be retrieved from a database. One way to shorten this step is to cache otherwise dynamic content in advance.
For instance, Apache web servers perform caching using the
mod_cache module. When a user accesses a URL,
mod_cache creates a hash of the URL and stores the content along with any metadata. Depending on whether you use the
mod_mem_cache module, the content is stored on either the disk or memory.
Each asset is also assigned with an expiration date, after which the web server refreshes the cache. Rather than having to access the database each time a user requests a webpage, you can serve database-driven content at the same speed as static content.
As a CDN, one of our goals is to distribute your content to all points on the globe as quickly as possible. To do this we use a technique called proxy caching where we store copies of your content on servers around the world. When users visit your site, they’re deferred to these copies instead of your origin server, saving your customers time and saving you bandwidth.
Action Step: Leverage these types of caching, plus leverage browser caching.
Put Big Things in Small Packages
There’s a lot of extra data that goes over the wire whenever a user accesses a website.
Web servers can either serve pre-compressed content or compress resources on-the-fly. Dynamic compression works best on text-based assets, while media files are often served pre-compressed.
Action Step: Enable GZIP compression.
Tune Your Server
There are many ways to tweak and modify your web server for faster performance. Each web server will have its own configuration settings and options, but there are a few modifications that will affect all servers.
- Upgrade your hardware. Throwing more power at a problem isn’t always the solution, but if you notice your servers are constantly running out of CPU or memory, it may be worth investing in some better equipment.
- Go lean. Web servers uses modules to extend their core functionality, many of which you won’t need for your web service. Removing extra modules will trim down memory usage and help your web server processes run faster.
- Maintain. Keeping your webserver up to date is essential for maintaining security and performance. Review and rotate log files, schedule software updates, and always keep frequent backups.
Not all websites are created equal. Based on the nature of your services, some of these tips might work for you while others won’t. Nonetheless, optimizing your website will lead to increased customer satisfaction, even more revenue for your business.
If you have any additional backend optimization tips, feel free to share them in the comments section below.