Offline-First Durable Objects / KV

Are there any examples of Workers KV and Durable Objects being used inside an offline-first app (an app that supports intermittent connections by storing offline actions and syncing them upon reconnections), as falls over as soon as you go offline.

Cloudflare would be really well positioned to offer a competitor to say PouchDB, AWS Amplify, Fauna, and MongoDB Realm for this.

However, that said, I imagine this would mostly just be about userland code, that builds on-top of either KV or Durable Objects, and works inside the workers and in the browser (and perhaps other runtimes) to allow easy syncing between the runtimes.

1 Like

A strategy could be :

Each message has a timestamp

Capture offline event
Disconnect & capture error & connection = null

Client writes messages
Store client messages in IndexedDB

Capture online event
Pull latest messages (history length depends on your need)
Send stored user messages (possibly with new send dates)
Clean IndexedDB

You can add flavor by storing received messages in IndexedDB so they are still accessible when refreshing the page when being offline

If you just need to store files offline, the Service worker File Cape API can do that for you. But it is limited in size (50MB). Whereas IndexedDB has a much larget limit (% of your disk, depends on browser, but expressed in GB/TB).

If it is offline first, CouchDB and PouchDB works like a charm.
I, for example only need the first load to be a blast, any sync can be done at the range of 1-2 seconds.