I recently gave a talk at cPConference 2018 about High Availability for web applications, and specifically how High Availability can be implemented with WHMCS.
In this blog post, I'm going to attempt to summarise that talk and demonstrate how WHMCS can be deployed in a high availability setup today, as well as look at what we are doing in WHMCS 7.7 to make a High Availability deployment easier to achieve in future.
So what is High Availability?
Availability is used to describe the period of time for which a service is online and operational. With high availability, we're trying to create a system that operates continuously, even when some of its components fail. We do this by eliminating single points of failure and thereby keeping things online more of the time.
At its simplest, High Availability is the idea of having redundancy at every level of the web stack. That redundancy is typically provided in one of two ways:
In an active/active setup, each component has two instances, and both are in operation concurrently with traffic distributed equally between them while ever both are operational.
In an active/passive setup, each component again has two instances, but only one is ever in operation at a time. When one component fails, the other component "wakes up" and becomes the active one. This is commonly referred to as a failover setup.
What are the benefits of High Availability?
- Eliminate Outage Costs - By keeping your business online all of the time, you're always available for business and not missing out on revenue
- Improved Fault Tolerance - Downtime and service interruptions due to system failure are eliminated
- Easier Scaling - A High Availability setup is a stepping stone to load balancing that enables you to scale horizontally and distribute visitor traffic accross multiple machines
- Seamless Maintenance - Ability to perform system updates and maintenance one node at a time so customers are not impacted
- Improved Security - Enforce better separation of responsibilities allowing for stricter control around security of each component of the system
- Customer Trust/Loyalty - Build customer trust by always being online and available when your customers need you.
What considerations are there for High Availability?
To achieve High Availability for WHMCS, at minimum we need at least two web server nodes. In addition we must implement all components of the system in a way that is stateless. There are 4 key areas that must be considered:
Filesystem Storage - WHMCS has a number of scenarios in which it writes to the file system. These files must be available across all instances of the deployment.
Sessions - Sessions need to be setup in a way that allows users to transition seamlessly between any of the web server nodes.
Database - To achieve redundancy for the database layer, we need to employ replication to provide us with multiple copies of the MySQL database.
Load Balancing - To distribute traffic between our web server nodes and detect when a web server node becomes unhealthy, we need to employ a load balancer that can distribute incoming traffic.
So with the above in mind, here's how this type of setup could look:
Figure 1: WHMCS High Availability Setup for WHMCS 7.6 and earlier
In the above example, our user hits our load balancer which is configured with session stickiness/affinity so that a single user always hits the same web server. This allows for session persistence. A network attached storage device is used for sharing files between the web server nodes, and our database has a master/master replication setup. The web server nodes in this example can be scaled horizontally as needed.
What are we doing in WHMCS 7.7 to make it easier?
In WHMCS 7.7, we're introducing 2 key new areas of functionality that will make it easier to deploy WHMCS in a highly available configuration. These include:
1. Amazon S3 Support for file storage - Amazon's S3 service offers unlimited storage space, high levels of durability and is cost effective. This removes the reliance on the local filesystem and adds the ability for WHMCS to natively use S3 for all file uploads. This solves one of the challenges with a load balanced setup by removing reliance on the local filesystem.
2. Support for database driven sessions - By moving sessions into the database, this will simplify load balancing setups by allowing users to transition between multiple web server node instances seamlessly without losing session state.
So with these changes, let's take a look at our example again with WHMCS 7.7 and later:
Figure 2: WHMCS High Availability Setup for WHMCS 7.7 and later
In this example, we are now using AWS, and taking advantage of multiple availability zones within an AWS region for increased redundancy. This time we no longer need to have our load balancer using session stickiness and are using S3 for attachment and download storage. The rest of the setup remains largely the same, but by introducing database backed sessions we can benefit from true load balancing and have reduced our overheads in managing a NAS device for shared file storage.
This is only a high level overview of what's required to deploy WHMCS in a HA setup but hopefully it goes some way to introducing how High Availability can be achieved with WHMCS. As cloud computing has become more prominent, and services have come down in cost, High Availability has become increasingly accessible. With the likes of AWS, a setup such as the one above can now be achieved relatively inexpensively.
A copy of my slides from the presentation have been made
available here and if you have any questions, please feel free to ask them in the comments below.
Liked this article? Share it