Is your WordPress website scalable? There are many examples of large-scale WordPress installations in the wild. WordPress.com for instance is a huge multisite installation that gets tens of millions of pageviews each month. It also serves thousands of users at any given moment.
Other examples include Time, TechCrunch, and CNN. There’s no doubt about it. You can definitely build a scalable website with WordPress that is powerful enough to handle any amount of traffic, as long as you create the right environment. Configuring your installation to scale can be complex, but it is a worthwhile investment for any site owner. In this post, we go over a few areas that you can focus on to ensure scalability, and offer tips on how to set up a scalable environment.
What Do We Mean by Scalable?
What makes a WordPress website scalable? A scalable WordPress website has the ability to increase capacity by scaling up or scaling out.
- Scale up – increase the power of the hardware (more RAM, a more powerful CPU).
- Scale out – increase the capacity by adding more nodes (having identical copies of your site distributed among multiple machines).
Doing so gives you the flexibility to accommodate growth. Basically, you want to be able to extend your site without any problems. With WordPress, you won’t have to worry about the software. The WordPress core implements layered software architecture conventions, like separating markup (HTML and CSS) from data (MySQL database). Below we will explore some ways that you can ensure maximum scalability.
One of the hardest parts of scaling a WordPress site is setting up a development environment. A good development environment will mirror the production environment without any problems. If you have a small site, you can get away with developing live, although it definitely won’t scale.
You will need some sort of version control to make sure that the developers don’t step on each other’s toes. Version control software records changes to you files over time so that they can be recalled later. Plus it’s a much more efficient, professional way to develop a scalable WordPress website.
There are many elegant solutions available thanks to the hard work of the open source community. Git is a distributed version control software that allows multiple developers to work remotely on separate repositories. It is reliable, fast, and able to handle incredibly large projects. After all, Git was created by Linus Torvalds for Linux development.
You can build a killer development environment with VVV (Varying Vagrant Vagrants). This free open source software is ideal for creating distributed development environments with WordPress. Check out our The Ultimate Guide to Setting Up Your WordPress Development Environment for an in depth tutorial on this. WordPress.org also has a helpful tutorial on Installing VVV.
Scaling out, or horizontal scaling, is one of the most important concepts of creating a scalable environment. This allows you run your website on many different machines (servers). Some people call the infrastructure “elastic architecture” – because the amount of resources you have can expand or diminish based on how much is needed.
This is done through cloud computing methods such as clustering, load balancing, and virtualization. In computer science, clustering is the process of organizing similar objects into groups. So, a single cluster will contain your website’s files, database, and software. Clustering ensures that your website has high availability by eliminating problems due to hardware and software failure. How does it work?
If your site gets a spike in traffic, a load balancer will determine how to appropriately allocate more resources to pick up the slack by scaling out – this happens dynamically, and your visitors never notice a thing. The idea is that you have identical copies of your website distributed among multiple machines, and they all know about each other. So there is always a computer in the cluster on standby if there is an increase in traffic or a component of the stack fails.
Cloud hosting providers like Amazon Web Services (AWS) or Cloudways are two popular cloud hosting providers that enable horizontal scalability. Check out this tutorial on Deploying a Highly Available WordPress Website with AWS for an example of a typical server infastructure with elastic architecture.
A cache is a temporary storage space for memory. Caching can help you deliver content faster, and avoid problems with concurrency. Every CMS needs some sort of caching, WordPress is no different. The bad news is that caching can be ridiculously complex. The good news is that the open source community has come up with many different solutions on the matter. There are plenty of tools to help you, including WP Super Cache, and Batcache.
Reverse Proxy Caching (Page Caching)
Reverse proxy caching is an efficient way to load dynamic web pages. The reverse proxy is a service that acts as the middleman between WordPress and the browser. This can help reduce the load on your main server and decrease perceived page loading time.
The problem is that PHP servers are resource heavy. They execute a large number of complex tasks, which can bog down your server. You can lighten the load on your server by implementing a reverse proxy.
For example, say you get a visitor on the home page of your website. It is the first visit of the day. At this point, there is no cached version of the home page yet.
- User enters URL in address bar, requesting a page from the server.
- The request passes through the proxy, which doesn’t have a cached version of the page yet, to WordPress.
- WordPress generates the homepage, and serves the response back to the reverse proxy.
- The proxy then sends the response to the browser, and it saves a cached copy of that page.
- As long as the cache is there, any user requesting that page will receive the cached version of the page.
The concept behind object caching is similar to page caching, except it works on individual objects. Many concurrency issues can pop up when there are lots of users logged into your site. Object caching saves an application object (such a video, image, document) in a data store. By caching application objects, you are less dependent on the database, freeing up lots of memory.
There are many options for caching. Content delivery networks like Cloudflare, Akamai, EdgeCast and KeyCDN can act as massive reverse proxies. Varnish and WP Super Cache are two popular options to implement caching with WordPress.
The database can often be the cause of the worst bottlenecks. Slow queries can tie up the PHP application on your server, and bring all activity to a standstill – even if you have an elastic architecture. As I mentioned before, PHP servers can slow down the server signifigantly. If caching isn’t getting the job done, you can find ways to improve your query performance by identifying slow queries.
Slow queries are due to problems with the SQL database, the network running your site, or the server. There are a variety of reasons why this can happen. There is definitely no one-size fixts all. The first step to improving query performance is identifying slow queries.
Once you identify the problem, you can take action. Sometimes the answer can be as simple as buying more bandwidth, other times you may need tweak the code, which can get tricky.
Check out the WordPress Query Monitor plugin if you are looking for a tool to monitor queries.
If you have a large amount of posts, say 1 million, you will have to be mindful of how your databases are setup. Most larger sites have an optimized search index. Which is a custom search engine added to WordPress.
The content search query in WordPress doesn’t work well if you have a large number of posts on your site. It also leaves something to be desired in terms of speed. A common fix for this problem is to create a dedicated search index. Doing this keeps those queries out of the database, giving users a better browsing experience, as well as increasing the performance of your database.
Popular search engines for large-scale WordPress sites include ElasticSearch and ApacheSolr.
Starting at the right scale is also important. Start simple, then optimize later. To quote Donald Knuth, “premature optimization is the root of all evil.” Accommodate for growth, but don’t try to squeeze a huge ecommerce site on a tiny foundation or vise versa. You may not need to build a scalable site if it’s for something simple like an event page.
Typically, elastic architecture is the standard for eCommerce websites. While some of this stuff can seem incredibly complex, you don’t really need to understand it all. As long as you have a grasp of the basics, you can build a robust environment for a large-scale site. All you need to do is find the right cloud services, and hook yourself up with the right CDN.
Feel free to share your experiences in the comments section. What steps did you take to make your WordPress website scalable?
Article thumbnail image by turbodesign / shutterstock.com