Sep 19 2012

WordPress as a SaaS Application Part II… Speed and Scalability?!

feature
116 Flares Twitter 23 Facebook 41 Buffer 3 Buffer Google+ 6 Pin It Share 0 StumbleUpon 41 Reddit 2 LinkedIn 0 116 Flares ×
A Series of Three Parts: WordPress as a SaaS Platform, The Second Part

So, you’ve decided to use WordPress as your application platform. Where do you start so your application performs well and scales easily? Well, setting up an efficient WordPress application is one part web server configuration and two parts clever application software programming. Start with a good server architecture, well programmed plugins and themes, the right WordPress installation mode and you’ll set yourself up for success.

Server Configuration

A good server setup is key to having a well-performing WordPress application. Shared hosting solutions you may normally use for a WordPress blog are not going to cut it for a full-blown application that thousands (and eventually hopefully millions) of users will be logging in and out of and interacting with on a regular basis. Your best bet is your own custom software stack, or a server, as a solution partner if you’re less command-line inclined (more on that later).

LNMP, is the new hotness. LAMP is old and busted.

For Hello Bar we set up a higher performance web server stack using an LNMP stack (Linux, nginx, MySQL and PHP-FPM). The combination of nginx and PHP-FPM (PHP as a FastCGI Processed Module) with APC installed make for a much faster, lighter weight, lower memory use server stack that can help you scale your application easily and not force you to scale as early. Iliya Polihronov recently gave a talk at WordCamp San Francisco about setting up a WordPress server using this stack and provided a great starter configuration for your own stack. EndofWeb also has a great article on setting up a full server stack from scratch using Ubuntu.

Cache ALL the Things!

When dealing with thousands of requests per second, caching is the best thing you can do to speed up your web application. With Hello Bar we utilized everything including APC for Object caching and for speeding up PHP in general, Batcache with Memcached to cache publicly viewed pages, and even file caching with nginx and URL rewrite capabilities. Caching systems that allow your web server to pull the cached data directly, avoiding PHP all together, provides a huge performance boost to those portions of your application. There are many caching technologies available and numerous caching plugins to help cache your web application. Just make sure that you are writing your application to clear caches when they need to be. You don’t want a list of entries a user has made to not update because the cache is stale.

Cache All the Things!

All the Things! from Hyperbole and a Half

Replicated Database

When running a high traffic site, one of the biggest bottlenecks becomes the database. Luckily, WordPress’ database library is implemented in a manner so that it can easily be adapted to a multiple database solution. By using the HyperDB database plugin, you can configure WordPress to distribute individual tables into multiple databases, provide failover support (when a connection to the database couldn’t be made), and most importantly, provide support for replicated MySQL database clusters. MySQL can be configured to automatically replicate any command sent to it to another MySQL database on another server. This creates two or more nearly real-time synced databases that WordPress can read from and serve back data. How To Forge has a good article about setting up a replicated MySQL server cluster and this article by HBY Consultancy also provides some good insight on getting this setup.

Ensuring Good Communication

Communication with your users is important and it’s most likely that you’ll be using email as your primary means of communication. To ensure the greatest deliverability of your email communications and to avoid a lot of the problems that go along with keeping your web server’s IP address white-listed, I recommend that you use an external email service. SendGrid is an easy to setup SMTP server that you can get integrated on the cheap. Just use a simple SMTP plugin such as WP Mail SMTP or WP SendGrid for your WordPress installation and all your wp_mail() function emails will be sent through the reliable, white-listed and stats rich SendGrid service instead of your own host’s email.

Setting up WordPress for Success

While a good hardware configuration makes for a solid foundation for your application, it won’t mean a thing with poorly configured software.

Intelligent and Picky Shopper

Intelligent and Picky Shopper from Shutterstock

Good Plugin Authoring

If you aren’t picky with the community plugins you choose to run or you’re a little sloppy with your own plugin authoring, then your WordPress application can become a bloated beast rapidly. Now, this doesn’t make WordPress a bad platform, it does however require some strategic planning when preparing it for use as an application platform due to its diverse community and ease of entry for plugin authorship. When authoring your own plugins and evaluating community plugins for use, consider some of the following practices:

  • Use good programming techniques to keep your code as flexible as possible. Take advantage of the numerous functions WordPress has made available to you for querying posts, database querying, object caching and transient caching. All of these plugins are already setup to be adaptable and flexible for caching and scaling, no need to write it all from scratch.
  • Take advantage of the numerous constants WordPress defines to make your plugin data dynamic and flexible. WP Engineer has a great article on some of the most useful constants you’ll want to take advantage of.
  • Follow the Plugin Development Suggestions that the WordPress group provides in their codex.
  • Make sure to validate your data. Poorly validated or non-validated data submission can be the death of your application. The WordPress Codex has a great article on how you should be approaching data validation and sanitization.
  • Be as light on your client-side assets as possible. Only load the JavaScript and CSS files you need for your plugins to operate when they are needed and don’t just blanket load them across your entire website. WordPress provides numerous conditional functions for your plugin to be aware of where it is being requested from; use them when enqueuing assets.
  • The more files you load the larger your memory footprint. Try and load only those files that are necessary for your immediate needs. Take advantage of Class autoloading and PHP5’s magic methods for OOP development to load files only as they are needed.

Sometimes of course there will be plugins that you’ll absolutely want to use in your application, but you don’t need them to load everywhere. Check out something like the Disable Plugins MU plugin for a lightweight solution for filtering out plugins from being loaded where you don’t need them.

Pick the Right WordPress Operating Mode

Depending on the needs of your application, you may want to consider operating WordPress differently. WordPress out of the box is configured to run as a single website installation and this works fine for most situations. If your application is offering lots of user controlled, maintained, and published content, you may want to consider running WordPress Network. This will provide additional super-administrative controls to you as the application owner and provide a better setup for horizontal hardware scaling and opportunities for sharding your databases with the previously mentioned HyperDB or ShardDB.

Lever of Switching

Lever of Switching photo from Shutterstock

A lesser known mode for WordPress to operate in is a headless mode that gives you greater control on exactly what is being loaded and used to process your data. To enable this, just add define(‘SHORTINIT’, true); in your wp-config.php file before the require_once(ABSPATH . ‘wp-settings.php’); line. This will load the bare minimum of the WordPress system and give you better control of customizing what gets loaded. Check out this article on How WordPress Boots Up to get greater insight on what this constant does to your WordPress installation’s normal operating process to see if its the right move for your application.

In Conclusion

Creating a high performance, WordPress-powered application is founded in careful planning and judicious selection of plugins from the community. So with the next WordPress app you build, roll up your sleeves and do some planning beforehand. Make sure the plugins you choose are of good quality, plan your plugin creation strategy for speed and modularity, and lay out your server setup for easy scaling and you’ll set yourself up for success.

Any good suggestions or techniques for setting up WordPress for speed and scalability that I didn’t cover? Contribute to the knowledge pool in the comment thread below!

Useful Links for Building WordPress Applications:

About the Author:

As the Lead User Interface Developer, Dave uses his development and interaction design experience to help create the most usable and innovative web interfaces. He works closely with the development, design, and marketing teams to strategize the most effective interface layouts. He has had extensive experience in front-end scripting, layout architecture, and interface development.He holds a Bachelor of Science degree in Media Arts with an emphasis in Web Design from Platt College of Graphic Design, San Diego and graduated with honors at the top of his class. In his off-time Dave enjoys spending time with his wife and when occasion permits, visiting the land of Azeroth on the back of a flaming hell-steed - a unique juxtaposition to his off-line life.Find him on Google+

introducing

Design Lab

Help us redefine the
standards of web design
Enter the Lab

Inventions for the Screen

Design Lab is an innovation platform for creating digital design products.

Leave a Response

4 Responses

  1. Sep 24 2012
    Jordan

    These two articles have been sort of mind blowing. I would never have considered WordPress as a reliable SaaS platform, but you’ve made a great case. Most of your suggestions could also be applied to any popular WordPress blog for some huge improvements.

  2. Nov 12 2012
    migaber

    … and another amazing article, you give me another view for “How to scale your server” as it was very hard to me to understand why my website hangs… I’ll try LNMP and feedback about the results

  3. Jan 06 2013
    mit.dhk

    u nailed it dude. my whole concept is changed specially choosing wordpress for large scale development.many many thanks :)

    • Jan 07 2013
      dtelepathy

      You’re welcome! =) We definitely discovered a lot of possibilities throughout the process.

116 Flares Twitter 23 Facebook 41 Buffer 3 Buffer Google+ 6 Pin It Share 0 StumbleUpon 41 Reddit 2 LinkedIn 0 116 Flares ×