- Deploying a server and client socket apps that simulates a tcp server that push a stream of data and client connects to it, created using nodejs.
- Creating a mongo relplicaset cluster, then integerating it with the client to store the streamed data into the mongo replset cluster
-
clone the repo
git clone git@github.com:amshrbo/deploying-nodejs-stack.git
-
Run the mongo replset cluster using instructions provided in this readme file
-
Run your client and server simulation using.
- make sure to have a .env file for storing your env vars required by the compose file
MONGO_UN=root_un MONGO_PW=root_pw DB_NAME=your_db_name MONGO_URI=mongodb://root_un:root_pw@mongo-primary,mongo-worker-1:27018,mongo-worker-2:27019/?replicaSet=bosta-rs-1
docker-compose up --build
- make sure to have a .env file for storing your env vars required by the compose file
-
Stop the client and server
docker-compose down
-
Stop the mongo replset cluster
cd replicaset_cluster docker-compose down # use -v of you wanna get ride of the persisted data
- It's a replicaSet cluster that consists of three nodes
- One primary that handels read and write operations
- The other 2 nodes are secondary that handels replication
- If the primary node fails for any specific reason, the two other nodes will vote for one of them to be the primary and the other to be the secondary (worker) node.
- The communication between nodes encrypted using keyfile auth provided by mongodb
- The mongodb documentation for replicaset
- An awesome playlist for mongodb in YouTube
- A YT video on how to spin up a mongo cluster using docker compose with a keyfile auth enabled
- Using keyfile auth as handling encrypted connection between the nodes
- How to enable communication between to compose files services
- For a higher performance you can add another replicaset cluster and setup sharding between them.