Here's what a typical application that adopted the client-server architecture looks like:
- A client-based frontend issues requests to a company backend server
- The company backend server accepts the request and hits a company DB
- A company DB fetches or manipulates the data (if necessary) and responds back to the backend server
- The server responds back to the frontend client that triggered the whole chain of events
But what if clients have their own DBs?
We have what seems to be a pretty unusual way of handing that. The key peculiarity is we don't have a separate backend layer
- A frontend client, a medical desktop app, issues a request to a DB with what we call an "app SQL" string. The DB-hosting machine would be typically stored in a server room in the same facility.
- The DB responds back with an SQL that matches the received "app SQL". There's a DB table for "app SQLs" with columns for names and actual SQL statements. Those statements may be simple SELECTs or procedure calls. Say, the frontend would call
SELECT * FROM APP_SQL WHERE NAME = 'GET_ACTIVE_SERVICES'and the DB would respond with a "DTO" whosetextfield would store this string:SELECT * FROM SERVICE WHERE active_status = 1. "App SQL" strings, e.g.GET_ACTIVE_SERVICES, are roughly similar to endpoints, that is they provide a layer of abstraction. A DB may wish to return a different SQL at some point, and the frontend wouldn't know. - The frontend, upon receiving the SQL, uses it to hit the DB again to actually get or modify the data it wants.
- The DB processes the request (fetches or modifies its data), responds back.
Sometimes, a frontend app skips the "app SQL" phase and hits the DB with an actual DQL/DML statement right away. Typically, it happens when it only needs to perform a trivial SELECT/UPDATE/DELETE
It seems wrong. The DB effectively doubles as a backend server. You should see its procedures: complex walls of imperative logic with ifs, cases, and loops. SQL was never designed for that. It was designed to efficiently (and declaratively) fetch and manipulate data, and it's what it should be used for
But how are modern apps with client-based DBs designed instead?
In particular, where should the backend be? If it starts up along with the frontend application on the same machine, then it would likely increase the start-up time (what with the web server bootstrap, etc.). Then, would we have to set up a backend server on either a third machine or the same machine as the DB (so it's running non-stop alongside the DB)?