Offline-first and sync

Offline Protocol vs Firebase offline persistence

Firebase offline persistence lets an app read, write, listen to and query a local cache of the Cloud Firestore data it is using, then synchronizes local changes with the Firestore backend when the device is back online, with last write wins for several changes to the same document. Every change still travels through Google's servers, so two phones in the same room only see each other's edits once both are online. Offline Protocol lets nearby devices exchange messages and merge shared documents with each other directly over Bluetooth LE. Firestore is the managed backend database; Offline Protocol covers coordination between devices, and the two can run in the same app.

TL;DR

Firestore's offline cache keeps each user working through short gaps, but changes reach other devices only through the backend, so two phones side by side without internet never see each other's edits. Offline Protocol lets nearby devices exchange changes directly over Bluetooth LE, with local traffic never metered. A common split keeps Firestore as the system of record.

Learning objectives

After reading this article you will be able to:

  • Explain what Firestore's offline persistence does and does not do while a device is offline
  • Compare Firestore and Offline Protocol on the path of a change, conflicts and billing
  • Decide when to use Firestore, Offline Protocol, or both

Firebase offline persistence features and limits

Cloud Firestore’s offline persistence caches a copy of the data the app is actively using. While the device is offline the app can write, read, listen to and query that cached data, and listeners fire when the cached data changes. When the device comes back online, Firestore synchronizes the app’s local changes with the Firestore backend. For several changes to the same document, Firebase’s documentation says the last write wins.

As of October 2026, the documentation sets these limits and defaults:

  • Offline persistence is supported only in Android, Apple and web apps. It is on by default on Android and Apple platforms and off by default on the web.
  • The cache covers documents the app has received. A query for a collection with nothing cached returns an empty result, and fetching a single uncached document returns an error.
  • The default cache size threshold on Android and Apple platforms is 100 MB, after which Firestore cleans up older, unused documents.
  • Transactions fail when the client is offline. Batched writes still execute.

Firebase’s Realtime Database has a similar model: with disk persistence enabled, cached data stays available and queued writes are sent when the connection returns. Its documentation notes that transactions made offline are queued but not persisted across app restarts.

Offline Protocol device-to-device sync

Offline Protocol is a mesh SDK inside the app on each device. Devices discover each other over Bluetooth LE and exchange messages and replicated documents inside MLS-encrypted sessions or groups. Each device edits its own copy of a document and the copies merge by fixed rules when the devices reconnect: last writer wins per map key, concurrent list insertions are kept, text merges by character, and counters add up. In version 0.30.0 the React Native package runs in native iOS and Android builds, including Expo development builds, but not in Expo Go or a browser.

It holds no hosted copy of your data. Your backend, which can be Firestore, stays the system of record.

Firebase offline persistence vs Offline Protocol

The main difference is where the primary copy lives and the path a change takes: Firestore keeps it on the backend and sends every change through it, while Offline Protocol keeps it on the devices and lets them exchange changes directly.

Firebase offline persistenceOffline Protocol
Where the primary copy livesOn the Firestore backend; the device holds a cacheOn the devices; the app sends records to its backend when it chooses
Path of a changeDevice to the Firestore backend, then to other devices’ cachesDevice to a nearby device over Bluetooth LE, or through a hosted relay when no local path exists
Two phones side by side, no internetEach works from its own cache; neither sees the other’s changesThey exchange changes directly
ConflictsLast write wins per documentFixed merge rule per collection type
QueriesFirestore queries, including on cached dataNone; documents are read as JSON
Access controlFirebase Security Rules on the backendMembership of an encrypted space; the app decides who may join
Platforms (as of October 2026)Offline persistence on Android, Apple and web appsReact Native on iOS and Android; Rust; Python on PyPI; Java on Maven Central; a C API through offline_protocol.h in the desktop archives; early native Swift and Android packages; a preview Flutter plugin, not on pub.dev yet

Firebase and Offline Protocol running costs

As of October 2026, Firebase has a no-cost Spark plan and a pay-as-you-go Blaze plan. Cloud Firestore’s Standard edition includes 1 GiB of stored data, 50,000 document reads, 20,000 writes and 20,000 deletes a day, and 10 GiB of outbound data a month at no cost; usage beyond that is billed at Google Cloud rates on Blaze. Firestore’s pricing page also notes that with offline persistence enabled, a listener that has been disconnected for more than 30 minutes is charged on reconnection as if it had issued a brand-new query.

Under this model every edit a crew member makes counts as a document write, and every colleague who needs to see it reads it from the backend, even when the two of them are standing in the same room. With Offline Protocol, traffic between devices over a local transport is never metered on any plan. The mesh SDK is free under AGPL-3.0-only when the app meets its obligations, and closed-source or App Store apps need the commercial license, which is annual with no published price. The optional hosted services (sign-in, the hosted relay, telemetry) run on plans from $0, with Pro at $99 a month and Scale at $499 a month.

Best fit for Firebase

Firestore is the better fit for most apps whose users are usually online and want a managed backend database, and its offline cache needs no extra code. Choose it if:

  • You want a managed backend database with queries, security rules and authentication, and your users are usually online.
  • Offline means short gaps for each user on their own, such as a lost signal on a train, rather than a group working together without a connection.
  • You also need the web, where Offline Protocol’s mesh SDK does not run.

Best fit for Offline Protocol

Offline Protocol fits when nearby devices must exchange changes directly while the backend is unreachable. Choose it if:

  • People working near each other must see each other’s changes while the backend is unreachable, such as a crew below deck on a ship or underground in a mine.
  • Handoffs and shared checklists between nearby devices should not each count as a backend write plus a read for every colleague.
  • Messages and shared state between devices need to be end-to-end encrypted with MLS.

Using Firebase with Offline Protocol

A common split keeps Firestore as the system of record and uses Offline Protocol for the time devices spend together without it. Devices exchange changes locally. When a device has the agreed result, the app writes it to Firestore; if the device is still offline, Firestore queues the write in its cache and synchronizes it when the connection returns. Decide which device writes each record to the backend, or make the write idempotent, so that several devices holding the same merged state do not each submit it.

Frequently asked questions

Can two phones running a Firestore app sync with each other without internet?

No. Firestore's offline persistence keeps each device's own cache usable and queues its writes. The writes reach other devices only after they sync with the Firestore backend.

Does Offline Protocol replace Firestore?

No. Offline Protocol has no hosted database, query engine or security rules for your data. It carries messages and shared documents between devices, and the app can write the results to Firestore when a connection exists.

Do Firestore transactions work offline?

No. Transactions fail when the client is offline, though batched writes still execute.

How big is the Firestore offline cache?

The default cache size threshold on Android and Apple platforms is 100 MB, after which Firestore cleans up older, unused documents.

Is Firestore offline persistence turned on by default?

It is on by default on Android and Apple platforms and off by default on the web. Offline persistence is supported only in Android, Apple and web apps.

Why can Firestore charge for reads when a device reconnects?

With offline persistence enabled, a listener that has been disconnected for more than 30 minutes is charged on reconnection as if it had issued a brand-new query.

Sources

Build it with Offline Protocol

The page on what the SDK handles splits the work between Offline Protocol and your application, including how a record reaches your existing backend after devices have handled it locally.

Read what the SDK handles