03Stateful multiplayer systems

AHD.GG

An Arabic strategy product built to test authoritative state, contested transactions, idempotency, background simulation, and full-stack delivery.

A convincing interface is not enough when multiple players compete for the same state.
348req/s village endpoint
66msp95 village latency
1/20winner in market contention
83test files at audit
THE CHALLENGE

Why this was hard

01

Concurrent players can attempt to accept the same market offer or repeat the same command.

02

Economy and combat outcomes must be resolved against authoritative server state.

03

Lightweight test databases cannot reproduce every PostgreSQL locking behavior.

MY ROLE

What I owned

  • Defined interconnected rules for the world, economy, combat, market, alliances, wallet, and progression.
  • Required server authority for sensitive commands and outcomes.
  • Directed monorepo structure, API behavior, persistence, workers, deployment, and PWA experience.
  • Designed controlled contention and load scenarios and interpreted the results.
KEY DECISIONS

The choices behind the system.

01

Intent in, authority out

The client expresses player intent. The server validates state and resolves the final economic or combat outcome.

02

Transactions decide races

Market acceptance and resource changes rely on atomic database behavior so contested operations produce one valid winner.

03

Test the risk on the real engine

PGlite remained useful for speed, but PostgreSQL tests were required for row locking, contested transactions, and concurrent idempotency.

VERIFICATION

Claims tied to evidence.

Every figure carries its scope. Strong evidence includes the boundary around what it does—and does not—prove.

  • React 19/Vite PWA, NestJS/Fastify, Drizzle, PostgreSQL, Docker, Caddy, workers, and Web Push.
  • Village endpoint: 348 req/s at 66 ms p95; map endpoint: 341 req/s at 70 ms p95 in a controlled environment.
  • Contested market acceptance produced one winner and 19 GONE responses.
  • Ten concurrent idempotent requests produced one execution across five rounds.
OUTCOME

What changed

AHD.GG became a broad full-stack system with explicit domain rules, server authority, CI gates, database-level contention tests, and measurable performance on core paths.

Scope note

Performance figures come from a controlled test environment, not production traffic or a general capacity guarantee.

REFLECTION

What I learned

Stateful products fail at the boundaries between systems.

Concurrency claims require contested scenarios on the production database engine.

Performance numbers remain honest only with environment and scope attached.

TypeScriptReactViteNestJSFastifyPostgreSQLDrizzleDocker
Next case studyScopova