← News

· 10 views

How to keep a sale from deducting stock twice

An unstable connection can cause the same sale to be sent more than once.

Assign a unique identifier when creating each operation. The server can use it to recognize a retry and return the result it already saved.

Test a case where a sale is saved but the phone loses its connection before receiving confirmation. Retrying should deduct stock only once.

Worked example

Start with 10 items, sell 3 and simulate a disconnect between saving and returning the response. Retry with the same identifier. Then sell another 3 with a new identifier.

How to test it

Compare stock with the operation log. The order record and stock deduction should commit together.

Expected result

Stock is 7 after the first sale and 4 after the second. The log shows two operations even though the first was sent twice.

WhatsApp