Skip to content
Case study

Kronland

Kronland is our own browser strategy game at village.blax.at, still a prototype: villages and armies on a shared map of 1,000 by 1,000 fields. We built it as a proof of concept for a realtime multi-user app on our standard stack, Laravel and Nuxt over WebSockets.

  1. Challenge

    In a browser strategy game, a lot happens while nobody is looking: a building finishes, an army arrives, a village runs out of food. Each event has to happen at the right moment and in the right order, and reach the owner's screen without a reload. Players compete, so the browser cannot be trusted with a single number. That makes the genre a good test for any app where many users share live state and work runs on timers.

    Kronland's twist: in an established browser strategy game every village has the same fixed list of buildings. Here a village has a budget of building space instead, 40 units at headquarters level 1 and 5 more per level, and most types can be built more than once, each copy at twice the cost and half the effect of the one before. A village filled mostly with resource or military buildings earns a bonus for that role.

  2. What we built

    The server owns every rule. The browser sends only intents, such as building a farm, and the Laravel server checks cost, space and queue and computes every cost, duration and timestamp. After login everything runs over one WebSocket connection, as in LearnATC: 64 WebSocket handlers, HTTP only for registration and login. In return the whole game depends on the WebSocket server.

    Nothing recomputes every village each second. The server keeps resources as a value, a rate and a timestamp, computes the current amount on read and writes it back before a rate changes. The client runs the same formula, so the counters on screen move without extra messages. The catch came when we raised the live world from speed 1 to 4: a migration first had to settle every village at the old speed. Beginner protection measures people, not the game, so it lasts 5 real days at any speed.

    Timed effects, such as a finished building or an arriving army, are rows in our own events table with a due time in milliseconds. Delayed queue jobs have no global order, and when an attack and a wall upgrade hit the same village in the same second, the order decides the battle. One worker processes the rows by due time and id with the village row locked, and every read or action on a village first runs its due events itself, so a slow worker never shows a stale village and the tests need no worker. Pushes carry no game state, only a hint that a village changed. They go out after the transaction, and the client fetches the village again.

    WebSockets alone did not make the game feel instant: after each action the controls locked. The causes were mostly in the client. One shared busy flag disabled every button until the answer came, a push then started a second full refresh, and answers arriving out of order let an older state overwrite a newer one. Now build, upgrade and cancel show at once, on a copy of the village built only from numbers the server already sent, and a refusal restores the old state. Refreshes run quietly one at a time, older answers are dropped, and only actions that commit troops or coins lock their form. Profiling the server found the same workforce computed 72 times per village payload. Computing such values once, and skipping a locking step when nothing is due, took the payload from 34 to 15.5 ms on our development machine and from about 88 to 65 ms on the live server.

    The village view started as inline SVG with about 12,700 polygons as DOM nodes, all re-rendered on every pan or zoom step. We moved the picture to three.js and kept a thin SVG layer on top for click targets, keyboard focus and labels: 72 elements. In a headless browser with software WebGL, a 40-step drag took 1.3 to 1.5 seconds instead of 2.0 to 2.5. The cost is a three.js file of 145 KB gzipped.

    The rules are plain PHP without database access or a clock, covered by 327 backend tests, and a config lint with 19 checks fails a test when a changed number could leave a village stuck. One deploy still went wrong. The old worker, still running, picked up an event the seeder had just scheduled, did not know its type and retired it after three failed attempts: the limit that keeps one broken row from stalling a village threw away a valid event. The deploy now stops the worker before migrating and seeding, and after each backend deploy we run a script that tests the WebSocket API end to end in a throwaway container with its own database, never with accounts on the live game.

  3. Stack

    The server runs Laravel 13 on PHP 8.4 with MySQL 8.4, Redis, Sanctum bearer tokens and Pest. WebSockets run on our laravel-websockets package, and the WebSocket server and the event worker share one container, so the worker's pushes reach the WebSocket server directly. The client is Nuxt 4 in TypeScript with Tailwind CSS 4 and three.js, built as static files without server rendering, which buys nothing behind a login. The cost is the public landing page: a crawler that does not run JavaScript gets an empty shell. Everything runs in Docker Compose behind Traefik on our servers at Hetzner in Germany.

  4. Result

    Kronland is live at village.blax.at as a prototype, in English. Of the 72 items on its roadmap, 55 are done. Encounters between marching armies, profile pages and overviews across villages are among the 17 still open. It is a test bed for our stack, not a launched product.

    What carries over to any app where many users share live state and work runs on timers: store value, rate and timestamp instead of ticking the world, and settle the value before a rate changes. Keep timed effects in your own table, ordered by due time and id, and catch up a record's due events on every read. Send pushes as hints after the commit. Show cheap actions at once, drop answers older than the one on screen and lock only what must not run twice. Measure before you optimise. Let timers that measure people run in real days, however fast the simulation runs.

    Visit the live site

A steaming green enamel mug next to a book on a table by the window.

Want something like this for your business?

Tell us what you need. We will get back to you within one business day.

Fabian Wagner, founder of Blax Software

You talk to Fabian Wagner, founder

No sales desk in between: he reads every enquiry himself.

Prefer a call? +•• ••• ••• •• ••