Iâ€™ve always been a fan of the winter living in the Chicago land area because like most typical northern cities in the United States you get snow, you get wind and most of all you get the amazing display of Christmas decorations down the Magnificent Mile. When the lights are going up in my mind that reminds me of something which in my job is much more important: the holiday shopping season is coming up on us.
A lot of online retailers and regular retailers love this time of season because they can drive people into their stores with a choice select items at outrageous discounts typically called door busters which bring people to their stores. I personally never partake in these sales because there have been far too many horror stories and Iâ€™m too impatient to wait 6 hours in the freezing to save a hundred dollars on a laptop.
The problem with these sales is apparent in both real retail stores as well as online stores: far too much traffic for a short period, which overloads capacity of the store/your solution. You announce for example for one hour you will provide a 20% discount on discounted items on your online store, start the discount and within 5 minutes the entire site is offline. System administrators try, as they might be able to bring your site back up due to the Denial of Service attack the sales generated. As frustrating as this may be there are some steps that can be done to help mitigate these problems. I work with a lot of our clients at SingleHop in scaling out their solutions and have used a plethora of different technologies to work with these kinds of issues. While I could write this post into a book of suggestions Iâ€™m going to give you four major ones that can help with the upcoming traffic your site is going to receive. While these might not work for all people this is just a general list of more popular tasks I have done here at SingleHop. Scalability is not a one-size-fits-all solution and at SingleHop we strive to be able to figure methods to scale any customers setup.
First and most obvious is scale out your back-end. MySQL supports replication that allows you to spread out your queries to multiple servers. The most common and easiest form to implement is what is known as Master/Slave replication. This allows you to send all select queries to an alternate server and leave the primary server for updates, inserts, deletes and any queries that need immediate data. You can also implement query and key caching by using the built-in key cache as well as a technology known as memcache for object caching. By reducing actual query lookups you are able to squeeze a little more juice out of your solution and stay up longer.
Second and just as important as the first, caching. You want to cache as much as possible and everywhere you can. My personal favorite caching engine is called Varnish which supports creating rules based on requests on what to cache. It also supports fragmented caching using edge side includes so you can partially cache a webpage and still generate the necessary dynamic content. There are also some good php opcode caching modules you can look into such as APC, eAccelerator and xCache. While you should not use all three you should look into implementing one into your solution that works. For example no PHP caching module work in a suPHP environment due to how a PHP process is forked from Apache. If you are utilizing suPHP I would suggest looking into FastCGI which will improve performance as well as provide the ability to cache while working similar to suPHP.
Third, look into offloading unnecessary traffic. Do you keep track of statistics in the same database as your product/sales? This is not a wise decision if you think about it: when you start your sale youâ€™re going to have such an influx of traffic youâ€™re essentially making your database work twice as hard for the same end result. Since traffic statistics are not the end-all of importance I would suggest actually moving them from MySQL to a NoSQL solution. Theyâ€™re scalable and also provide much better response for logging statistics versus MySQLLastly, cluster and distribute as much as possible. With all the new technology that is out there are so many ways to distribute a solution these days itâ€™s almost dizzying. To give a brief digest of some options: load balancing, distributed query cache, distributed object cache and replication.
We here at SingleHop utilize hardware load balancers along with many technologies to provide solutions to extremely complex ideas. Our mantra internally is â€śautomation, automation, automationâ€ť and along with automation comes scalability. While you can make something simple to shove out the door it needs to also be able to expand just as easily. Are you ready for the rush this year? If not feel free to contact us. We will gladly work over your current solution and provide a good idea of how to scale your solution to be ready for the coming rush of traffic.