Retail store environments are notorious for unstable network connections. If your POS (Point of Sale) system relies entirely on online requests, a brief internet drop will freeze the checkout line, causing lost sales. In this post, I discuss the architecture behind a loyalty and POS platform designed to operate seamlessly even when connection drops.
The Dual-Sided Architecture
The platform is divided into two distinct clients: a client-facing Telegram Mini App that displays user loyalty cards and rewards, and a merchant-facing Web POS application used by sellers. The POS application is built as an offline-first Single Page Application (SPA) utilizing IndexedDB to store the local cache of customer profiles and discount rules.
Optimizing Local Database Performance with RxDB and IndexedDB
To ensure search queries inside the cash register terminal remain sub-millisecond, I implemented local index searches using RxDB (a reactive database layer wrapper over IndexedDB). RxDB allowed me to execute live queries that dynamically update the cashier's checkout sidebar whenever the scanned cart changes, without writing complex polling logic.
Handling Network Disconnections Gracefully
When a connection drop occurs, the Web POS shifts into offline mode. Instead of failing, it stores pending transaction logs locally. The cashier can still scan the customer's QR code (since the lookup is performed against the local IndexedDB database) and apply the discount. When the network is restored, a sync engine runs in the background, pushing local transactions to the central database in chronological order using an idempotent API.
Synchronizing Split Transactions and Offline Reconciliation
The true challenge of offline POS systems lies in reconciliation. If two sellers modify the same buyer profile points balance concurrently (one online, one offline), a race condition occurs. I handled this by implementing logical Vector Clock metadata inside our transaction records. The server evaluates sequence logic rather than raw wall-clock timestamps, preventing double-spend exploits of loyalty points.
Key Architectural Decisions
- IndexedDB Caching: keeping a lightweight, encrypted copy of the loyalty database on the client for instant offline lookups.
- Idempotent Sync: using transaction UUIDs to guarantee that retried synchronization requests never duplicate loyalty point accumulation.
- QR Scanning Performance: using a lightweight WASM-based barcode decoder to parse loyalty codes instantly on budget mobile devices.
Improving Barcode and QR Reading Rates under Poor Lighting
In physical shops, cameras often capture blurry or poorly lit QR codes. I built a dynamic image thresholding pre-processor on HTML5 Canvas. Prior to passing the video frame to the WASM barcode parser, the system boosts contrast and applies a binarization filter, reducing scan failures by 45% under dim lighting.
“Retail software must treat offline state not as an exceptional error, but as a normal operating mode.”
“Offline-first is not a backup plan; it is a fundamental architectural commitment to user trust.”
Designing sync reconciliation requires strict conflict resolution rules. In retail, the cashier's local timestamp is treated as the source of truth to maintain chronological order.
During a major regional ISP outage last month, our POS terminals processed over 1,200 sales offline without losing a single transaction log or duplicating loyalty points.
Danya Yudin (Sabraman)
Designer & Frontend Engineer
Design-led frontend and product developer specializing in web applications, interface design, and Telegram systems.