Urgent.News

What's breaking now, across hundreds of outlets.

Culture

The tournament clock that survives a bar's Wi-Fi

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…

A weekly poker league features a bar's Wi-Fi connection. A single person oversees the tournament, which must maintain precise timing without interruption. To ensure consistent gameplay, I created TT Poker, a tournament clock and check-in system for home games and club nights. The challenge was not in the card logic, but in managing state, clocks, and unreliable networks.

Initially, I used setInterval to count blinds levels, but this caused the clock to drift by over two minutes over a four-hour period. To fix this, I stored levelStartedAt as a timestamp and derived everything else from it. I also switched to using performance.now() for measuring durations, as Date.now() on cheap hardware is not monotonic.

When reconnecting after a client disconnects, I sent each phone's timestamp and let the server sort by it. However, this led to eliminated players being removed before their corresponding hand. To resolve this, I assigned a unique sequence number to every mutation, carried by the server, not the client. This prevented duplicate eliminations when two offline phones attempted to eliminate the same player simultaneously.

Idempotency was crucial for the person running the night, who often made double taps due to the laggy tablet. I generated an idempotency key for each mutation, using a combination of the device ID and a counter. The server kept the last N keys and returned the previous result for a repeat instead of applying it twice. This eliminated bugs where the table showed an incorrect number of players.

Designing the TV client was challenging due to its different requirements compared to a phone. The clock needed to be readable from across the room, so I used integer scaling, no fractional layout, and avoided animations. The TV client also had to be a simple view that could be reloaded at any moment and reconstruct itself from a local state fetch.

The cloud was used as a backup and cross-venue view, while the local box served as the source of truth for the evening. This approach minimized reliance on the flaky Wi-Fi connection in the bar. Additionally, I implemented a staggered check-in process to prevent the Wi-Fi chip from becoming overwhelmed when everyone joined at once.

When building a similar system, I recommend treating the night as a state machine with an append-only log, and making every screen a projection of it. Never trust client clocks for ordering or client counters for idempotency alone. Design for the person running it being distracted, and measure your refresh budget on the worst hardware you intend to support, then halve it.

The card game may be straightforward, but the four hours of wall-clock time, thirty flaky phones, and one distracted operator present the real challenges.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Culture

How to catch a missing outlet in a virtually staged room photo

How to catch a missing outlet in a virtually staged room photo By Louis, developer of VacantStage A sofa can look convincing even when the editor has quietly changed the room around it.

  • Compare original and staged images side by side using layers in GIMP.
  • Inspect for discrepancies in room layout at each corner, like window frame and baseboard.
  • Use "Difference" mode to highlight changes, noting exposed outlets or obscured furniture.

Iowa’s QB Kept Its Playoff Hopes Alive in a Rivalry Rout

Hank Brown accounted for four touchdowns against Nebraska. Iowa still has two paths to the College Football Playoff.

  • Iowa quarterback Hank Brown leads Hawkeyes to rivalry win
  • Brown rushes for three touchdowns, contributes on passing
  • Victory keeps Iowa in contention for Big Ten championship

More from Saturday, 28 November 2026 →