Local-First: Building Offline-Ready Apps with SQLite
Connectivity is a feature, not a guarantee. For Insylink, our POS system, "offline mode" is the default state. We built a local-first architecture that prioritizes instant user feedback over server confirmation.
The Stack: Expo SQLite + Drizzle
We use Expo SQLite as our single source of truth. By pairing it with Drizzle ORM, we get type-safe SQL queries directly on the device. When a waiter punches in an order, it writes to SQLite immediately.
Sync Engine & Optimistic UI
We implemented a "Sync Queue" pattern. Every mutation is wrapped in a job that is:
- Applied optimistically to the UI.
- Persisted to a local
mutation_queuetable. - Processed by a background worker when the network is reachable.
Conflict Resolution
What happens if two devices edit the same order offline? We utilize a simplified CRDT (Conflict-free Replicated Data Type) approach. Instead of saving "User X set quantity to 5", we save "User X added 2 items". Commutative operations allow us to merge changes from multiple offline devices without data loss when they finally reconnect.