How to redirect user from one server to another server

Actually google or Facebook whatever the company it is, I know that all those company has different server in each country . Each user accessing their server from each country will be redirected to the server they have in the same country. is there any Middleware server or something to redirect user to server of the country user try to access the server from ? Can you please tell me if I have two node server and if the load in a server is high, How can i redirect the user to another server

For load, it’s called a load balancer, you put another server in front of other servers, and all requests hit the load balancer, which decides which server to use. NGINX is commonly used: here is the config for a simple load balancer: https://www.nginx.com/resources/wiki/start/topics/examples/loadbalanceexample/.

For location, location-based DNS, so a request is made, the DNS lookup is made, and it returns the location of a [hopefully] geographically-close load balancer. Anycast for example. This leads to CDNs for storing content in geographically-close locations.

SaaS/IaaS providers normally offer both as part of their packages (AWS, Azure, Google, etc).

3 Likes

I am good at react mongodb graphQl Node.js.
I developed one project using react.js mongodb and node.js . But I am confused whether I have to apply for full-stack or front-end engineer.
if I only write the code for fulfilling the request from client, I can write that code for that. But I am really afraid to apply for full-stack developer!. Because if server crash because of more load ,it will be problem
I know express Framework , Creating middleware and all the thing I learn from freecodecamp challenges! Do you think this is enough to work as a full-stack developer.
I have one more doubt. we can have many server to fulfill the request from client.
This server is fetching data from data base! So can this data base have multiple server?

Do you have thousands of users all hitting your server in a short period of time? Can you definitely say that your app is slow due to distance for the big group of users you have on the other side of the world and you need to optimise that? Are you a global company with loads of customers and your bottom line depends on you building your own location-specific infrastructure? I’m going to guess no and no and no. So do you really need to build complex and expensive infrastructure that sits on top of your app?

Knowing how to do it is obviously useful information, but these are things you can pay some money to the provider you use and they will do it for you.

Yes, this is called scaling. Again, knowing how to do this is a very useful skill to have, but

Maybe as a very junior developer, not much will be expected of you 🤷 You have very, very little experience, so meter your expectations – learn everything you can, it will all be valuable, but no-one hiring will expect you to be building production-level things. If the server falls over under heavy load there really should be no way you’re touching it

1 Like

Thank you for finding time to replay back

Since your question now has valid answers (load balancer, nginx, dns routing with aws, etc) I may also add my two cents:

A CDN, it allows your static assets or cached static copies of your site to be stored in different locations across the world that get “hit” once a user requests your page; thus choosing the one closest to them and helping you reduce the data transfer costs.

As for the original question, I also think that, depending on your project, a load balancer might help you scale it horizontally. We’re in 2019 and you no longer need to be a DevOps superhero because most VPS services simplify that for you.

1 Like