- The POS device calls the API for every sale and writes to a local outbox only when the call fails. Now there are two code paths, and the offline path is not well tested.
- Sales go into SQLite, and a background job posts them to the server. The job retries after a timeout and the server records the same sale twice.
- Two POS devices disagree on the stock count and overwrite each other.
- The POS device can’t get an order number while offline, so it generates a temporary one, causing reconciliation issues.
- The POS device fetches changes since its last sync. A race condition causes it to miss changes.
1. Put a Real Database on Every POS Device
The network should never be on the critical path of a sale. Every terminal should have its own full database, and the UI reads from and writes to only that database. The network is only used to move data between that database and head office. PowerSync gives each device a SQLite database and syncs it with your backend. Your app queries SQLite with plain SQL, and writes go to SQLite first, whether or not the device is online. You define the client schema in code:powersync/AppSchema.ts
id column to every table, so you don’t declare one. See the React Native & Expo SDK reference for setup and the PowerSyncDatabase constructor.
2. Generate IDs on the POS Device and Make Every Upload Idempotent
Every record gets a globally unique ID generated on the device at the moment it is created. The server uses that ID as the idempotency key, so receiving the same record twice has the same effect as receiving it once. PowerSync recommends UUID primary keys for tables the client writes to, and provides auuid() SQL helper on the device (Client ID). Your backend should expect to receive the same operation more than once and handle it idempotently. For append-only POS records, that is one line of SQL per table on the server:
3. You Don’t Need to Build an Outbox
Once sales live in a local database, something has to get them to the server reliably and in order. This process needs to survive app restarts. DIY designs need an outbox: a local table of unsent changes, drained by a worker that retries until the server confirms. PowerSync records everyINSERT, UPDATE or DELETE on a synced table automatically in an upload queue (the internal ps_crud table), in the same SQLite transaction as the write. You define an uploadData() function that determines how entries in that upload queue are uploaded to your backend. The PowerSync SDK calls that uploadData() function after local writes, on reconnection, and automatically retries after failures. Entries leave the queue only once they have been successfully processed. See Client-Side Integration.
Ringing up a sale is one local transaction. The sale, its lines and its stock movements are queued together and uploaded as a group:
sales/completeSale.ts
uploadData() function sends each queued transaction to your backend API:
powersync/Connector.ts
4. Make Sales Append-Only
Edits to completed sales break audit trails and tax reports. If a refund updates the original sale row, you lose data. Two POS devices editing the same record creates a race condition. To prevent this, treat sales as immutable facts. Nothing is updated or deleted after the receipt prints. A refund or void is a new entry with a reference to the original. With PowerSync, your own API code handles uploads. This allows you to acceptPUT operations on sales, sale_lines and stock_movements with ON CONFLICT (id) DO NOTHING. You should also record any PATCH or DELETE on those tables in a review table (see section 9) instead of applying it.
5. Treat Stock as a Ledger, Not a Counter
If two POS devices in the same store each sell three units of a product while offline, each device’s local copy saysquantity = 6. Each writes quantity = 3. When they sync, the server ends up at 3. The real answer is 0. With a counter, last-write-wins silently causes data loss.
Treat quantity changes as changes, not absolute values, so concurrent sales are all honored. PowerSync’s conflict resolution guide calls this Cumulative Operations (Inventory). The guide lists a separate transactions table as one way to do it: this is your ledger.
In Postgres:
6. Decide Your Overselling Policy Before It Happens
With offline POS devices, you can’t prevent overselling. Two POS devices with no connection between them cannot agree on who sold the last unit. You need to decide how to handle this. PowerSync doesn’t impose a policy. Pick one per product type:- Allow and flag. The POS device warns when a sale would take derived stock below zero but completes the sale. The server alerts on negative positions for a supervisor to investigate (a missed delivery receipt, a mis-scan, or real shrinkage).
- Block. Refuse the sale when stock would go negative. This only works reliably when the check happens against a single authority, which means online. Reserve it for things that can’t be oversold, such as serialized items, event tickets or click-and-collect reservations. Accept that those sales need a connection.
7. Sync Only the Data Each Device Needs
A chain has thousands of products, store-specific prices and promotions, and dozens or hundreds of stores. Each POS device needs the full catalog and its own store’s prices and stock, and nothing else. Sync Streams define what each device receives, using SQL-like queries filtered by parameters. Your auth server issues each device a JWT withstore_id and pos_device_id claims (custom auth). The streams filter on those claims, so PowerSync only syncs the required data to the device.
updated_at cursor can fail in subtle ways:
- Late commits are skipped. A transaction that started before the cursor time can commit after the device fetched changes. Its rows have an older
updated_at, so the device never receives them. - Deletes are missed. A deleted row has no
updated_atto query. You need tombstones or soft deletes, and a way to clean them up later. - Rows that leave scope stay on the device. When a product is deactivated, the old row in the local database matches nothing on the server, so the device keeps it.
- Cursor and data get out of step. If the device saves the cursor before it applies the data and then crashes, it will skip data on the next fetch.
8. Share Open Orders Between Devices in the Store
In a restaurant, when one POS device takes an order, that order needs to reach the kitchen screen and the other POS devices within seconds. Open orders are shared state that several devices may need to display and change. Store an order as a header row plus one row per item. Two devices that add items to the same order insert separate rows, so they never conflict. The kitchen screen only changes an item’s status, and the default conflict resolution (per-field last-write-wins) handles that.closed on the order and its items, and they drop off every device. The item rows carry their own store_id and closed so the stream can filter them without a join.
A change travels from the device to your write API, into the source database, and back out through PowerSync to the other devices. A PowerSync POS customer stress-tested this propagation across a swarm of tablets, demonstrating the order propagation completing to 14 tablets in under 5 seconds.
PowerSync syncs through the server, not peer-to-peer. If the store’s internet goes down, each device keeps working, but new orders don’t reach the kitchen until it reconnects. If that isn’t acceptable, you can run a self-hosted PowerSync Service and source database on a local server in the store.
9. Write Down Your Conflict Rules
With the architecture above, conflict rules reduce to these five points:- Sales, sale lines, stock movements: never conflict. Append-only, client UUIDs,
ON CONFLICT (id) DO NOTHING. - Stock levels: derived from the ledger, never written directly.
- Catalog and prices: head office is authoritative.
- Open orders: one row per item, so devices adding items never conflict. Status changes are last-write-wins per field.
- Anything that fails a business rule: accepted, recorded in a review table for a supervisor to handle.
10. Snapshot the Price at the Moment of Sale
A POS device that is offline during a head-office price change keeps selling at the old price until it reconnects. If the server recalculates the sale from the current price table, totals won’t match what the customer paid. Copy the unit price and tax rate onto the sale line when the sale happens. The sale line is the record of what was charged. The server stores it as-is and never recalculates it from the catalog. With PowerSync, a POS device with sales in its upload queue doesn’t apply new server data until they have uploaded (see Consistency). This means that the charged price and the price on the server can differ for a short window even when online.11. Make Sync Status Visible per POS Device and per Store
Support needs to know whether a POS device is synced. The head office also needs to know which stores have POS devices holding sales that have not yet been uploaded. The PowerSync SDK exposesSyncStatus (connected, hasSynced, lastSyncedAt, upload and download state), available in React Native through the useStatus() hook. The pending upload count is a query against the upload queue, as recommended in the production readiness guide.
Here’s how you display the information to the operator:
What PowerSync Removes from a DIY Design
You still need to implement:
- The write API (idempotent inserts, append-only enforcement, the review table for rejected writes)
- Device credentials and JWTs with store and POS device claims
- Business policies for stale prices, late data and overselling
Which Backend Database
PowerSync works with Postgres, MySQL, SQL Server and MongoDB as the source database, so you can add PowerSync to an existing POS system without migrating its database.Where to Start
Make the decisions in this order:- UUIDs and append-only sales schema design
- Stock ledger design
- Overselling policy