Skip to content
Write to me

Qoria: Load testing for about 100,000 daily users

Case study

Load testing for about 100,000 daily users

Over two days, nine test runs sent up to ten thousand simulated phones at once, the busiest moment of an app with about 100,000 daily users, at a throwaway copy of the backend, with a fix between runs.

How I did itHide how I did it

Our advisor drafted the first test plan. I had it replanned around simulated phones that behaved like the app, then built and ran it. It ran on a throwaway copy of production with 100,000 seeded accounts and stand-ins for every outside service. Each phone had its own account and device key, signed its requests like the app, and walked the app's real screens.

Run 1 collapsed. The database hit 100% CPU and ran out of memory twice, and about one request in ten got through. Between runs I capped database connections and fixed slow queries. Run by run, phones served in under a second went from about 26% to all.

Transcript

Hi, I'm Maiz. As the backend lead at Qoria, I spent a week trying to break our backend on purpose, and I want to tell you how that went.

On screen: The peak of about 100,000 daily users. An estimate. Simulated phones, all at once. A load test.

The goal sounded simple. We wanted ten thousand people to be able to use the app at the same moment. To give you a feel for that number, by a rough estimate it's the busiest moment of an app with about a hundred thousand daily users.

So we built that many simulated phones and pointed them at a copy of our backend. It held about three thousand five hundred of them, and then it fell over. Only about one request in ten got through in that run.

Before I tell you how we fixed it, let me show you what we were testing. A phone reached the app servers through the edge. Behind those servers sat a cache, a single database, and several outside services for things like payments and chat. I didn't want to aim thousands of fake phones at the real thing, so we built a throwaway twin of production: the same code, a hundred thousand made-up accounts, and a stand-in for every outside service.

One of our changes came before the first run even started. The cache was on Upstash, a hosted Redis that lives outside our own network, so every read had to leave the network and come back. Almost every request touched the cache several times, so that was time we paid again and again. The main reason I moved it was speed: the cache went to Valkey on AWS, inside our own network and right beside the app servers, so a read no longer had to cross the internet. It was also the cheaper choice. We were paying Upstash for every command, and by our estimate that would have run to thousands of dollars a month at full load. Even its fixed plans would have cost a few hundred dollars a month at this scale, and more beyond it. The new cache would cost less than either at the same load. The new cache ran as a cluster, which meant changing how the code talked to it.

That first run showed us exactly where the trouble was. The database was at a hundred percent, while the app servers were barely working, at about seventeen percent. The servers kept opening new connections to the database until there were more than three thousand of them, and the database ran out of memory twice. Then it made itself worse. Our simulated phones signed straight back in every time they failed, which the real app doesn't do, and signing in is expensive.

So before the next run we fixed our own test as well as the backend, and from then on the phones also left out the app's known extra requests, which went to the app team as a list. On the backend, the easy answer would have been an even bigger database, and I didn't take it. The first change was a limit on how many connections the servers could open, with a proxy in front of the database. On the very next run, the connections peaked at eight hundred and fifty-three and nothing crashed, but the database still ran out of CPU at about seven thousand phones.

After that we went after the busiest queries. Three changes to the code later, on exactly the same machine, the database went from ninety-three percent busy to forty-four.

By then the numbers looked good, and that's when I noticed something uncomfortable. Every test so far had started with the servers already running. In production we started small and added servers as people arrived, and we had never tested that. So run seven started from two servers, the way production did at the time. Our scaling rules added a server or two every minute, and while they caught up, one request in twenty waited twenty-seven seconds or more. The rules weren't wrong. They were just late.

So I came up with a different kind of scaler, one that would watch how fast the load was growing and not only how high it was. The formula we built from it is simple. Every fifteen seconds it looked at how many requests had arrived in the last minute, and how quickly that number was climbing. It carried that climb forward to the moment a new server would be ready, and worked out how many servers that much traffic would need. Then it ordered them straight away, so they were ready by the time that traffic arrived. It also watched how busy the servers were, and went with whichever signal asked for more. On the same day we also moved the database to one that grows by itself while it's running, so nobody has to take it offline to make it bigger.

Then came run eight. This time the climb to full load started on only three servers, and the scaler stayed ahead of the phones the whole way. Out of about three hundred and fifty thousand requests, more than ninety-nine point nine nine nine percent went through.

It still wasn't perfect. When we threw a sudden rush at it, the new scaler overreacted and asked for a hundred and forty-six servers when about fifteen would have done. So we gave it some limits and ran the same two-minute rush again. Across that whole test, ninety-eight and a half percent of more than three hundred and sixty thousand requests went through. The system had no warning of that spike, and no servers had been added ahead of time for it, so I think that's a strong result. In the last run, a gentler five-minute rush, ninety-nine point nine nine five percent of more than four hundred thousand requests went through, and afterwards it calmly scaled itself back down.

I want to be honest about what this proves. It was a test, not real traffic, and real people are messier than a script. A sudden rush still hurt for the first few minutes, while new servers started. But the backend that fell over at three and a half thousand phones went on to hold the full load, and both the new scaler and the new database went into production soon after.

All nine runs

  1. Run 1~3,500phones held, then it fell over
  2. Run 2853database connections, capped
  3. Run 3~86%of phones answered in under 1 s
  4. Run 40.34 sslowest 5% of answers at full load
  5. Run 544%database CPU, down from 93%
  6. Run 6100%requests passed on a new database
  7. Run 727 sslowest 5%, starting from 2 servers
  8. Run 8350,792of 350,794 passed, climb and hold
  9. Run 999.995%passed in a five-minute rush

01

The test setup

The test ran on a throwaway copy of production with the same code, 100,000 made-up accounts and a stand-in for every outside service, so no real provider saw test traffic. Each simulated phone had its own account and device key, signed its requests like the app, and walked the app's real screens.

The test copy, from phone to database

Phones reached a test-only load balancer, then the app servers. Behind them sat the cache, the database and a stand-in for each outside service.

02

The cache, moved inside the network

Before the first run, the cache moved from Upstash, a hosted Redis outside our network, to Valkey on AWS, inside the network and beside the app servers. The new cache ran as a cluster, which meant changing how the code talked to it.

Where the cache sat, before and after

Before, every cache read left the network and came back. After, the cache sat beside the app servers.

03

Run 1: where it broke

The first run held about 3,500 phones, then fell over. The database sat at 100% CPU while the app servers sat at about 17%. The servers kept opening database connections until there were 3,130, and the database ran out of memory twice.

Run 1 at its peak

The database was the limit. The app servers had room to spare.

04

Capping database connections

Before run 2, the servers got a limit on how many database connections they could open, with a proxy in front of the database. Connections peaked at 853 and nothing crashed.

Database connections at the peak

Run 1 had no cap: 3,130 connections. Run 2, capped behind a proxy: 853, and no crashes.

05

Phones answered in under a second

Between runs, code fixes went after the slowest queries. By run 4, every phone was answered in under a second, but the database was at 93% CPU.

Share of phones answered in under a second, runs 1 to 4

Run 1: about 26%. Run 2: about 71%. Run 3: about 86%. Run 4: all of them.

06

Database CPU on the same machine

Three changes to the busiest queries took the database's CPU at full load from 93% to 44%, on the same machine. The CPU time for each request fell from 22 to 10 milliseconds. The query performance section on the Qoria page has the details.

Run 4 against run 5, same database

CPU at full load: 93% then 44%. CPU time per request: 22 ms then 10 ms.

07

Starting from two servers

Every run so far had started with the servers already running. Run 7 started from 2, the way production did, with production's scaling rules. While they caught up, the slowest 5% of requests waited 27 seconds at worst, and stayed over a second for 12 minutes.

Run 7, the step rules

Production's step rules, starting from 2 servers.

08

A scaler that looks ahead

The idea was mine: scale on how fast load grows, not only how high it is. Every 15 seconds the scaler projected the last minute's traffic forward to when a new server would be ready, and sized for that. It scaled up at once and down slowly. On the same day the database moved to Aurora Serverless, which grows while it runs.

The scaler's loop

It ordered the servers the coming traffic would need, so they were ready when it arrived.

09

Run 8: the climb to full load

Run 8 let the phones in over ten minutes, from none to all of them, starting on 3 servers, then held them. The servers went to 9 by minute 4 and 15 by minute 9, and 350,792 of 350,794 requests passed.

App servers running in run 8, minute by minute

After minute 10, an old request-count step rule was still on and added servers on top of the scaler's own count of 14. The rule has since been removed.

10

Sudden rushes

In a two-minute rush, 92.1% of requests passed with the old step rules. With the scaler, once it had limits on how much it could ask for at once, 98.5% passed. In a longer, five-minute rush, 99.995% passed, and the scaler stepped down from 24 servers to 15 by itself.

Requests passed in sudden rushes

Two-minute rush: 92.1% with the old rules, 98.5% with the scaler. Five-minute rush: 99.995%.

Downloads

Read on

Next project

EZ-Spectrum

Software Engineer, Jul 2025 to now

Radio-network engineering software whose study engine runs 33× faster on the same 7,630 studies than the tool it replaced.

33×faster on the same 7,630 studies