Robbie Ardiansyah
← All work

Keeping open orders in sync across tills

A restaurant often runs several POS terminals at once. An order opened at one has to be visible, and editable, at the others. I built real-time open-order sync over Firestore for an app that was designed to work alone and offline.

Product
Omni POS
When
2023 – 2024, extended 2026
Built with
Kotlin, Firestore, MQTT, Realm, Room

01The problem

Omni POS is offline-first. Each terminal keeps its own orders and syncs with the server later. That works for one till. With several, an order opened on one terminal wasn't visible on the others.

Open orders needed to be shared between terminals in real time, without giving up the local-first model that keeps the POS running when the connection drops.

02The design

Each store gets a Firestore collection of its open orders. Every terminal in the store listens to that collection and keeps writing to its own local database as before. Firestore carries changes between them.

  • Upload on change. When an order changes locally, the terminal writes the whole order to its document in the store's collection.
  • A revision ID on every order. Every local change stamps the order with a new random revision ID and a last-updated time.
  • Apply incoming changes selectively. When a document changes, the terminal compares revisions. If it already holds that revision, the event is ignored, which also stops a terminal from re-applying its own writes when the listener echoes them back. Otherwise the incoming order replaces the local copy.
  • Closed sales are never touched. An order that's already paid or cancelled locally is never overwritten by an incoming update or removed by a remote delete. Once a sale is final on the device, sync can't undo it.
// Simplified from the production handler.
fun onRemoteChange(number: String, data: Map<String, Any?>) {
    val local = Order.byNumber(number)
    if (local != null) {
        if (local.revision == data["revision"]) return   // already have it (or it's our own echo)
        if (local.status in CLOSED_STATUSES) return       // a final sale is never overwritten
    }
    writeLocally(Order.fromJson(data))
}

Conflict handling is last-writer-wins at the order level rather than a field-by-field merge. That's simple, and it keeps every terminal converging on the same version of an order.

03Making it usable

  • Read status. New orders and newly added items show as unread on the other terminals, so staff can see what changed rather than hunting for it.
  • A switch. Real-time sync is a setting, and turning it on or off registers or removes the listener.
  • Existing features kept working. Split bills, item deletion and member changes each needed fixes once orders could change underneath them. Each path that modifies an order bumps the revision.
  • Cleanup. Stale sync data is cleared out, and a data-status screen shows when each kind of data last updated.

04When the store's internet is the weak link (2026)

Firestore needs the internet, and the tills in a store often share a local network that's more reliable than their uplink. In 2026 I extended the sync so a store can choose how its tills talk to each other.

  • MQTT on the store network. I added a channel that publishes each order to an MQTT broker on the local network. Messages are retained, so a till that reconnects picks up the latest version of each order. Updates made while the broker is unreachable are buffered and sent on reconnect, and retained messages expire so old orders don't pile up.
  • One channel at a time. With MQTT there were three channels, cloud sync and two on the local network, and some installations had more than one switched on. I made the channel a single choice: existing installs are migrated to one channel by a fixed priority, connection details are validated before they can be saved, and only an administrator can change the channel.
  • Same rules, every channel. Each channel goes through the same revision check, so echo filtering and the protection on closed sales don't depend on the transport.
  • Payments survive concurrent edits. Two tills can take partial payments on the same open order while offline. Order-level last-writer-wins used to drop one of them on reconnect; now incoming updates keep payments they don't mention, and a cancelled payment stops counting toward the amount paid on every till.
  • A guard that was too strict. While a local upload is in flight, server fetches are blocked from overwriting the order with stale data. That guard was also blocking legitimate changes from other tills. Since the revision check already handles echoes, real-time updates now bypass it.

05Result

Several tills in one store share open orders in real time, over the cloud or over the store's own network, while each one keeps working from its own local data when the connection drops.