B4J Question Keeping data in sync between multiple servers

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am just trying to work out what the best way in doing the following..

I am designing some software (in B4J) which will run on the main server and on some sub servers.

The sub servers will host the users data which will be used with B4A/B4i. However to work out what server the user needs to connect to I am using a main server.

I could host everything on the one server, but if things get busy I want to spread it over a few servers.

Since the B4A/B4i app needs to login to both servers, I need to keep all servers in sync with the user logins.

For Example:
User connects to main server and sends login.
Main server replies with IP/Port to the app.
User now connects to the sub server and sends the same login details.
User can now access the files.

If the user changes there login details on the sub server I need to forward that login to the main server and the other sub servers. There could be 4-5 sub servers.

I need both main and sub servers to keep the login in sync.

I was looking though the CloudKVS - synchronized key / value store tutorial. - https://www.b4x.com/android/forum/threads/b4x-cloudkvs-synchronized-key-value-store.63536/#content

Would this be the best way in keeping the login details in sync? Or is there a better way ?

I am only wanting to keep the B4J apps in sync on the server and not the B4A/B4i apps since the B4A/B4i apps will check the server if the login is valid or not.

I am planning on using WebSockets or MQTT to send the data to/from the B4A/B4i apps to the servers.

So, the data I am wanting to keep in sync is the login data between the servers only.

Also, if the login data got sent to the other server (the user changes the login) will this trigger anything on the other server to notify that server the value was updated or does it do it silently in the background.

Can the data be encrypted with the CloudKVS? I noticed with the KeyValueStore 2 it allows messages to be encrypted. Is this the same with the CloudKVS?

https://www.b4x.com/android/forum/threads/b4x-keyvaluestore-2-simple-powerful-local-datastore.63633/
 

udg

Expert
Licensed User
Longtime User
Hi,
in a similar scenario we used what we call a dispatcher. It is a module which receives the first loging attempt made up of credentials along with a special code.
The dispatcher looks up the special code in a table where it finds the server and app that should serve the login and finally routes the request to that final destination.
This way we can change servers (and apps, eventually) at any time just updating the dispatcher's table.

In your case, you could decide that users using special code "s1" go directed to serverA while users using "s2" go to serverB and so on. On each server you manage only the credentials for the intended users, no needing any sync between servers. More, login data will be transmitted only once.

As an alternative, DBMSes have their sync methods, so you could rely on those.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I could host everything on the one server, but if things get busy I want to spread it over a few servers.
Make some tests. A single server can serve many users. It will be much simpler than implementing a synchronization solution.

How many users do you expect online at the some time?

If you really need to use multiple servers then you can use MongoDB.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
How many users do you expect online at the some time?
That's a good question.

My server will do the following..
1. Hardware out in the field will be connecting by TCP and sending an ASCII message to my server. There could be 200-300 message each day just from 1 hardware device.

(I have no control over the hardware, so it has to be an TCP connection)

At the start there could be 10-50 hardware devices for the first month and then a year later there could be 300-500+ devices going to connect.

2. B4A/B4i apps.. there could be many people logged in at a time. Each app will be controlling the hardware front point 1 above.
How many at a time is hard to tell. It could be 1 to 300-400 at a time. Would only be able to tell once I release my server but don't want to find out the hard way.

I plan on using a WebSocket connection if not a MQTT connection between my apps and server.

3. B4J will be acting as a webserver as well. So users need to be able to connect and control the devices though the web browser.

Would you say 1 server could handle:
500+ TCP connections
approx. 50-100 B4A/B4i connections (WebSocket or MQTT)
approx. 50 Webserver requests
all at the same time.
This is worse case I am planning.

Would something like the following handle the above ?
VPS Linux Server
1 Core
512MB ECC Memory
SSD Hard Drive

I also looked at MongoDB sometime ago, but forgot about it. I will read up on it.
 
Upvote 0
Top