Skip to content

Clustering



The SAMA server supports clustering out of the box.
You can run a cluster across separate physical servers or on the same machine with multiple SAMA-server instances.

  1. Run dependent services:

    Use the following command to start MongoDB, Minio, and Redis:

    Terminal window
    docker-compose up
  2. Run multiple SAMA-server instances:

    • Option 1: Open multiple terminal consoles, run npm run start in each, and set the APP_PORT environment variable to a different value for each instance.
    • Option 2: Remove the APP_PORT environment variable and run multiple nodes via PM2:
    Terminal window
    pm2 start pm2.config.cjs

    The number of instances is defined by the instances value in the pm2.config.cjs file.

  3. Set up Nginx balancer:

    1. Open nginx/default.conf and provide the IP addresses of all running nodes.
      If running locally, use your machine’s private IPs, not localhost or 127.0.0.1.
    2. Start the Nginx balancer:
    Terminal window
    docker-compose -f docker-compose-nginx-balancer.yml up --build
  4. Access the cluster:

    The cluster will be available on port 9000. Point your SAMA-client to this port for testing.