Remember when Ellen DeGeneres’ viral Oscar selfie crashed Twitter? Or when Coinbase’s app and website went down because of the crazy traffic generated by their Super Bowl ad in 2022?
The list goes on, but the point is that even the biggest sites with the most reliable servers in the world can crash due to heavy traffic spikes, so your website may crash too if you don’t take the right precautions.
In this interview with
Website Planet, Ivan Messina, CEO and founder of
SupportHost, details the steps to prevent a website from crashing due to a sudden surge in traffic, and what to do if that happens.
P.S. This guide comes from Ivan’s experience building the server infrastructure able to sustain 1.5 million page views per day with zero downtime for “Italy is simply extraordinary: be IT”, the biggest Made in Italy promotion ever created.
How does a website use a server’s resources
Let’s take a WordPress site as an example, since WP is the most common CMS.
Every time a client visits a page on your website, thousands of php files are processed by the server and the database receives a couple dozen requests. To process all these files and process the database requests needed to generate the HTML of our webpage, the server has to use some CPU, RAM, and other limited resources.
Moreover, every plugin installed on your WP site adds more PHP files and database requests to process. Some plugins will use more resources than others, but in general the more you have, the more resources you will need to use them.
On the other hand, the amount of resources needed to load an HTML page is minimal, because it’s just about reading one file and serving it. When we use a cache plugin, or server-side cache, this is exactly what we do. We generate a static file and serve that file to the next user visiting that exact page.
If you go above the resource limit, your server gets overloaded.
What happens when a website is overloaded?
When a website is overloaded, it doesn’t have enough resources to handle the amount of heavy database requests coming from unexpected traffic spikes, so all applications and websites on that server crash and become unavailable.
Why does a website crash during high traffic?
A website crashes during high traffic because the server’s resources are too limited to handle the number of visitors and their activities on the website. The server gets overloaded, and the website goes offline.
Every hosting plan has limits, whether they tell you or not, since unlimited CPU and unlimited RAM do NOT exist. A shared hosting will have lower limits compared to a dedicated server, but this doesn’t mean that the dedicated server is unlimited. It’s a false claim!
Shared web hosting providers use specific pieces of software to set the resource limitations for each of their subscribers accounts. The most popular is by far CloudLinux.
If your website uses more resources than allowed on a shared server, the software automatically blocks your account and your website goes offline. This way we don’t have to put the entire server down, and guarantee that all the other sites hosted on it remain online. It’s a safety net for our customers.
Similarly,
on a dedicated server these limits depend on the hardware – If we try to use more resources than the server has available, this will crash, and your website will go offline until the traffic spike ends.
However, the number of requests (users visiting your website) is not the only factor affecting your server’s loading capacity. In fact, some requests are more complex than others. For example, a programming error can generate a sudden surge in resource usage, and put the website offline with just one page load.
Those more complex requests are the bottlenecks that increase the risk of your website slowing down or even going completely offline.
How to prevent a website to crash from heavy traffic
In my opinion, these kinds of problems are the worst. You have a traffic surge, maybe because one of your posts or video went viral, an ad campaign,
or a big influencer that mentioned you. All this massive number of users land on your site… And they find it offline! Not the best first impression.
As in real life, you should always be ready for the worst (and hope for the best!). For websites, this means that
you need an infrastructure ready to handle sudden traffic spikes when they occur.
Start by asking yourself these two questions:
- How many visits are you expecting?
- Is your current hosting plan capable of handling that, or do you need to go for a more powerful plan?
Once you have cleared those two points out, follow this checklist of actionable steps to prevent your website from crashing during high traffic.
-
Cache your content
A cache reduces the network requests on a server by returning a previously stored version of your website’s content to new visitors.
A server side cache is usually better than a caching plugin (like W3 Total Cache or WP Super Cache), but in the end it all depends on your situation and what your website really needs.
You should discuss this with your webmaster and sysadmin.
At SupportHost, we use Redis and Memcached, but for the plans based on Apache you still need a caching plugin. On our litespeed plans, instead, we offer side-server caching.
-
Choose a reliable web hosting service
Every website has different resource consumption depending on the plugins
used, the theme, and the cache system in place. The easier way to handle this is to host new websites on a shared hosting, and upgrade as your traffic volume and site’s complexity increase.
Reliable hosting services allow upgrades at all times.
If you have an existing website, and you expect an online traffic spike, for example because of an influencer campaign, it will be a bit harder. You need to somehow estimate the volume of such a spike and set up a server (or a cluster of servers) powerful enough to sustain a bit more than the expected traffic just to play on the safe side.
Autoscaling allows to allocate more resources automatically during spikes in traffic. The downside is that your next bill will probably see a huge spike too, so make sure you block all bot traffic coming to your website.*
* Remember how Amazon crashed during Prime Day in 2018? You get an idea of how tricky autoscaling a website can be.
-
Improve your website performance
Generally speaking, optimizing a website for performance means limiting the impact of complex database requests.
These are the best ways to improve your website’s performance:
- Less is more: remove all unused or outdated plugins from your website.
- Use a CDN (Content Delivery Network) to serve all the static content on your website (i.e. images) and free up space on your servers for dynamic content.
- Compress all media files. Website Planet’s image optimizer can compress images up to 80% of their original file size for free, but if you need to do this to a bulk of pics, there are tools like TinyPNG.
One more thing we do at SupportHost
We use plugins, like Asset Cleanup, to remove CSS and JS files from those pages where they are not used.
-
Monitor your traffic
Keeping track of your traffic is essential to prevent sudden spikes in a timely manner. There’s plenty of third-party solutions available for traffic monitoring, and some web hosting providers offer their own dedicated software.
-
Load testing
Load testing is a type of performance testing that helps you understand how much overload your site REALLY can handle, by sending controlled amounts of traffic. The difficult part here is being able to replicate how customers interact with your website, which is the only way to find the bottlenecks that may cause a website to crash during traffic peaks. That’s why there are specialized load testing services for that.
Take your time to try the different free and paid load testing tools on the market that can help you simulate a surge of traffic and provide the right metrics
Important: Let your web hosting provider know you are going to run a load test, because it will look like a DDoS attack to them!
-
Improve your website security
Malicious hackers know how to generate mass amounts of bot traffic and use it to overwhelm a server. It’s important to have ways to identify fake traffic sources and block that flow of traffic promptly.
WordPress websites have access to a plethora of security
plugins, like Wordfence and Sucuri to name two, whereas websites built on different technology can still avail of complete security solutions like those provided by
Heimdal to prevent a security breach.
Also, don’t skip software updates, especially when ti comes to your CMS. *
* some web hosts will run WordPress update automatically for you!
-
Go easy with your marketing campaigns
Marketing efforts can drive mass amounts of traffic to your websites, and that’s a good thing, but you must be ready to handle such spikes, or the user experience will be impacted, and your conversions will shrink. That would be a shame.
How to fix a website crash due to high traffic
A website crashes when it’s unable to transfer or receive the data needed to load the content. When that happens, it will show a blank page or a 503 HTTP status code (Service unavailable), which means that the server is down.
Crashes have to (ideally) be prevented, not solved, because when that happens, it’s already too late.
However, here is a plan of action to fix a website crash caused by a sudden increase in traffic.
Make sure your website is REALLY down
Sometimes you may be the only one seeing your site offline. Poor connection and caching issues are two common reasons for false alarms.
Check these signs to make sure that your web server is possibly overloaded:
- Is your server returning an HTTP error code? (500, 502, 503, 504, 408, etc. )
- Is your server delaying serving requests by one second or more?
- Is your server resetting or denying all TCP connections before returning any content?
- Is your server returning only part of the content that was requested? (this could be caused by either server overload or simply a bug)
Filter traffic
It’s possible that part of the traffic is not legitimate, and the traffic spike is caused by an influencer video, fake traffic, or a malicious attack. In this case, a Sysadmin should be able to tell the real traffic apart from the non-legitimate traffic and block it. (This should happen before it reaches the server).
As for all the legit traffic, stop all your marketing campaigns (especially ads, or you may end up wasting a lot of money).
Scale the website’s infrastructure
Depending on your hosting provider, you might be able to allocate more resources temporarily to your account. If you can do this, this is definitely a good option to solve the problem.
Implement a cache system
If you’re not using a cache for your website, you can implement during the traffic spike, it will definitely help. In this case, since the server is unavailable, you should close it to all traffic but your IP address, configure a cache (either server side or a plugin) and then open again the server to the world
Inform your customers
Even when your website is down, you can still save the user experience by letting everyone know what’s going on by sending a message on all your communication channels and adding a status page.
In the meantime that you fix the issue, you can also redirect your flow of traffic to a dedicated page with the latest updates (sometimes called a “virtual waiting room”).
Once the problem is fixed, send a last message to your community to explain what happened, say sorry again, and highlight the measures you have taken to prevent this from happening again.