Best solutions for peak traffic: start with the slowest step
Your annual sale went live this morning. According to the server graphs, nothing much is wrong: CPU usage is normal and there is plenty of memory. Still, the checkout screen keeps spinning, and a customer who doesn't know whether the payment went through clicks pay a second time. The best solutions for peak traffic start with the question of where your application actually gets stuck under pressure.
Normal server load combined with long loading times tends to point to an external integration, a database query or a queue. In a sale like that it could be a payment provider that is temporarily slower to respond, or a stock integration that slows down with every order. For a webshop or customer portal, a moment like that costs revenue and trust straight away, and afterwards someone may have to work out whether any orders came in twice.
The order we would follow: first measure per action, then take the integrations and the heavy work out of the critical path, and only after that buy capacity. Automatic scaling sits at the back of that order, and then with a ceiling.
Peak traffic finds your weakest link
Capacity consists of more parts than the web server. A powerful server does little if the database can't keep up with the requests, and a fast database solves nothing if images are needlessly heavy or a single bug in the application keeps starting more processes.
Sometimes the weakest link is a single feature. A search function that runs through thousands of records for every query becomes the place where everything waits during a promotion.
So think in actions. Ten thousand people reading a product page ask something different of your platform than ten thousand visitors checking out at the same time. For your next busy moment, write down which systems your visitors touch with their actions, and what happens when one of them answers more slowly.
The best solutions for peak traffic start with measuring
Without measurements, scaling up is guesswork. Look at response times, CPU and memory usage, database load, error messages and the number of concurrent requests, and read them side by side.
The first measurement to set up is the one at transaction level. How long does it take to complete an order, and which steps are called during that action? With the spinning checkout, you then see whether the time goes to the payment provider or to the stock integration.
Put your historical data next to it. Compare a normal working day with earlier campaigns and the busiest hours of the week, and an expected peak becomes a scenario you can plan for. For a new promotion you need a realistic estimate of conversion and concurrency. To translate the reach of a newsletter landing in thousands of inboxes into server load, you need to know how many of those people check out at the same time.
Reserve capacity for peaks you see coming
Capacity is best expanded before a planned campaign and scaled back in a controlled way afterwards, because a server permanently sized for the busiest five minutes of the year is often needlessly expensive. For ticket sales that open at a fixed time or a webshop with an annual sale, reserving extra capacity in advance can be the best choice.
That only works if the application is suited to it. If sessions, uploads or temporary files are stored locally on one server, a second server needs some preparation first. Cron jobs and integrations also need to be clearly divided. Scaling is as much a matter of application architecture as of infrastructure.
Automatic scaling suits traffic that grows unevenly. Expect extra maintenance and cost monitoring in that case, and set limits before you switch automatic scaling on. Without limits, it can replace a technical outage with an unexpectedly high bill.
First cache what stays the same for everyone
Caching is often one of the fastest ways to reduce peak load. Images, scripts and frequently requested data don't need to be rebuilt or fetched on every visit. Serve static files close to the visitor and keep frequently used data temporarily available, and capacity stays free for the actions that need real processing.
The risk lies in everything that differs per visitor or changes quickly, such as a personal dashboard, current stock or a shopping basket. Badly configured caching shows outdated prices or the wrong content there, and can cause privacy problems. Our rule of thumb is to open with what stays the same for every visitor, such as a general landing page, and cache the rest as soon as you know exactly how long that data stays correct.
Look at the database in the same round. Slow or needlessly broad queries quickly become a bottleneck with many concurrent visitors. Good indexes and limited data selections help, as does a clear separation between read-heavy and write-heavy processes. A check you can do this week: see when your heaviest report runs. If it falls in the middle of your busiest ordering hours, move it.
Put the PDF invoice in the queue
Sending emails and generating invoices often don't need to happen within the web request. Put them in a queue, and the visitor gets a quick confirmation while a separate process handles the heavier work in a controlled way. In a webshop the successful payment can then get priority, and the detailed PDF invoice follows afterwards.
That stops a busy moment escalating as every request waits on several external systems. A queue also gives you control: you rerun failed tasks and see where backlogs build up.
The trade-off lies in what your customer expects. If someone needs to use a service right after paying, that processing can't sit in the queue for minutes, and you need enough workers and clear priorities. Technology should follow the business promise, not the other way round.
Give every external integration a timeout
Payment providers, ERP systems and shipping services also have to handle more calls from your platform during a peak. If one of them slows down, it can hold up your whole process.
So work with timeouts, controlled retries and clear error handling, so your system stops waiting for a party that is temporarily not responding. Show previously stored data for a while where the information isn't critical, and decide in advance for orders and payments what the user sees and how the action can be safely repeated.
That last part is called idempotency: the same request must not unexpectedly run a transaction again when it is repeated. It is the technical side of the customer who clicks pay twice. We would only switch on retries for a payment or order call once it is certain that a repeat can't create a second order.
Find the tipping point with a load test
A load test simulates realistic behaviour before a campaign goes live, with a mix of page views, searches, logins and transactions. Most of its value lies in the tipping point: the volume at which response times start to climb, and the component that causes it.
The test environment has to resemble production closely enough to give usable results. Also test what happens when an API answers slowly or a worker fails. Pick the scenarios that hit your business hardest first, such as a slow payment provider.
After each test, plan time to make improvements and measure again, because a report without follow-up doesn't prevent an outage. At LJPc we look at the whole chain: application, hosting, database, integrations and maintenance.
Agree who steps in during the peak
Monitoring should answer the questions you ask during a busy promotion:
- Is the site reachable?
- How fast is the checkout?
- Is the number of errors rising?
- Is the queue growing?
- Is there still enough capacity?
Tie alerts to what customers notice, such as the loading time of the checkout. An alert about high CPU usage would never have gone off during the sale described at the start.
Set thresholds that warn early and agree who acts. With a short runbook covering escalation and fallback options, everyone knows during a big promotion where the login details are and who to call.
Check the basics too: backups, recovery procedures and protection against unwanted traffic. A peak can consist of buyers, or of bots, crawlers or an attack, and that protection should catch that unwanted traffic early while real customers get through.
A first step for your next busy moment: pick the action that costs you most when it stalls, which for a webshop is checkout, and measure how long each step in it takes. If you want to go through that measurement with us, we'll look at the whole chain with you from Assen.