A weekly poker league night is a distributed system that nobody calls a distributed system.
There are 18 to 30 phones on a bar's Wi-Fi. There's a TV on the wall that everyone stares at. There's one person running the thing who is also, unfortunately, playing. And there's a four-hour clock that must not drift, must not double-eliminate anyone, and must keep working when the router does its 11pm thing.
I built TT Poker (a tournament clock and check-in system for home games and club nights) and the interesting part was never the card logic. It was everything around it: state, clocks, flaky networks, and a TV nobody can touch.
Here's what actually bit us, in the order it bit us.
1. setInterval is not a clock
The first version counted blinds levels with a setInterval(1000). Over a four-hour night it drifted by more than two minutes, because every tick is "at least 1000ms", never exactly. Worse, when the tab was backgrounded or the TV box's vendor cleaner suspended the browser, the interval simply stopped — and then fired a burst of catch-up ticks on resume, skipping a level entirely.
The fix is boring and correct: store levelStartedAt as a timestamp, and derive everything from it.
const elapsed = () => Date.now() - levelStartedAt; const remaining = () => Math.max(0, levelMs - elapsed()); Render from a requestAnimationFrame loop, but never store the time from that loop. The clock is a function of two numbers, and the display is a projection of it. If the process dies and restarts, it recomputes the same answer.
One caveat that cost us a night: Date.now() on cheap hardware is not monotonic. If the box gets its time from the network and the network is wrong, your clock jumps. Any duration you measure should use performance.now(); only wall-clock labels (the timestamp you show humans) should use Date.now().
2. Time is a lie on the client
Our first reconnect protocol sent "I was eliminated at 21:47:03" from each phone and let the server sort by timestamp. That produced a player being eliminated before the hand that eliminated them, because two phones disagreed about the current minute by 90 seconds.
Timestamps from clients are decoration. Ordering has to come from a single monotonic counter on the authority:
// every mutation carries the server's seq, not the client's clock { seq: 418, type: 'eliminate', playerId: 'p-27', by: 'p-12' } Phones can queue actions while offline and replay them on reconnect, but the server assigns seq on receipt. If two offline phones both claim to have eliminated the same player, the second one gets a conflict, not a duplicate elimination.
3. Idempotency is a UI feature
The person running the night is doing this on a laggy tablet, one-handed, while being dealt in. Double taps are not an edge case; they are the normal case.
Every mutation gets a client-generated idempotency key:
const key = `${deviceId}:${localCounter++}`; The server keeps the last N keys and returns the previous result for a repeat instead of applying it twice. This single change removed an entire class of "why is table 2 showing 8 players when 9 people sat down" bugs. The button also disables on pointerdown, not on the response — you can't rely on round-trip latency to protect you from a human tapping twice in 200ms.
4. The TV is the hardest client
A wall-mounted TV at three meters has different requirements from a phone at thirty centimeters:
- Legibility beats density. The clock is the only thing that must be readable from across a room. Everything else is secondary.
- Integer scale, no fractional layout. Non-integer scaling on a 1080p TV panel makes text shimmer. Compute a scale factor once per break, not per frame.
- Don't animate. These boxes are quad-core A53 class with 2GB of RAM. A CSS transition on a list of 30 rows is enough to drop frames and make the whole display feel broken. We removed all of it and the perceived quality went up.
- Assume it will be interrupted. Vendor "cleaners" and Android's doze will kill a backgrounded browser. The TV client has to be a dumb view that can be reloaded at any moment and reconstruct itself from one state fetch.
5. Put the authority on the box, not in the cloud
We started cloud-first, because that's the default. It was wrong for this use case: a bar's uplink is the least reliable link in the room, and it's shared with 30 phones uploading photos.
The current shape:
phones ──(local Wi-Fi)──> TV box (authoritative state, SQLite) │ └──(opportunistic)──> cloud (backup, cross-venue view) The local box is the source of truth for the evening. The cloud is a replica that catches up when it can. If the internet dies mid-level, nobody notices. If the box dies, you lose the night — so state is appended to a local log and the whole thing can be replayed from it.
The local state delta is tiny, around a kilobyte per mutation. You are not moving video; you are moving {seq, type, payload}. That's the whole reason this can run on hardware that costs less than the beer.
6. Check-in should not require installing anything
QR code on the TV, phone camera opens a URL, you're seated. No app, no account, no password. The join token is single-use and expires with the level.
The failure mode we did not anticipate: everyone joins at once, in the same 90 seconds, and the box's Wi-Fi chip gives up. We now stagger check-in by table and treat the join endpoint as a rate-limited queue rather than a burst handler.
What I'd tell someone starting today
- Treat the night as a state machine with an append-only log, and make every screen a projection of it.
- Never trust a client clock for ordering; never trust a client counter for idempotency alone.
- Design for the person running it being distracted. Every destructive action needs an undo that costs one tap.
- Measure your refresh budget on the worst hardware you intend to support, and then halve it.
The card game is the easy part. The four hours of wall-clock time, thirty flaky phones, and one person who is also trying to play — that's the system.
