CraftResearch Tech Logo
CraftResearch.tech
LAB NOTE 03Published July 22, 2024 · 7 min readAuthor: Sakshyam Pokhrel

Offline-First Transaction Synchronization in Emerging Market Commerce

How to engineer commercial retail systems in developing markets like Nepal where internet connectivity fluctuates, without dropping customer billing transactions or corrupting inventory ledgers.

1. The Fallacy of Continuous Cloud Uptime

Standard SaaS retail software relies on continuous synchronous HTTP requests to cloud APIs. In markets like Nepal, where regional power cuts, ISP routing hiccups, or fiber cuts interrupt internet access, synchronous cloud POS systems grind business to a halt.

An offline-first architecture treats local device storage as the primary authority during sales transactions. The cloud is treated as an asynchronous replication target rather than a synchronous dependency.

2. Reconciling Distributed State Deterministically

To prevent duplicate invoice numbers and stock discrepancies across multiple checkout registers, we implement monotonic sequence allocation and append-only event sourcing on local SQLite engines:

  • Local Event Sourcing: Every bill creation and stock decrement is written as an immutable append-only event locally.
  • Idempotent Sync Queue: A background daemon batches uncommitted events and syncs with PostgreSQL using unique idempotency keys.
  • Deterministic Inventory Deduction: Stock deductions are ordered by timestamp with automatic low-stock notifications.
ABOUT THE AUTHOR

Sakshyam Pokhrel

Founder of CraftResearch Tech. Building digital infrastructure for Nepal and global markets.

pokhrel.tech ↗
View Nepal POS System