Call for Collaboration: Designing a Dgraph offline-first library

@pbassham, @maaft, @uncle_juniper, @marcown, @verneleem Let’s pick up this topic here to figure out how to better do a better offline first Dgraph client.

Some related posts:

Idea Phase

What we want to come up with eventually is a thin, embeddable, syncable client. From what we have so far:

  • The thin client should have a GraphQL endpoint
  • The thin client should have a local data store of some kind
  • The thin client should be able to two way sync data when online to the main Dgraph database whether by DQL or GraphQL.
  • This will very likely depend upon Query server timestamps or some other means of synce last sync meta data.
  • This thin client should be lite and embeddable. (With lowest memory consumption as possible)
  • This thin client should answer queries to best of ability when offline and fill in gaps with local cache when online.
  • This thin client needs to respect GraphQL authentication rules.
  • TBD: will users be authenticated based upon local machines local credentials with a generated JWT, or will users need to authenticate against an online service that responds with a JWT. This discussion will determine if users can authenticate when offline, or if can only use last online authenticated credentials for as long as they last. Maybe allow users to authenticate when online with a long lived JWT. What happens when user logs out, or a different user logs in from a different client on the same thin client.
  • In the sync process, it may be possible that the same node was updated by the client when offline and during that same offline time also by the Dgraph online db. The sync process needs to account for this. Storing mutations that a user performed while offline and then pushing those mutations in a sync when a user connects may be a possible solution, but not perfect, as data may have changed on the source of truth and the mutations no longer have the same effect, also the JWT may no longer be valid when reconnected if multiple users are using the same thin-client.

And that is the tip of the iceberg in my opinion.

Research Questions:

  • Are there any thin graph dbms like SQLite?
  • What about embeddable key-value stores or NoSQL?
  • Any references from the web with anyone that has made a GraphQL API client that syncs when online?

Possible Usable Tech

Client Language

  • WASM using Go
  • I am a Javascript developer myself, but this is open to suggestions.

Challenges:

  • Schema Updates between SSOT and client
  • Supporting the same queries and mutations supported on SSOT.
    Example: If when online the client requests queryContact(first: 100)... then when offline the client is qeuried for getContact(id: "0x1")..., This also applies to querying the thin client with filters and arguments not used when online. Apollo State Management cannot handle this very well, and any other local db will require a completely customized GraphQL layer in this thin client.
  • overcoming N+1 without a embeddable graph database. Is this even an issue with a local dbms since there are no network trips.

Really Advanced Stuff

  • It would be neat if after all of the above is figured out if local LAN clients could communicate with each other to fill in the data from other local thin clients when working together in an offline mode.
    Example: I was working on my Desktop and internet went out, and I am now on my laptop and my Desktop is on the same LAN, I make a query for data that is not locally, but can be obtained on the local network.

Back to work now on my current tasks at hand that I can do without needing an offline client at the moment.

5 Likes