Understanding HTTP-Based Multiplayer Games

The most basic type of a multiplayer game you can build is the one in which the client does full-page or AJAX requests to update itself. This type of game relies on the client sending information to and requesting information from the server. If this sounds like a typical web page, you’re correct. The downside is that the server has no capability to reverse the equation and instantly notify the client when something happens. The upside is that you can use a standard web architecture and server to build and scale your game.

Most small-scale websites share a similar architecture: server code written in a scripting language (be it PHP, Ruby, Python, or JavaScript) that writes and reads data to and from a persistence layer, such as a database. No information is shared between requests except a small amount of session data; instead everything is stored in the database (or other persistence layer such as a key-value store such as Redis). Keeping the architecture simple means that you can continue to add web servers to handle an increased load, and the only area in which you need to worry about having a scaling problem is at the database layer.

This type of architecture has served the web well for the past couple of decades and can be a suitable architecture for building multiplayer games provided it’s used appropriately. It’s not a great architecture for games that need to have a lot of direct interactions between different players because the ...

Get Professional HTML5 Mobile Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.