The client–server contract: optimistic updates, offline and sync
A good app shows a change the moment the user taps, keeps working in a tunnel and agrees with her other devices once the signal is back. The phone's part is the mobile round's work; the product round asks for the server's side.
A salesperson's order book
A salesperson visits shops in villages with no phone signal. She writes each order in her notebook, numbered by her, and tells the shopkeeper "done" at once. In the evening she phones the office and reads the orders out, and the office reads back the line number each got in its daybook. Then she asks for "everything after line 1,042" and hears new prices and the products crossed out. If an order can't be filled, she rings the shop. If she's been away longer than the office keeps old pages, they send the whole price list.
The salesperson is the phone, her notebook its local store and queue of unsent changes, and the office is the server. Saying "done" at once is an optimistic update, and ringing the shop is its rollback when the server refuses. Her own order numbers are IDs the phone creates, so reading an order out twice can't make two. The daybook's line number is the sync token, a position in the server's list of changes, and the crossed-out products are tombstones, the records of deletes. Sending the whole price list is a full resync.