Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A sample system demonstrating a highly scalable and fault tolerant application that implements a REST API for product ordering, by leveraging Node.js, MongoDB replica sets and NGINX as a load balancer, wrapped with Docker Compose.

License

NotificationsYou must be signed in to change notification settings

vbarzokas/scalable-rest-api-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A sample system demonstrating a highly scalable and fault tolerant application that implements a REST API for product ordering, by leveragingnode.js,mongoDB replica sets andnginx as a load balancer, wrapped withdocker-compose.

Architecture

system diagram

The system consists of 3 layers, all running within docker containers and being managed bydocker-compose as follows:

  • Node.js - Spawns a server that listens for incoming requests and serves a sample REST API; It can scale from 1 to many instances, depending on the load expected for increasing the system's capacity on delivering requests;
  • nginx - Acts as a reverse proxy and a load balancer towards the available Node.js servers. It uses its built-in mechanism for load balancing the requests to each available server, allowing the system to run efficiently.
  • MongoDB - The persistence layer consists of a MongoDB replica set with 1 primary node and 2 secondaries, which can add failover handling and backup advantages to the system.

Folder structure

  • /deploy - Contains all the different parts required to build and deploy the application withdocker-compose.
    • /deploy/api/src - Contains the source code of the Node.js servers, among with the REST API.
    • /deploy/db - Contains the required scripts for setting up a MongoDB replica set.
    • /deploy/nginx - Contains the required configuration for the nginx load balancer.
  • /test - Contains the automated E2E suite that tests all the functionalities of the REST API.

Running

Prerequisites
Steps
Automated
  • Just run the provided shell script:
    sh ./deploy.sh
Manually
  • Change the working directory todeploy folder.

  • (Optional) Modify the values of the required environmental variables via the provided.env file.

  • First build the required docker images with:

    docker-compose build
  • Then bring up the containers with:

    docker-compose up

    Notes:

    • Scaling: In order to scale the node.js servers, you can optionally append the flag--scale api-node=<NUMBER OF INSTANCES>, e.g. for a total of 5 instances use:
      docker-compose up --scale api-node=5
  • Wait until all the containers have started, usually takes about 20 seconds, but it depends on the resources of the host machine. After that the server should be accessible in port80 of your local machine.

Testing

Automated Testing

There is a set of E2E tests using Jest, that test all the functionalities of the REST API.

In order to run the tests follow these steps:

Automated
  • Just run the provided shell script:
    sh ./test.sh
Manually
  • Make sure that you have deployed the application and it is running as described inRunning section.
  • Change the working directory totest folder:
  • Install the requirednode.js modules by running:
    npm install
  • Execute the tests by running:
    npm run test

Manual Testing & REST API Documentation

The provided REST API has been documented using Swagger and it exposes the available documentation and a testing UI framework that can send HTTP requests, viahttp://localhost/api/docs.

About

A sample system demonstrating a highly scalable and fault tolerant application that implements a REST API for product ordering, by leveraging Node.js, MongoDB replica sets and NGINX as a load balancer, wrapped with Docker Compose.

Topics

Resources

License

Stars

Watchers

Forks

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp