Fly.ioTutorial
Building a Distributed Turn-Based Game System in Elixir
Summary
Mark Ericksen describes building a proof-of-concept distributed, clustered game system for turn-based multiplayer applications with Elixir and Phoenix LiveView. Rather than separate JavaScript and API layers or external state systems such as Kafka and Redis, the design uses server-rendered HTML over websockets, Phoenix.PubSub, and Horde’s distributed process registry. A player’s LiveView sends moves to a GameServer, which publishes updated game state so subscribed LiveViews re-render for every connected player; Tic-Tac-Toe supplies the model. Hosted on Fly.io, geographically close web servers connect over a private WireGuard network while a game’s single GameServer remains the source of truth, with libcluster handling cluster formation and healing. The resulting open-source proof of concept supports multiplayer games, four-letter game codes, on-demand creation, responsive updates, and globally clustered servers.
Context
The author wanted to move beyond Phoenix LiveView examples where multiple browsers communicate with one web server, creating instead a fully clustered, globally distributed, privately networked, and secure game server system. The project also aimed to test whether this could be built independently with fewer technologies and less specialized infrastructure.
Approach / What changed
The system uses Elixir, Phoenix, Phoenix LiveView, Phoenix.PubSub, Horde, and libcluster. LiveViews communicate with browsers over bidirectional websockets, send moves to distributed GameServers, and receive published state updates. Fly.io provides geographically distributed servers, private WireGuard networking, HTTPS, and multi-region deployment, while each game’s single GameServer acts as its source of truth.
Takeaways
Phoenix.PubSub distributes updated game state, while Horde provides a distributed process registry for locating and interacting with GameServers.
Fly.io places web servers near users while allowing them to communicate privately with a GameServer running in another region over WireGuard.
The proof of concept supports multiplayer games, four-letter game codes, on-demand game and match creation, responsive updates, and clustered servers.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.