Menu

What happens when an offline POS sale syncs twice?
📰

What happens when an offline POS sale syncs twice?

DEV Community: database·programmings 360·about 11 hours ago
#RczEKQam
#devtodatabase#devto#dev#sale#receipt
Reading 0:00
15s threshold

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

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.