Memoryless is a free multiplayer memory game that runs in the browser. You flip face-down tiles looking for sets of three, race a turn timer, and try to outscore everyone else in the room. It has private rooms with invite links and QR codes, random matchmaking with strangers, a leaderboard, and it works fully in English and Arabic.

I designed and built it solo, end to end. This post is about the two constraints that shaped every decision, and what I learned building against them.

The two constraints

1. It had to cost nothing to run. Not "cheap". Zero. No billing account anywhere, forever.

2. It had to be cheat-proof. In a memory game, the whole game is the hidden information. If a tile's value ever reaches a browser before it is flipped, someone will write a script that reads it. So hidden tile values must never leave the server. Not encrypted, not obfuscated. Absent.

The first constraint rules out most of the usual real-time stack. The second rules out most of the usual shortcuts. Together they made the architecture almost pick itself.

The stack

Layer Choice Why
Web app Next.js static export, TypeScript, Tailwind, Framer Motion, Zustand A static site on Cloudflare Pages is free with unlimited bandwidth. No server rendering needed.
Game server Cloudflare Workers + Durable Objects One Durable Object per room gives me a single-threaded, stateful process per game with WebSockets. The free plan includes SQLite-backed Durable Objects.
Auth Firebase Authentication, Google and anonymous only Firebase's free tier covers auth. Phone sign-in was out because SMS is never free.
Validation Zod, shared by client and server One schema, both sides.
i18n next-intl English and Arabic with full RTL layout.

Firebase is used for auth and nothing else. No Firestore, no Realtime Database. The Worker verifies Firebase ID tokens itself with jose against Google's public keys.

One rule: the engine is pure, the server is a thin host

The monorepo has three packages: apps/web, apps/server, and packages/shared. Every game rule lives in packages/shared as pure functions with unit tests. The core of it is one signature:

applyMove(state, move, now) => { state, events, error } 

Give it the room state, a move, and the current time. Get back the new state, a list of events to broadcast, or a rejection. No I/O, no timers, no randomness that is not passed in.

The Durable Object does three things: validate the incoming message with the shared Zod schema, call applyMove, persist the new state and broadcast the events. It does not know what a "match" is. The UI does not know either. Both are hosts for the engine.

This paid off immediately. Every edge case in the rules, and there are many, is a unit test that runs in milliseconds with no server. When I found a bug in how a player who closes the tab in the lobby was handled, the fix was a pure function and a test, and the Durable Object did not change.

Cheat-proof by construction

The room state on the server has two views of every tile: the secret value and the public face. Clients only ever receive a public snapshot, produced by one function that maps each tile to what a viewer is allowed to see. A face-down tile serializes with no value at all.

That function is the invariant, and it has a test: build a room, take a snapshot, assert that no hidden value appears anywhere in the serialized output. Any future change to the protocol has to keep that test green.

The harder mode made this more interesting. In advanced mode, each turn you choose to either reveal (peek at three tiles, visible to everyone for a few seconds) or select (pick tiles face-down from memory). In select, the tiles never flip. The server compares the hidden values and tells you only whether you matched. The client literally cannot cheat, because it has nothing to cheat with.

Time belongs to the server

Countdown timers are a classic source of desync and exploits. A client that renders its own timer can be paused in devtools.

In Memoryless, the server owns every deadline: turn timer, reveal visibility, mismatch flip-back delay, reconnect grace, session cap, rematch window. Each snapshot carries the relevant deadline as an absolute timestamp. The client measures its clock offset from the server and renders the countdown from that. It never runs a timer of its own that affects the game.

On the server side, Durable Objects have exactly one alarm. The engine exposes a function that returns the earliest moment the room needs to be revisited, and the DO sets its alarm to that. When the alarm fires, the DO calls applyMove with a tick and the same pure rules decide what expired. No polling, no setInterval, and the room hibernates between events, which is what keeps it inside the free tier.

The parts that were harder than they looked

Disconnects. A player who drops gets a 30-second grace period. After that their turns are skipped, and after two missed turns they are removed and the game continues. If fewer than two players remain, the game ends. All of it is in the engine, so it is tested like everything else.

Random matchmaking. Four strangers, fixed settings, and each player votes on category and mode. Majority wins, ties are random. A single matchmaker Durable Object holds the queue and heartbeats dead sockets out of it.

Static export and dynamic URLs. A room lives at /room/<code>, but a static export cannot pre-render a URL it does not know at build time. The fix is a fixed /room page plus a Cloudflare Pages redirect rule that serves it for /room/*, with the code read from the browser's location on the client. The URL bar keeps the real address, and there is no server rendering anywhere.

Arabic. Right-to-left is not a translation task, it is a layout task. Every spacing and positioning utility in the app uses logical properties, so padding-inline-start instead of padding-left, and the whole UI mirrors correctly with one dir="rtl" attribute. Arabic gets its own typeface.

Before launch

I ran a full security audit before going live: secret scanning across the git history, dependency audit, a review of the auth flow and the protocol, and rate limiting on every HTTP route plus per-socket throttling in the room. Findings went into a register and were fixed and re-verified before the gate passed. Hidden tile values not reaching the browser was already covered by the invariant test, which is the point of writing it.

What I would tell past me

  • Make the rules a pure library first. Everything else became easy because the engine had no dependencies. Even the time is a parameter.
  • Put the invariant that matters in a test, not a comment. "Hidden values never leave the server" is a sentence until a test enforces it.
  • Design for the free tier on day one. Hibernating WebSockets, a single alarm per room, and an edge-cached leaderboard are not optimizations I added later. They are why the bill is zero.
  • Treat RTL as a first-class layout mode from the first component. Retrofitting it is miserable.

Play it at memoryless.pages.dev, or in Arabic at memoryless.pages.dev/ar. The project page with screenshots is on GitHub, and you can find more of my work on my portfolio.

I'm Nour Mohsen, a software engineer working with React, React Native and real-time web applications. Happy to answer questions about any part of this in the comments.