Skip to main content

Posts

Showing posts with the label System Design

Implementing load balancing with HAProxy in Node.js apps

What is a load balancer? Load balancers distribute incoming client requests to computing resources such as application servers and databases. In each case, the load balancer returns the response from the computing resource to the appropriate client. Why use a load balancer? Preventing requests from going to unhealthy servers Preventing overloading resources Helping to eliminate a single point of failure This introduction is enough to get started. For this tutorial, we are going to use  HAProxy  which is a free,  very  fast, and reliable solution offering  high availability ,  load balancing , and proxying for TCP and HTTP-based applications. We are not going to create a Node.js application here. For this tutorial let’s say you have a node.js application up and running on localhost:3000 When c l ients hits the server on localhost:3000 the server returns the appropriate response. Now let's say if we start sending a lot of requests to this single server, the...

Setting up Nginx as a reverse proxy for Node.js App

Okay.. but what is a reverse proxy? A reverse proxy is a web server that centralizes internal services and provides unified interfaces to the public. Requests from clients are forwarded to a server that can fulfill it before the reverse proxy returns the server’s response to the client. Nginx is a popular choice to use as a reverse proxy for your node.js application. Got it. Now let’s set up Nginx Let’s say your nodejs server is running locally on localhost:3000. We will set up Nginx to get the request and forward the request to our nodejs server. Ins t alling Nginx on ubuntu sudo apt-get update sudo apt-get install nginx Configure Nginx Disable the default, virtual host unlink /etc/nginx/sites-enabled/default 2. Create a configuration file cd /etc/nginx/sites-available sudo nano reverse-proxy.conf 3. Put the following content in the file server { listen 80; listen [::]:80; access_log /var/log/nginx/reverse-access.log; error_log /var/log/nginx/reverse-e...