realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.47k stars 1.75k forks source link

Combining React Native and NodeJS in single fat client Android app using Realm DB #5103

Open aschrijver opened 7 years ago

aschrijver commented 7 years ago

I am investigating viable options for running NodeJS on Android and then combining React Native and NodeJS in single fat client Android app using Realm DB. The node side of the application is involved in complex decentralized P2P networking (the rationale for having node on android).

I know Realm supports NodeJS on a server, but does it also run the node version on an android device?


Background info

I am musing on a CQRS-style design that does not need node realm support currently:

realm-rn-node_arch-concept

Application UI (react):

Background Service (node):

DB


I thought this was a feasible design, but if there is no great overhead or large benefit to having realm-js on the node side I'd be glad to hear.

cmelchior commented 7 years ago

It isn't a combination that we officially support, nor have we heard of anyone else doing, so I'm afraid you will have to try for yourself.

One thing that concerns me a little is that if you run both Realm Java and Realm JS they will both try to load some of the same native code. This might or might not work. If you run them in different processes, then loading the native code shouldn't be an issue.

Unfortunately Realm Java is not fully process safe yet, and you might run into schema issues if you load the same Realm file in Java and Node in two different processes.

aschrijver commented 7 years ago

Thanks @cmelchior good points!

I expect this node-on-android use case to become more common as mobile devices get more powerful. I know of a number of people planning implementations.

The sharing of native code is something to avoid. An alternative in this design would be to have only a single realm package, either realm-js in RN or node, or a single realm-java bridging to both node and RN (where the bridges are also java).

I know this is a peculiar use case, but to a Realm expert what would seem the best choice in this? Personally I incline to realm-java as it provides the most stable foundation for the DB layer, I would think.

beeender commented 7 years ago

Some needed things for support realm-java and realm-js in one apk