RUNG: a server-authoritative multiplayer backend in Go
My own project: a four-player Court Piece (Rang) card game with a Kotlin Android client.
RUNG is a real-time card game played in two teams of two. You can try it on playrung.online or Google Play.
In numbers
- Around 3,000 installs
- More than 1,000 matches played a day
- 33,396 matches played in total
Figures as of December 2026.
The constraints
- Clients can be modified, so none of them can be trusted with the rules or the other players' cards.
- Mobile networks drop. Losing a connection for a moment can't lose the match.
- Players need a way to check that the deal wasn't rigged.
- I need to ship server changes while people are mid-hand.
Architecture
Android / web client
| HTTPS + WebSocket
rung-server (Go) REST API, matchmaking, match sessions
|
+----+-----+
PostgreSQL Redis
records queue, presence, saved tables
Decisions that shaped it
The server decides everything
The client sends an intent such as "play this card". The server owns the shuffle, legality, trick winner, score and rating change. Each seat gets its own snapshot containing only its cards and the number of cards everyone else holds. The rules live in a pure Go package with no clock, database or network, which makes them easy to test.
One goroutine owns one match
A card from a socket, a disconnect, a timeout and a bot's move are all posted to the same channel. The rules engine is never touched concurrently, so a card can't race a dropped connection. The price is that the session's timing logic has to be right, and I learned that the hard way.
A shuffle you can verify
The server draws a random 32-byte seed for each match and publishes a SHA-256 commitment before every hand. The deck is a Fisher-Yates shuffle driven by an HMAC-SHA256 stream, and the seed is revealed when the match ends, so anyone can recompute the deal. I didn't use math/rand because an old match has to produce the same deck after a Go upgrade.
Disconnects are normal
If it's your turn when your connection drops, the turn clock pauses for a limited grace period. After that a bot covers your turns so the other three can keep playing, and only a long absence forfeits the match. Bots see exactly what a human in that seat would see.
Deploys during live games
Live tables sit in memory, so a restart used to end every match. Now each table is saved to Redis whenever it moves. The old server saves, releases ownership and closes sockets with WebSocket code 1012; the app reconnects after a short random delay, and the new server picks the table up. Stopping the old session before releasing it means two servers never drive the same match. Blue/green containers behind nginx keep a warm server ready.
Tradeoffs
- Keeping live state in memory keeps the move path simple and quick, but needs the save and hand-off machinery above.
- The hand-off is stop-then-resume. A gapless takeover would need fencing on every move, which I haven't built.
- A watchdog settles a table that stops advancing. Ending a broken match early is better than leaving four people stuck, but it is a backstop and every trigger is a bug to chase.
Stack
Go, chi, gorilla/websocket, PostgreSQL (pgx), Redis, Firebase, Docker, nginx, Kotlin.
Building something real-time in Go?
Email haiderzamanusafxay@gmail.com and tell me what's going on.