AppStars

Live scoring without a scoring server

How Slam, our tennis club app, put live scores on every member's phone with Firebase listeners and transactions, one umpire lock per match and presence-based release.

In 2020 we started building Slam, a social tennis club app designed and developed for Tennis Australia. Club volunteers were running competitions on paper draws, score sheets and clipboards. Members and parents rarely knew who was playing when, or what the score was.

The feature everyone wanted was live scoring. Someone courtside taps the score on their phone, and everyone else in the club sees it change. Even if you don't know the rules of tennis, the app does the counting for you.

The obvious design is a scoring server with sockets. We didn't build one. This post is about what we built instead, and why it held up.

The problem

Live scoring sounds like a broadcast problem: one writer, many readers. In a club it isn't that tidy.

  • Anyone with the app could pick up a match and start umpiring it, so two people might try at once.
  • Phones lose signal at the far court, get locked, run flat or get handed to a child.
  • Scores get corrected. A wrong tap followed by a fix must not leave the ladder points wrong.
  • Spectators must see changes without refreshing, on cheap phones on club Wi-Fi.
  • One product with a small budget. Every server we ran was a server to patch, monitor and pay for.

Architecture

Slam is a Flutter app for iOS, Android and iPad on Firebase. There are no sockets and no scoring server. "Real time" is the Firebase Realtime Database: the app writes small updates and transactions to a JSON tree, and every client watching a node gets a change event.

Flutter app (iOS / Android / iPad)
  umpire taps --update() / runTransaction()--> Realtime Database
  spectators  <--onChildChanged streams------  (clubs/competitions/draws/
                                                 rosterItems/matches/sets)
                                                  |
                                     Cloud Functions (database triggers)
                                     - push notifications (FCM)
                                     - release umpire locks on disconnect
  Node/Express on App Engine: payments, email, scheduled match reminders

The data sits in a deep per-club tree. Field names on hot paths are short keys (lfu, lfub, lfubk, lfut, umk), because every byte goes to every spectator on every change.

The engineering

One umpire per match

Two people scoring the same match at once is not a merge problem. It's a "who holds the pen" problem, so we gave each match a lock: lockedForUmpiring, plus who holds it, their user key and a timestamp.

Entering the umpire screen checks the live match. If it's unlocked and playable, the app takes the lock. If someone else holds it, or the match can no longer be played, the screen closes with a "kick". The same check runs when ownership changes underneath you, so a second umpire can't keep tapping on a stale screen. Abridged from the umpire screen:

if (!match.lockedForUmpiring && match.status == MatchStatus.CanBePlayed) {
  if (!await _lockUmpiring()) { /* tell the person, go back */ }
} else {
  if (match.status != MatchStatus.CanBePlayed ||
      match.lockedForUmpiringByUserKey != Application.loggedInUser.key) {
    Navigator.pop(context, 'kick');
    return;
  }
}

Releasing the lock when the phone disappears

A lock is only as good as its release. The umpire whose phone dies mid-set never presses "done", so the lock has to be released by something that notices they've gone.

The Realtime Database has a primitive for exactly this. When a user comes online, the app registers an onDisconnect write with the server, which sets the user's online flag o to false when the connection drops, however it drops:

FirebaseDatabase.instance
    .reference()
    .child('$path/$userKey/o')
    .onDisconnect()
    .set(false);

A Cloud Function triggers on writes to /users/{userKey}/o. When it goes false, it reads the match the user was umpiring (umk), checks the lock is still theirs, and clears it. The check matters: if someone else has taken over in the meantime, the function leaves their lock alone.

The nice property is that no client has to be well behaved for this to work. The server notices the dropped connection, the database writes the flag, and the function cleans up. A comment in the code shows we were already planning to move the umpiring status onto the user object to simplify it further. That's honest work in progress, and the mechanism held.

Transactions where they matter

Scores are written to a single leaf per side per set. setSetScore uses a Realtime Database transaction with a one-minute timeout, and retries after a second if the transaction doesn't commit. With the lock in place there's normally only one writer, so for the score itself this behaves as last-write-wins with a reliable retry.

Counters are where transactions earn their keep. Ladder points, likes and similar totals are updated transactionally in more than 20 places, because two clients incrementing the same number is the classic lost update.

Corrections as deltas

When a score changes, the app doesn't recompute a player's points from scratch. It computes the difference between the new and previous score and applies that as a transactional increment or decrement:

double deltaPoints = ((newScore == -1 ? 0 : newScore) -
        (previousScore == -1 ? 0 : previousScore).toDouble()) /
    10.0;

A wrong tap followed by a correction produces a positive delta and then an equal negative one, so the totals end where they should, even with other matches updating the same player concurrently.

Live fan-out

Spectators subscribe to onChildChanged on the match node, and the app hands each changed property and value to the screen. The code carries a blunt reminder above the subscription methods: "DON'T forget to unsubscribe!" Every listener left open is bandwidth and battery spent on a screen nobody is looking at.

Around that core sit the club features: score validation against each draw's rules (games per set, lead-by, limited games) with rule text people can read, completion cascading from set to roster item to finals, a round-robin scheduler using the circle method with byes, and our own geohash encoder for finding nearby clubs.

Where AI fits

Slam had no AI in it, and it was built before AI coding agents were part of our workflow. But the umpire lock is a pattern we use with AI today.

The question "who holds the pen?" comes back whenever an automated system can write to the same place as a person. On the Knowby platform, AI assistants can create guides through an MCP server, but only as private drafts. A person decides when anything is published. That's the same idea as one umpire per match: let many readers in freely, and make the right to write explicit, visible and revocable.

What it taught us

Slam was a small codebase with a big surface: about 58,000 lines of Dart, payments, email, push, chat, news, albums and a store listing. Some trade-offs we made knowingly, and some we'd change.

  • Use the platform's primitives before writing servers. onDisconnect, transactions and database triggers removed the need for a socket server and a session tracker. That's fewer moving parts to keep alive for a club on a Saturday morning.
  • Prefer avoiding conflicts to resolving them. A single-writer lock and delta updates meant we never needed vector clocks or merge logic.
  • The lock timestamp deserves an expiry. We recorded when a lock was taken but leaned on presence for release. A time-based expiry as a second safety net is something we'd add today.
  • Tests were thin. A handful of function tests and a UI-test script isn't enough for scoring logic with three competition formats. Today the rules and the cascade would sit behind a solid unit-test suite before anything else.

We also took Slam all the way to market: store listings, preview videos, club posters, onboarding and paid subscriptions through Square. Building the engine is half the work. Getting a volunteer to trust it on court is the other half.

Why it still matters

Plenty of business apps have the same shape as a tennis match: one person doing the work, many people watching, and phones that drop out at the worst moment. Job sites, inspections and dispatch boards all need someone clearly holding the pen and everyone else seeing it live. The Slam case study shows the product, and our mobile and field apps page covers how we build for patchy connections.

Bring us the hard problem.

A 45-minute discovery call with the engineer who'll build it.