What happens when an offline POS sale syncs twice?
A cashier completes a sale while the connection is down. Later, the server saves it, but the response never reaches the device. The app retries. Without a way to recognize the original request, the second attempt can create a second receipt and deduct stock again. Give each sale a stable ID Generate a client sale ID when checkout starts. Save it with the completed sale and the pending sync entry…
When a Point of Sale (POS) transaction is completed while the internet connection is unavailable, there is a risk that the sale may be processed twice. The first sale is saved on the server, but the response is never received by the device. The app then retries the transaction, unaware that the previous attempt already occurred. This can result in two receipts being generated and inventory being deducted twice.
To prevent this issue, it is crucial to assign a unique client sale ID when checkout begins. This ID should be saved with the completed sale and the pending sync entry in a single local transaction. The same ID should be maintained throughout retries and app restarts. The server should also be able to handle retries safely by using a unique database constraint that is specific to the store and client sale ID.
When the sale and its stock movements are committed together, the system can ensure that the same ID arriving with the same payload will display the existing receipt. If the payload differs, a conflict is returned, allowing the app to review the discrepancy.
It is essential to thoroughly test the lost acknowledgement feature. To complete a sale offline, the device should be disconnected, and the server should commit the transaction. Then, simulate a dropped response by disconnecting the device again. Restart the app and retry the pending sale. Verify that the receipt number remains unchanged, and inventory is moved exactly once. In the event of a timeout, treat it as an unknown outcome and handle it accordingly.
By implementing a stable ID system and ensuring that the server and client can handle retries reliably, retailers can avoid the complications of duplicate POS sales when offline. This approach not only simplifies the recovery process for customers but also maintains accurate inventory levels throughout the sales process.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.