Mia: Okay, so picture this: you log onto a website, and bam! One million tiny chessboards staring back at you. And get this—every single one is live, like, right now. That's the whole deal with One Million Chessboards: Global Instant Chess. Sounds absolutely insane, right?
Mars: It *is* insane! But in a seriously genius kind of way. Forget that annoying turn-by-turn lag you normally get. Every move you make just *whoosh* across the entire million boards in real-time. Click, done. No waiting, whatsoever.
Mia: Hold up. One *million* boards? And no turns? Seriously, how on earth does that not melt your browser or, you know, explode the server?
Mars: That's the million-dollar question, isn't it? Under the hood, it's all running on one single server. The crazy part is, all those board states are crammed into memory as one giant, 2D array. Think of it like, sixty-four million tiny slots, and each slot keeps track of where each piece is sitting. And the author uses 64-bit integers to pack the data super, super tight. It's pretty slick.
Mia: So, it's like stuffing, I don't know, sixty-four million grains of rice into one giant sack, and still having room for... a hamster? Is that kinda the idea?
Mars: Exactly! And get this – the code is written in Go. And it was the author’s first Go project. He set up one writer thread to handle all the moves and a bunch of reader threads for everyone who's watching. A mutex keeps everybody from stepping on each others toes and causing some kind of digital pile up.
Mia: Man, I can barely keep a cactus alive, and you're talking about threading and mutexes... I'm impressed!
Mars: Ha!
Mia: Okay, so, how do players even *see* what's going on across all those boards without drowning in data?
Mars: Ah, that's where the zones come into play! So, they group the clients into zones. You only get updates for the zone that you're in, plus the zones that are right next to it. It's sort of like chatting in a group text, right? You only see messages that people who matter... or messages from the zones that matter. Plus, they compress all that info with zstd and protobufs over WebSockets. It’s nice and lean, but fast.
Mia: That is slick. But what happens when someone tries to make a move that conflicts? I mean, since everything is instant. What if two people grab the same piece at the same time?
Mars: Right, so they use what's called an optimistic move application strategy. You play the move right away on *your* screen, but behind the scenes, the server is checking to make sure that it's valid. And if there *is* a conflict, it rolls back and tells you Oops, try again!. It's kind of like when you're sending a group text, and two people edit the *same* reply... your phone shows you the very latest version, right?
Mia: Ah, love that analogy! So, how many people are actually playing? I can't imagine it is millions, but maybe thousands?
Mars: Well, get this: After the first eight hours of going live, they logged about four hundred concurrent users, and a whopping one-point-three million moves! And the server? Barely broke a sweat.
Mia: That is wild! One server, and zero sweat? You know, like a marathon runner who never even breaks a sweat. Do you have any idea how they keep those costs in check for global data?
Mars: They do polling for global stuff, with Cloudflare caching. So only the fresh data hits the origin server, and that will save them a ton on bandwidth and cloud bills. Nice, huh?
Mia: Dude, I love how they have turned chess into this living, breathing organism that's spanning a million boards. You can just hop from one corner of the galaxy of boards to the other and nobody's waiting for you. Gotta love it!
Mars: And the really fun part? It was actually inspired by One Million Checkboxes. It was an art project where you tick boxes on a million grid canvas. Chess just upped the complexity and honestly, it stole the show.
Mia: Totally. Alright, I'm gonna go try it out: Global, instantaneous Chess on a million boards – what could *possibly* go wrong?
Mars: Only checkmate... everywhere! Enjoy!