Call for Collaboration: Designing a Dgraph offline-first library

Suggestion: Replicate MongoDB Realm Sync API and use Realm databases.

Building a lite-version of the Dgraph database and keeping it up to date would be hard to maintain IMO. What makes sense to me is to use an existing database, and then build syncing middleware between that database and Dgraph.

Realm is an open-source database that is battle-tested, works in multiple environments (iOS/Swift, Java, Windows etc.) and has built in syncing logic. It’s designed to work with MongoDB Realm Sync which is basically just a middleware API between Realm instances and Mongo Atlas cloud database. You configure your client Realm db like this:

let configuration = AppConfiguration(
   baseURL: "https://realm.mongodb.com", // Custom base URL
   transport: nil, // Custom RLMNetworkTransportProtocol
   localAppName: "My App",
   localAppVersion: "3.14.159",
   defaultRequestTimeoutMS: 30000
)
let app = App(id: "my-realm-app-id", configuration: configuration)

DigitalOcean have replicated the AWS s3 API and provide the same service with a different pricing model. It works with existing AWS libraries. My thinking is that the solution to the problem could be a middleware API that receives data from Realm db instances by replicated the same endpoints as MongoDB Realm Sync, and then transforms that data into Dgraph transactions.

Then in your mobile client all you need to do is change your config to:

let configuration = AppConfiguration(
   baseURL: "https://realm.yourserver.com", // Host the middleware on your server
   transport: nil, // Custom RLMNetworkTransportProtocol
   localAppName: "My App",
   localAppVersion: "3.14.159",
   defaultRequestTimeoutMS: 30000
)
let app = App(id: "my-realm-app-id", configuration: configuration)
2 Likes

any one still considering such shennanegans?

i am neck deep in a so far rather successful dive into these waters… ping me if you’re interested.

headline:
idempotent op-logs with granular historic rollups
dexie - dgraph sync, done right.

3 Likes

2 Likes

Looks promising. What mobile DB would this work with? Is it open source?

1 Like

it will be open source, at least for non commercial usage

dexie uses indexdb, which is available for pwa apps on all major platforms.

not sure if i’ll get busy with native dbs, and ios vs android hooplah.
but if its mission critical for someone, we could consider collaborating.

1 Like

You would be stuck with javascript if your mindset is indeed a “library”.

I think more apt to consider a wasm instance running standard dgraph locally on the client. Then we are invoking networking via gRPC to hit the DQL endpoint on localhost or probably more practically simply target apollo-client or urql at the graphql endpoint also on localhost

This is in some sense similar to holochain’s paradigm (they are also using wasm)