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 in one local transaction. Keep that same ID through retries and app restarts.
Make the server retry-safe
Use a unique database constraint scoped to the store and client sale ID. Commit the sale and its stock movements together. When the same ID arrives with the same payload, return the existing receipt. If the payload differs, return a conflict so the app can surface it for review.
Test the lost acknowledgement
- Complete a sale offline.
- Reconnect and let the server commit it, then simulate a dropped response.
- Restart the app and retry the pending sale.
- Verify that the receipt number is unchanged and inventory moved exactly once.
Treat a timeout as an unknown outcome. A stable ID gives the client a way to recover the receipt without guessing what happened.
Top comments (0)