Game Server Framework Architecture Overview
This article outlines a four‑layer game server framework—including gateway, logic, record, and database services—detailing their responsibilities, implementation models such as multithreaded reactors and coroutine libraries, service‑driven designs, and the common design patterns and algorithms used in backend game development.
Game types (card, ARPG, MMO, MOBA, etc.) vary greatly, leading to different framework designs; this article discusses the essence of these frameworks from a layered architecture perspective.
The architecture can be mapped to a four‑layer model: Gateway Service, Logic Service, Record Service, and Database.
Gateway Service handles client network entry, converting and filtering messages. It is implemented as a high‑performance network service using a Linux multithreaded model (one loop per thread) based on the reactor pattern, with optimizations such as CPU binding and NIC interrupt tuning. In practice a single gateway can support up to 150,000 concurrent users with low load.
Implementation options include:
多线程模型 – multithreaded model; open‑source examples: muduo, asio, netty.
纤程 – coroutine model; open‑source examples: Go, Erlang, libco, skynet.
Logic Service processes core game logic. A common approach is multiple I/O threads combined with dedicated business threads, communicating via message queues (locked or lock‑free). Business logic often runs in a single thread to avoid data races; for high‑load MMOs, multiple Logic Services or multi‑process designs may be used.
Record Service acts as a database proxy, decoupling business logic from data storage and simplifying database changes. It can be merged into the Logic Service but is usually kept separate for clarity.
Database stores player data. Typical choices include MySQL, Redis, MongoDB. The article describes using RedisLV , which integrates LevelDB for efficient backup, reducing memory usage during Redis snapshots.
Service‑Driven Design for the Logic Service includes two driving mechanisms:
消息驱动 – message‑driven, responding to network messages via the command pattern.
时间驱动 – time‑driven, handling timed events (e.g., scheduled activities) using timers implemented with algorithms such as time wheels or red‑black trees.
Common design patterns used in game server development are Singleton, Factory, Command, Observer, State, and Strategy.
Typical algorithms include Binary Search, Quick Sort, Red‑Black Tree, Skip List, Priority Queue, A*, and Behavior Trees.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.