I am building some web application using NodeJS. I deployed the application to AWS beanstalk web server and I decoupled some heavy duty tasks, And deployed the heavy tasks to different AWS beanstalk workers, The main web server is executing the worker with SQS (aws queue).
The main web server has a big DB layer to connect, get and save to the database. The workers do need some db actions, every worker type need different actions that already implemented in the DB layer of the main web server.
So I'm trying to find a way to use the DB layer of the web server without duplicate it in every worker type (that's what I'm doing now).
What I thought is to decouple the DB layer from the main application and to deploy it to a web server to it self, but that's looks like a waste because I don't need to listen to requests in DB layer all the time, I need some on demand actions.
I attached a picture of how it looks:
- number 1 the main server (with full db layer)
- number 2 the queue
- number 3 the workers. (with duplicated db actions)
Is there any good solution to it?