Skip to content
Write to me

Qoria

Backend LeadJul 2025 to now

The backend behind an app for learning from working artists and teachers.

As backend lead, I ran it end to end, from the API and the database to AWS and the Cloudflare edge in front of them. The case study below is how it was load-tested for about 100,000 daily users.

15app servers running

Minute 10 of the climb

350,792 of 350,794 requests passed

Also here: a load balancer, a database proxy, and the outside services for payments, sign-in, chat, push, email and AI search.

QuietThe busiest moment of an app with about 100,000 daily users

01 of 04Case studyFilm 5:41

Load testing for about 100,000 daily users

daily users it was load-tested for
about 100,000
requests passed in a climb and its hold
350,792 out of 350,794
runs in two days, a change between each
9

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

02 of 04Query performance

Rewriting the busiest database queries

Same answers, less work

Three changes to the busiest queries. Before merging, 392 recorded responses from the old code matched the new code exactly.
database CPU per request
from 22 to 10 milliseconds
database CPU at full load
from 93% to 44%
free member's one-letter search time
from 3,310 to 54 milliseconds

At full load the database sat at 93% CPU. The easy fix was a bigger machine. I fixed the code instead, and the answers had to stay exactly the same.

How I did itHide how I did it

I ranked the database's busiest statements by their share of total time, not their average speed. After the change, Search and Discover read a page's keys first, then fetched only those rows. A search of one or two letters skipped the fuzzy-match index. Likes, saves, shares, comments and follows each ran four fewer statements. Before merging, 392 recorded responses from the old code matched the new code exactly.

Then I ran the same test on the same machine.

03 of 04Security

Edge security and an OWASP audit

Only the edge reaches the API

Requests through Cloudflare are answered. A direct request gets a 403, and scanner probes are turned away before the app.
for anything that skipped the edge
403
Critical and High audit findings
Critical from 1 to 0, High from 2 to 0
Medium audit findings, two weeks later
from 32 to 7

Qoria's API sat behind Cloudflare, but a direct request could still reach it. After the change, the API answered only traffic that came through the edge, and everything else got a 403. Rate limits saw the real caller. Scanner probes were turned away before they reached the app. Cloudflare's managed rules against known exploits were switched on, with strict TLS 1.2 or newer.

How I did itHide how I did it

Before that, I audited the backend against OWASP's list of web security risks. It found one Critical and two High issues, and fixes for account takeover and payment replay were among the first to land. Two weeks later there were no Critical or High issues left.

04 of 04How the work was run

Goals, reviews and a fast test suite

The test suite, run across 24 workers

Redrawn from the recorded run, with pytest's own progress lines, which name no tests. 8,253 tests on 24 workers in 91 s, against about 30 minutes before.
for 8,253 tests, down from about 30 min
91 s
decision records written
60

The team was small. For each piece of work, I set the goal and the rules, asked for the plan, reviewed what came back and made the go and no-go calls. Design decisions were written down as decision records.

How I did itHide how I did it

That only worked if checking was fast. The test suite took about 30 minutes, and the cost was in the setup, not the tests: mocks rebuilt for every test and real password hashing for every fake user. I made the setup cheap and spread the suite over 24 workers. Deploys to all three environments went through one workflow.

Also at Qoria

  • Moved the live database twice in a month, from MySQL to PostgreSQL with built-in vector search, then to Aurora Serverless with a write pause of 5 minutes 23 seconds.
  • Found that a forgotten GitHub webhook was 55% of production requests and 96% of server time, with nothing listening. I removed it and blocked it at the load balancer.
  • Cut each API worker's memory by 31% by freezing shared objects before the server forks its workers.
5 moreShow fewer
  • Cut a heavy member's first home feed page from 1,452 ms to under 260 ms of database time, with 42 kinds of viewer checked for identical results.
  • Fixed a goal-progress check that ran 4,025 queries and timed out. After the fix it ran 77.
  • Made the yearly payments ledger in the admin panel load in 0.84 seconds instead of 52.7, by paging and streaming it.
  • Put 22 views across nine flows behind Apple's device check.
  • Built the React admin panel from scratch, with required multi-factor sign-in, payouts, takedowns and an audit trail.

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