MMO Architecture: Area-Based Sharding, Shared State, and the Art of Herding Digital Cats

More on MMO Architecture:
- MMO Architecture: Source of truth, Dataflows, I/O bottlenecks and how to solve them
- MMO Architecture: client connections, sockets, threads and connection-oriented servers
- MMO Architecture: Optimizing Server Performance with Lockless Queues

Building an MMO feels a lot like herding cats, noisy, frantic, unpredictable and forever on the brink of half of them running into the road. The question is how to keep everything from descending into chaos when tens of thousands of players decide to storm your virtual castle at the same time.

In Massively Multiplayer Online (MMO) games, ensuring a seamless and immersive experience for thousands of players simultaneously is a monumental chore. At the heart of this challenge lies the architecture that governs how game servers manage player interactions, world events, and resource distribution. A pivotal component of this architecture—and the main focus of this post—is area-based sharding, a strategy that divides the game world into manageable sections (often called “zones”), each overseen by dedicated servers.

So, your players are laying siege to a castle, and your servers are silently screaming for mercy. How do you handle this digital nightmare without devolving into a lag-ridden slideshow for everyone in your online world?

Continue reading “MMO Architecture: Area-Based Sharding, Shared State, and the Art of Herding Digital Cats”

MMO Architecture: Optimizing Server Performance with Lockless Queues

More on MMO Architecture:
- MMO Architecture: Source of truth, Dataflows, I/O bottlenecks and how to solve them
- MMO Architecture: client connections, sockets, threads and connection-oriented servers
- MMO Architecture: Area-Based Sharding, Shared State, and the Art of Herding Digital Cats

I'm writing this article within the last 2 hours of 2024, so I guess I'm forced to say Merry Christmas ❤ Thank you for your time, I hope you enjoy it and learn something new.


In modern MMO (Massively Multiplayer Online) games, server performance is as crucial as any other part of the game’s architecture. You want your servers to handle thousands of player connections seamlessly, process real-time game logic, and keep latency as low as possible.

A common technique in building such systems (and any other high performance socket-based software tbh, you already know my obsession with MMOs…) is to separate the networking thread from the main game logic thread(s) so the application doesn’t stall on big net transfers. This separation goes a long way to improving performance, maintainability, and scalability, especially in high-concurrency environments.

In this article, we will explore the reasons behind this design decision, discuss race conditions and how they can occur in multi-threaded code, and see why lockless queues are often a great choice for handling messages between threads in.

Finally, we will present a working C++ implementation of a lockless SPMCQueue (Single Producer, Multiple Consumer Queue) and discuss the key concepts behind it. This queue allows a single producing thread to push data into the queue while multiple consumer threads can pop data concurrently.

Continue reading “MMO Architecture: Optimizing Server Performance with Lockless Queues”

Deep-diving into Entity Component System (ECS) Architecture and Data Oriented Programming

1–2 minutes

Some years ago I wrote the first article about ECS, at that time, in a comment, someone suggested that my solution was closer to a standard CS than to a real ECS.
Unfortunately for me, that anonymous internet person was right.

Entity component system (ECS) is an architectural design pattern used primarily in video game development. This pattern differs significantly from object-oriented programming (OOP), which has been the dominant paradigm in software programming for decades.

ECS offers significant advantages in video game development, especially in terms of flexibility, performance and ease of maintenance. This architecture is well suited to the dynamic and often complex needs of modern games, greatly facilitating phases as essential as complex as the prototyping of new features.

Continue reading “Deep-diving into Entity Component System (ECS) Architecture and Data Oriented Programming”

Beyond Brute Force: Spatial Hashing for Optimized Collision Management in Video games

1–2 minutes

This article may not be as deep, complex or elaborate as others I have published lately. It has come up while I was drafting another post about swarm intelligence which, with any luck will be coming soon.
Something like local entity interactions processing in high-density environments is certainly interesting enough to require an article on its own.

The landscape of simulation and game development offers a vast terrain where interactions between entities manifest themselves as a constant, and the need to evaluate and manage these interactions in real time becomes crucial.
The quadratic complexity involved in checking entity-by-entity issues such as collisions makes managing large numbers of entities in a single scene a complicated challenge to solve.

Continue reading “Beyond Brute Force: Spatial Hashing for Optimized Collision Management in Video games”

Distributed Systems Architecture: Authentication, authorization and ping-pong nonsense.

1–2 minutes

In the last post we explored the problems of accepting connections in high concurrency applications.
One of the significant points in opting for asynchronous queue-digester-based solutions is, in my opinion, the management of the client-server relationship from the point of view of authentication, authorization, limitations, etc.

This reflection did not take long to bring to my mind the hell of authorization flows in distributed systems and how complex (and absurd) they turn out to be.

In this article we will try to summarize authorization flows, the complications we have in distributed architectures and what, from my point of view, is an alternative solution to address them once and for all.

Continue reading “Distributed Systems Architecture: Authentication, authorization and ping-pong nonsense.”

Videogames behind the scenes: Maths in movement

In the videogame’s world, everything is math, maths are everywhere, shooting is feed with maths, reward systems are feed maths and movement -our main topic here- is feed math.

Welcome son to the world of mathematics.
Continue reading “Videogames behind the scenes: Maths in movement”

Javascript by reference: understanding javascript

When someone ask me to introduce him into the whole programming thing i always recommend to start with C, it’s not just because it’s the cleanest and straightest language to work with -it definitely is-, no, it’s because learning C will teach the developer how things really work and will turn on your “programmer” mind-set.

Understanding how C works makes you capable of understanding how other c-based languages (like JS, or python) works under the hood and hack or trick them with knowledge and ease.

Continue reading “Javascript by reference: understanding javascript”

High performance with canvas prerendering

Canvas API is slow by nature, don’t try to argue this, it is…
When using HTMLcanvas, we have to know how the whole thing works, first of all, the canvas 2D context itself is an Int8Array with length (side^2) * 4 and an API to modify this array, this API is an abstraction layer that allows you to easily draw shapes, paths, etc without leading with pixel modification or rasterizing.

Each time you tells this API to draw a rectangle, it calculates the new state of all the pixels involved, this could be easy, but if you draw a shape like an triangle or a irregular one, the API will triangulate it, calculate the pixels state and rasterize it, and trust me, this take’s a lot of time and hard working.

Continue reading “High performance with canvas prerendering”

Design a site like this with WordPress.com
Get started