I am trying to structure an application environment that utilizes resources offered by Firebase and Amazon Web Services (AWS).
Firebase takes care of the front end (client side logic) by providing a database and a hosting service for a web application (static javascript). AWS takes care of the server side logic, which is needed to carry out some tasks that cannot be done or exposed in the front end (examples: sending email, processing checkouts, connecting to third party APIs with private keys, etc), by providing a Node.js server running on Elastic Beanstalk.
I came up with the following logic:
- Node.js server listens to changes in database
- Web app updates database
- Node.js server detects a change in the database
- Node.js server processes task

I am covered when it comes to building the web application and having it linked with Firebase resources, but I am having some issues with the server side logic, especially since I am not heavily experienced with AWS or Node.js servers.
How can I make the Node.js server listen to the changes in database? meaning that it should always be running and listening for any triggers. The tasks should run in realtime, no queues, I am not interested in a cron-job-solution-like.
I do have a mechanism in mind to make sure that all the updates were indeed processed, let us say that for some reason the server didn't detect an update to the database, it was down for a couple of seconds or something, the server cannot skip any update. This can be easily solved by making the server listening to a separate database node that contains a list of all the triggers, and once processed it will remove that trigger. This is my current idea, can you verify that this approach is solid and won't cause any issues? are there any other ways to establish this all-triggers-must-be-processed checking mechanism?
As a code:
// import firebase
firebase.initializeApp({
apiKey: '<your-api-key>',
authDomain: '<your-auth-domain>',
databaseURL: '<your-database-url>',
serviceAccount: '<your-private-key>' // full access to db
});
firebase.database().ref('path/to/triggers').on('value', function(triggers) { // is .on('child_added', ..) better?
triggers.forEach(function(trigger) {
// run process
firebase.database().ref('path/to/triggers').child(trigger.key).remove();
});
});
What do I need to do exactly to keep this piece of code always running on the Node.js server? never disconnect or timeout, reconnect when there is a failure, and how can I establish that on Elastic Beanstalk?
The reason I am doing all of this, is that I don't want my front end/client to have any information about my backend, I cannot afford having any manipulation by the user, just in case you were wondering why not use an http trigger from the client side.
Overall, does this approach makes sense? I am a heading to the right direction with this?