#1 2017-09-29 00:24:24

Joker
Member
Registered: 2015-07-06
Posts: 15

Multiple Mormot based servers accessing the same SQLite database

Hi all,
I'm after some advice here.

I have multiple servers, one a rest server and the other a MVC web server, developed using Mormot, that I want to access the same SQLite database i.e. these servers are currently running two separate processes/executables.

1. Is it safe to just allow them both to access the same SQL database?
2. Should I combine the servers into a single process/executable?
3. Should I use some other method to access the database, or use some other database engine?

Thanks in advance.

Offline

#2 2017-09-29 06:50:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Multiple Mormot based servers accessing the same SQLite database

I understand that our MVC sample could be misleading.
As we wrote in the documentation, the MVC code uses directly the database, but it is not the best approach if you need a separated REST access.

No, it is not safe to share SQLite3 databases unless you add a lock (so performance will be lowered down in respect to "exclusive mode"), nor recommended, from the SOA design point of view.
A centric SQL database approach may sound handy, but it creates unmaintainable code, and real bottlenecks.

Today's idea of proper SOA writing is about MicroServices: small uncoupled services, with their own database.
Then you connect between the services using SOA interfaces.
In mORMot, you have interface-based services, with real-time callbacks over WebSockets, to make your servers communicate.

For your purpose (a REST server and a MVC server), it sounds obvious to me that the MVC server should be a client of the REST server, and that only the REST server should access the database.
This is a classical n-tier architecture: the MVC server is part of the presentation layer, and the REST server is the business layer, connecting to the database layer.
Your presentation layer should NOT access the database layer directly.

What I wrote above is about "logical" view.
If you use mORMot interfaces, you can run the REST and MVC server in separated executables (using WebSockets in-between), or in the same executable (using fast direct in-process interface calls).
For instance, you may write a regression test executable which runs all services locally, then have several stand-alone services/daemons for production.

Check our slides about modern SOA architecture.

Offline

#3 2017-09-29 10:11:15

oz
Member
Registered: 2015-09-02
Posts: 95

Re: Multiple Mormot based servers accessing the same SQLite database

Well explained! We are using the same approach over here.
Just a little question: is it save to let one TSQLRestServer instance be served by different THttpServers at the same time? Meaning one WebSocket Server for server-to-server communication and one http.sys server for an Admin-MVC Client frontend? I remember trying that some time ago and faced problems as far as i can remeber. But as far as I understand it should be possible by design.

Offline

Board footer

Powered by FluxBB