I have multiple client e-commerce web applications running on a single VM, each web application is a node.js express application.
The express web application communicates with the back end via API's to retrieve the content for the pages and the list of products etc. However, to make the product searches quicker we're currently using an in-memory database (lokijs) for all search to happen against, this works pretty well for us at the moment as the average product catalogue for each client is only around 80 items, we have a simple cron running within each clients web app to refresh the in-memory database with the latest product list via an API call.
Some of the downsides to this are since we're using PM2 to run each application in a 2 node cluster, the in-memory database has to be duplicated as you cannot share memory between the nodes, to ensure that in-memory databases stay in sync we use IPC's to pass messages to all processes within the cluster.
As we're bringing larger clients on-board with larger product catalogues we don't really want to be keeping duplicate in-memory databases for each child process.
The way our offering works is although the product catalogues aren't large per client, the search volume is quite large, so a client with 80 items may still get 1000's of searches a day.
I had a couple of options in mind, however unsure what would be the best:
Option 1 - Single global elasticsearch cluster
I have spoken to and thought about using elasticsearch and then point every single client web application to a single global elasticsearch cluster to perform product searches against, this way we can use events to keep the elasticsearch database up to date in real time.
However, i don't know how this will perform as we scale up, i don't want elasticsearch to become a bottleneck
Option 2 - Local nosql database
The second option was to simply replace the use of lokijs as the in-memory database and have a shared nosql database (such as mongo) for each VM, all the web apps then use the local database for queries, each web app is still responsible for updating the product catalogue for their own store. Then as we add more VM's each VM will have it's own local database for any apps running on there to use
We are heavy users of faceted search, and aggregations on facets to get counts for the facets