[{"data":1,"prerenderedAt":296,"buildId":297},["ShallowReactive",2],{"note:\u002Fnotes\u002Fcodm-backend-detour":3,"notes":277},{"id":4,"title":5,"body":6,"date":262,"description":263,"draft":264,"extension":265,"meta":266,"navigation":267,"path":268,"readingTime":269,"seo":270,"stem":271,"tags":272,"__hash__":276},"notes\u002Fnotes\u002Fcodm-backend-detour.md","A detour: how I would approach a game like Call of Duty: Mobile",{"type":7,"value":8,"toc":251},"minimark",[9,24,27,32,35,101,104,107,111,114,117,130,133,137,140,143,146,157,160,163,167,170,181,184,188,191,194,202,205,208,212,215,218,226,230,233,245,248],[10,11,12,13,18,19,23],"p",{},"When I am not writing code I am usually in a battle royale lobby. So after two notes on ",[14,15,17],"a",{"href":16},"\u002Fnotes\u002Fone-million-rps-nodejs","handling a million requests per second in Node.js"," and ",[14,20,22],{"href":21},"\u002Fnotes\u002Fone-million-rps-aws-cost","what that costs on AWS",", I wanted to point the same ideas at something I play: Call of Duty: Mobile.",[10,25,26],{},"I have no inside knowledge of how CODM is built. This is a thought experiment about how I would approach the backend of a game like it, using only what I have learned so far. The numbers below are my own assumptions, chosen to make the arithmetic easy.",[28,29,31],"h2",{"id":30},"a-game-has-two-kinds-of-traffic","A game has two kinds of traffic",[10,33,34],{},"The first thing I would do is stop thinking of \"the server\" as one thing.",[36,37,38,53],"table",{},[39,40,41],"thead",{},[42,43,44,47,50],"tr",{},[45,46],"th",{},[45,48,49],{},"The lobby",[45,51,52],{},"The match",[54,55,56,68,79,90],"tbody",{},[42,57,58,62,65],{},[59,60,61],"td",{},"What happens",[59,63,64],{},"Login, loadouts, store, friends, ranks, matchmaking",[59,66,67],{},"Moving, shooting, the circle closing",[42,69,70,73,76],{},[59,71,72],{},"Shape of traffic",[59,74,75],{},"A request, then a response",[59,77,78],{},"A constant stream both ways",[42,80,81,84,87],{},[59,82,83],{},"What matters most",[59,85,86],{},"Requests per second",[59,88,89],{},"Latency, and never missing an update",[42,91,92,95,98],{},[59,93,94],{},"How long state lives",[59,96,97],{},"Forever",[59,99,100],{},"About as long as the match",[10,102,103],{},"The lobby is the world the video lives in. It is an HTTP API, and everything I learned about Fastify, Cpeak, autocannon and clustering applies to it directly.",[10,105,106],{},"The match is a different animal. Nobody waits for a response there. Every player sends their inputs many times a second, and the server sends back what the world looks like just as often.",[28,108,110],{"id":109},"a-million-a-second-arrives-early","A million a second arrives early",[10,112,113],{},"In the video, a million requests per second is the finish line. In a shooter it shows up much sooner than I expected.",[10,115,116],{},"Take a 100-player battle royale match and assume each player sends 20 updates a second:",[118,119,120,124,127],"ul",{},[121,122,123],"li",{},"One match is 100 × 20 = 2,000 messages a second coming in.",[121,125,126],{},"500 matches is 1,000,000 messages a second.",[121,128,129],{},"500 matches is only 50,000 players.",[10,131,132],{},"So a game does not need millions of players online to face the number from the video's title. Fifty thousand people in matches is enough, and that is before the lobby traffic is counted.",[28,134,136],{"id":135},"one-match-one-thread","One match, one thread",[10,138,139],{},"The lesson that one thread can use only one core changes shape here.",[10,141,142],{},"For the HTTP API, I would do what the video does: run one process per core and let any worker answer any request. The workers share nothing, and that is fine because every request stands alone.",[10,144,145],{},"A match is the opposite. All 100 players have to reach the same process, because that process holds the one true copy of the match. Spreading them across workers would break the game. So the unit I would scale is the match:",[118,147,148,151,154],{},[121,149,150],{},"Each match runs as its own loop on one thread, which is the model Node already gave me.",[121,152,153],{},"A machine hosts as many matches as its cores can keep up with.",[121,155,156],{},"A matchmaker decides which machine a new match goes to and tells the players where to connect.",[10,158,159],{},"At 20 updates a second, each turn of that loop has 50 milliseconds to read every input, move the world forward and send the results. If a turn runs longer, every player in the match feels it. That makes time per turn the number to watch, the way requests per second was for the API.",[10,161,162],{},"The video reaches for C++ when Node runs out of room. If my match loop could not keep to its 50 milliseconds, this is the part I would rewrite first, and I would leave the lobby in Node.",[28,164,166],{"id":165},"what-lives-outside-the-match","What lives outside the match",[10,168,169],{},"Clustering taught me that anything two processes both need has to live outside both of them. In a game that list is easy to write:",[118,171,172,175,178],{},[121,173,174],{},"Who you are, your rank and what you own belong in a database on disk.",[121,176,177],{},"Who is online, who is in your party and the live leaderboard change constantly and are read constantly, so they belong in memory, in something like Redis.",[121,179,180],{},"The match itself stays in the match process and nowhere else while it is running.",[10,182,183],{},"I would write the result of a match once, when it ends, and not kill by kill. The video's code does something similar for fast writes: it accepts the data in Redis straight away and moves it to PostgreSQL afterwards from a queue. A match can lose a few seconds of progress if a server dies. It cannot afford to wait on a disk for every bullet.",[28,185,187],{"id":186},"the-bottleneck-would-be-the-network","The bottleneck would be the network",[10,189,190],{},"The AWS part showed a server with half its CPU idle because its network card was full, and the fix was a smaller response. A shooter lives with that limit all the time.",[10,192,193],{},"Assume the server sends each player a 1 KB picture of the world, 20 times a second:",[118,195,196,199],{},[121,197,198],{},"One match sends 100 × 20 × 1 KB, which is about 2 MB a second, or 16 Mbit\u002Fs.",[121,200,201],{},"A 50 Gbit\u002Fs network card, the size that capped the video's first AWS server, fills up at about 3,100 matches.",[10,203,204],{},"Halve the size of each update and the same card carries twice the matches. So I would spend effort on sending less: only what a player can see or hear, and only what has changed.",[10,206,207],{},"Distance matters here in a way it did not for the API. A player in Lagos connected to a server in Europe pays for that distance on every single update, and no amount of cores fixes it. Servers have to be near players, which means many smaller groups of machines around the world and not one giant one.",[28,209,211],{"id":210},"testing-it-means-bots","Testing it means bots",[10,213,214],{},"autocannon works for the lobby exactly as it did in my first note. It cannot play a match.",[10,216,217],{},"For the match server I would write bots: small programs that connect, send inputs at the same rate a real player would, and record how late the server's updates arrive. Two rules carry over unchanged:",[118,219,220,223],{},[121,221,222],{},"Bots run on their own machines, so they do not steal CPU from the server they are testing.",[121,224,225],{},"I would read the slowest 1% of updates alongside the average, because that 1% is the moment a player says the game is lagging.",[28,227,229],{"id":228},"what-i-would-build-first","What I would build first",[10,231,232],{},"The AWS note ended with me not being able to afford the hardware, so I would start at a size that costs almost nothing:",[234,235,236,239,242],"ol",{},[121,237,238],{},"One match server for 10 players, the size of a 5v5 game.",[121,240,241],{},"Ten bots on a second machine.",[121,243,244],{},"A measurement of how long each turn of the loop takes as I add matches to the same core.",[10,246,247],{},"That last number answers the question everything else depends on: how many matches fit on one core. Multiply by cores and by machines and I have a first estimate of what any player count would cost, before spending money to find out.",[10,249,250],{},"The video taught me to ask where the limit is before adding hardware. For a game like CODM I think I would hit the limits in this order: the match loop's time budget, then the network, then the bill.",{"title":252,"searchDepth":253,"depth":253,"links":254},"",2,[255,256,257,258,259,260,261],{"id":30,"depth":253,"text":31},{"id":109,"depth":253,"text":110},{"id":135,"depth":253,"text":136},{"id":165,"depth":253,"text":166},{"id":186,"depth":253,"text":187},{"id":210,"depth":253,"text":211},{"id":228,"depth":253,"text":229},"2026-11-27","A thought experiment that takes what I learned from the 1 million requests per second video and applies it to a battle royale shooter.",false,"md",{},true,"\u002Fnotes\u002Fcodm-backend-detour",6,{"title":5,"description":263},"notes\u002Fcodm-backend-detour",[273,274,275],"gaming","performance","system-design","aB-jU2CTJvXaG1hQjulcy7zkrZDvVF2jNczTInqO84Q",[278,280,289],{"path":268,"title":5,"description":263,"date":262,"tags":279,"readingTime":269,"draft":264},[273,274,275],{"path":21,"title":281,"description":282,"date":283,"tags":284,"readingTime":288,"draft":264},"1 million requests per second: where the AWS bill stopped me","The video moves from a laptop to AWS machines with hundreds of cores. Here is what that costs, why I cannot follow along, and what I can still learn from it.","2026-11-26",[285,274,286,287],"aws","cost","video-notes",4,{"path":16,"title":290,"description":291,"date":292,"tags":293,"readingTime":295,"draft":264},"Chasing 1 million requests per second: the Node.js groundwork","Notes from the first half hour of Cododev's 1M requests per second video, covering Cpeak, Fastify, autocannon and using every CPU core.","2026-11-25",[294,274,287],"nodejs",7,1795639237702,"8ada6b5d-d82e-40a2-b259-f20981c3cd97"]