How does Firestore handle offline support?
Answer
Firestore has built-in offline persistence that allows apps to continue working without network connectivity. How it works: (1) Local cache — Firestore caches all queried data locally (IndexedDB on web, SQLite on mobile); (2) Offline reads — reads serve data from the local cache when offline, with no code changes needed; (3) Offline writes — writes go to the local cache with a pending status and sync to the server when reconnected; (4) Listen recovery — when reconnected, Firestore automatically syncs pending writes and fetches any changes that occurred while offline. Enabling offline persistence on web (disabled by default): enableIndexedDbPersistence(db) or enableMultiTabIndexedDbPersistence(db) for multi-tab support. On mobile (iOS/Android), it's enabled by default. The DocumentSnapshot.metadata.fromCache property indicates if data came from cache. DocumentSnapshot.metadata.hasPendingWrites indicates if local writes haven't synced yet. Design consideration: offline-capable apps must handle eventual consistency — display pending states in the UI.
Previous
How does Firebase Cloud Functions work and how do you trigger them?
Next
What is the difference between `set()`, `add()`, and `update()` in Firestore?