Notes

1 million requests per second: where the AWS bill stopped me

4 min read

In my last note I followed the first half hour of Cododev's video Let's Handle 1 Million Requests per Second, It's Scarier Than You Think! on my own laptop. Then the video moves to AWS, and that is where I stopped typing along and started only watching.

The reason is money. This note is about what the AWS part uses, what it costs, and what I am doing instead.

The move is to a very large machine

"Moving to AWS" here does not mean renting a small cloud server. According to Easin Arafat's write-up of the video, the first AWS server is a C8i.32xlarge: 128 CPU cores and 256 GB of RAM, at about $6 an hour.

My laptop has 4 cores and 16 GB. That one server has 32 times the cores, and next to what I own it might as well be a supercomputer.

The move also fixes the problem I ran into at the end of the last note. On my laptop the load tester and the server fought over the same four cores. On AWS the testers get machines of their own, so the server's numbers are the server's.

The final setup, priced

The setup grows from there. The video's tester repository lists exactly what the final test ran on, with prices in US dollars:

RoleMachinesCoresRAMPer hour
Server1 × c8gn.48xlarge192384 GB$11.00
Testers60 × c8gn.2xlarge480 (8 each)16 GB each$28.44
Total61 machines672$39.44

Left running for a month, the same repository puts the server at $8,300 and the testers at $20,000.

What that bought: in a 30-minute run the server handled 2,074,672,000 requests and moved 67.81 terabytes of data. That is about 1.15 million requests every second, sustained for half an hour.

Why I cannot follow along

At first the hourly price looks reachable. At $39.44 an hour, the 30-minute final run costs about $20. The trouble is everything around that half hour.

  • Nobody gets there in 30 minutes. The creator wrote in a LinkedIn post that he could only afford $2,000 of infrastructure for the video, for a setup that would cost more than $30,000 a month to keep running. He knows what he is doing. I would be learning as I go, which means more hours on the meter.
  • Mistakes are billed. Forget to shut down the 192-core server overnight and eight hours cost $88. Forget the 60 testers for the same eight hours and that is about $228 more.
  • AWS will not hand you this hardware by default. Accounts have a limit on how many cores they can run. The write-up says the creator hit a cap of 800 cores per region, which is why the final test used 60 testers and not more. A new account typically starts far below 192 cores, so I would have to ask AWS for a higher limit before I could launch the server at all.
  • There is nothing on the other side of the bill. This is a learning project. I cannot justify spending hundreds of dollars to reproduce a number that the video has already shown me.

What still transfers without the hardware

I do not need 192 cores to keep the ideas.

  • Test from a separate machine. A tester that shares the server's CPU measures both at once. That holds at any size.
  • The bottleneck moves. The write-up describes the 128-core server stalling at around 100,000 requests per second on a route returning about 30 KB, with half its CPU idle. The 50 Gbit/s network card was full. More cores would not have helped, and a smaller response did. My own version of this was an antivirus sitting in front of an idle server.
  • A monthly price is not what an experiment costs. Cloud machines are billed for the time they run. $8,300 a month and $11 an hour describe the same server, and the second number is the one that matters for a test.
  • The code is public. The Node.js repository only needs Node, PostgreSQL and Redis, so the database chapters can run on a laptop. It has four versions of the same read, from /code-v1, which sorts the whole table with ORDER BY RANDOM(), to /code-v4, which looks up one row by a random id. The gap between a full scan and an indexed lookup shows up with far fewer rows than the video uses.

How I plan to continue

  • Watch the rest of the video as a viewer and keep notes on the reasoning.
  • Run the PostgreSQL and Redis parts locally at a small scale, and compare the query versions myself.
  • If I do go to AWS, keep the same shape at a size I can afford: one small server and one small tester, a billing alarm set before anything is launched, and everything terminated the same day.

The video's title says handling a million requests per second is scarier than you think. For me the scary part turned out to be the invoice. At this scale the budget is as much of the problem as the engineering.