I've been building nanoMMO, an MMO written from scratch in C++, on a YouTube series where every step of building it is on video, and ninety episodes in, it has become a game you can play in your browser, with a lot more engineering around it than I expected when I started.
Where it comes from
I've always been passionate about game development and complex systems, starting out with Borland Pascal as a teenager, then moving on to C++ and competitive programming, and building websites, games and mobile apps in PHP and C# on the side. One of those games is Secret Republic, a hacker role-playing game in the browser where you break into simulated servers, crack passwords and run SQL against live databases, which I first launched in 2012 and which is open source, with four versions of it by now.
In 2017, I tried an MMO in Swift, as a research experiment into how MMO servers and clients work, with a login server and a world server talking in packets I laid out byte by byte, and nanoMMO splits its servers in the same way. In 2021, I wrote Omen, a backend in Scala for old-school browser games in the style of Travian and Tribal Wars, where you describe a game in YAML, and in 2023, I started Hades, a 3D game engine in C++ with an editor and a Vulkan renderer, which can train reinforcement learning agents too. nanoMMO picks up from all of these, down to its monsters and items being written as data, the way Omen describes a game in YAML, and the difference this time is that each step of building it is out in the open.
The name is a working title, and it takes after nanochat, Andrej Karpathy's repository whose code is kept minimal and easy to hack on, which is what I'm going for as well, a codebase that covers an MMO from one end to the other and that you can read, run yourself and play with.
The engineering beyond the gameplay
What drives nanoMMO more than anything is my interest in complex software engineering at scale, and in the practices that keep large systems running, which comes from my years in industry at Morgan Stanley and Google, building large distributed systems, where I came across most of what the series covers, though never at a game company. An MMO is one of the best excuses I know to bring all of those practices together in a codebase small enough to read, so while your average game devlog tends to focus on flashy graphics or a new gameplay mechanic, and nanoMMO has its share of both, the series spends most of its time on the software engineering and DevOps side of a game like this, from the choice of databases and Docker to tests, monitoring and deploys. The idea is to show what comes into play in a production-like setup, especially for people at the start of their careers, so that when a problem occurs, they understand what actually happens behind the scenes and can debug it, whether or not an AI writes a lot of the code for them. It's the same point I made about junior engineers, that the depth of knowledge is what lets you use these tools well rather than hand all the thinking over to them.
There's a lot more than a game server by now, with a client that draws the world with raylib and sends what the player does, while the servers decide what happens. The client logs in through a login server of our own, over TLS, against accounts kept in MySQL, and a browser comes in through a WebSocket gateway that we wrote from the RFC. Each world registers with Consul and keeps its players in Redis, while a saver writes them behind to MySQL, what the players do goes into ClickHouse for analytics, and Prometheus, Grafana, Loki and Pyroscope keep an eye on all of it, while most of the players you see in the videos are bots that play the game over the network as a real client would, as many as two thousand of them at once.
The game as it is today
Each land in nanoMMO is an island of its own, and you travel between them through gates, from the Meadows, which sit in the sea, to the Ashlands, in a sea of lava, and the Crypt, a dungeon where each player who goes in gets a copy of their own. The server works out each land's time of day and weather from the wall clock, so every server agrees on it and there's nothing to save, while the client draws the sunsets, the rain and the stars at night.
The skeletons of the Ashlands and the Crypt show their attacks as shapes on the ground before they land, filling them in as the blow gets closer so you have a moment to step out of the way, and the Bone Colossus, our first world boss, is a skeleton four and a half metres tall that fights in three phases and goes for whoever has hurt it the most, from a threat table that every monster keeps now. Two players can agree to a duel that ends once one of them is down to one health, they can trade items and gold in a window where both of them have to say they're ready, and they can start guilds, with a roster, ranks and officers, kept in MySQL a transaction at a time.
What went wrong first
A lot of what we built came from something going wrong first, and those are some of my favourite episodes, as they're the parts most tutorials skip and the ones that decide whether a game server holds up once players arrive. In episode thirteen, saving to MySQL after each change fell behind with only a few dozen players, which is why Redis went in between, with a saver that writes to MySQL in batches, and deploys used to throw everyone out of the game, until a world learned to hand its players over to its next version before it stops. With two thousand bots, a world fell from twenty ticks a second to about eight, and a flame graph showed where the time went, all the way from the broadcast down to the kernel's UDP stack.
The network had its own lessons, as on a connection slowed down to a 150 millisecond round trip, our player started and stopped walking late, so the client now walks you the moment a key goes down and lets the server correct it, and when packets got lost, everyone else lurched, so the client now draws other players a tenth of a second in the past, between two updates it already has. In a duel, a blow that looked as if it landed could still miss, so the server now checks it against where the attacker's screen showed the opponent, up to 200 milliseconds back.
The client runs on the player's machine, so anything it sends can be made up, which is why the game's logic stays on the server, and when a red-team client of ours tried to cheat, the server already stopped most of its tricks. Trading was another story, as the red-team client found two ways to turn two swords into three, and another by playing one character on two servers at once during a deploy, each of which got fixed on the server, with both sides of a trade saved in a single Redis transaction, a lease for each character and an alert in Prometheus for whenever an item is held twice. If you'd like to pick a few episodes to watch, I'd go for those, as dupes like these come up in most other games too, and then for the chaos testing episodes, where we froze Redis, MySQL and the login server while the bots played, found a sword that existed twice and players dropped while our numbers said all was well, made the game resilient to it, and wrote our first postmortem.
Why the game is built the way it is, and what we weighed and turned down along the way, is written up in its decision records, and what broke and was hard to get right is gathered on the hard parts page of the series' website, each with the episode it's in.
Playing it in a browser
More recently, the client learned to build to WebAssembly, so the game now plays in a web browser, either offline, with the world's rules running in the page, or online, through that WebSocket gateway, although on the way, raylib sent WebGL its bone matrices untransposed, which stood a tall spindle next to every person in the world until a patch fixed it. You can try it on the Play page of the series' website, without installing anything and without a server.
Where it's going
I should say up front that what I'm about to describe might not scale in the end, for one reason or another, but what interests me most is dynamic intelligence, and a world that evolves, so I'd like to end up with something like Sword Art Online, in the sense of a world that can adapt of its own volition. Along the way, I want to build features I'd like to see exist, even if some of them might be impractical for most games, such as a system for players to create skills of their own, and further down the line, an AI agent could generate quests on the fly, made for a specific player, and items too.
We've already taken a small step in that direction, in episode twenty-five, with a storyteller NPC that writes you a story from a few words using mvGPT, the small GPT from my other series, served next to the game. In episode ninety, the game's content went into smollerGraph, the graph database from another of my series, as a graph of quests, monsters, items and skills, with a test in CI that fails whenever a new player can no longer reach one of them.
Following along
The website of the series has a page for each episode, with the code at each of its steps, and the game's code is on GitHub under the MIT licence, with every step of every episode tagged in the repository, so you can check out the code at any point in a video, build it and run it yourself. If you're new to it, your best bet is episode one, which sets out the plan, followed by the rest of the episodes in order, which go up on my YouTube channel.
Two books go well with the series, Design Patterns, by Gamma, Helm, Johnson and Vlissides, which gave names to patterns like Observer, Command and State, and Robert Nystrom's Game Programming Patterns, which goes back over them as they turn up in games, adds the ones games need, like the game loop, and is free to read online.