offline-first-strategy
Installation
SKILL.md
Offline-First Strategy
Instructions
Mobile devices are flaky by nature. Treat the network as optional. Offline-first apps feel fast, survive tunnels and airplane mode, and reduce server load. The trick is picking the authoritative source per data kind and building a predictable read/write path around it.
1. Tiers of Cache
| Tier | Where | Lifespan | Example |
|---|---|---|---|
| L0: in-memory | app process | foreground session | current screen view model |
| L1: on-disk structured | SQLite, Realm, Core Data, Room, Drift, SQLDelight | persistent | lists, entities, search indices |
| L2: on-disk blob | file cache directory | purgeable | images, videos, exports |
| L3: secure | Keychain / Keystore | persistent, encrypted | tokens, keys |
| Remote | server | authoritative for shared data | transactional writes |
Pick tiers explicitly per data type; do not let a JSON in SharedPreferences grow into a database.