Persistent multiplayer state without chaos
A practical architecture for managing multiplayer game state using PostgreSQL as the authoritative source of truth and Redis for hot/derived state. The approach separates authoritative state (player resources, queued jobs, achievements) from hot state (caches, presence, locks), using PostgreSQL transactions with SELECT FOR UPDATE for per-player mutations and Redis SetNX distributed locks to prevent double-execution of background tickers across multiple backend instances. Key patterns include cache invalidation before returning success, pushing scheduled work into a finishes_at column for efficient indexed queries, and keeping all multi-row mutations inside a single transaction. The architecture is demonstrated through HiddenWars, a browser-based multiplayer strategy game built with Go (Echo + pgx).