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.…