Setup a fixed IP like Shopify?

Please don't roast me. I did lots of research but obviously, I used the wrong keywords (I think I don't know the term I'm looking for). If I should post this question elsewhere, please do let me know. I posted this on StackOverflow but was advised to post it here.

I'm working on a SaaS application which helps people to create and host websites (Similar to Shopify, but non ecommerce). I would like to be able to give the client a fixed IP address that should never change, so that they can point their domains, sub-domains to it. This IP address should be the same for every client (Similar to how Shopify uses the exact same IP for every website). I think the term I looke for is load-balancing? But I'm not exactly sure how that works. Do I route all the traffic to 1 single instance that will do some routing to distribute traffic to other instances? What happens if this single instance fails? If I use several instances to handle the load then how do I have just a single fixed IP to route the traffic? I'm so confused.

I read many articles about L4, L7, DNS level load balancing but for some reason I still don't get the whole picture yet. If there is any resource, course out there that I should look into please let me know, I'm willing to learn just not sure where to start.


Solution 1:

The term you’re looking for is reverse proxy. What you do to achieve HA is that you set up a load balancer pair to listen to a common IP address, and then you use a protocol like carp or vrrp (for example using keepalived) that lets them agree on which node is active. Provided you keep all components and paths redundant enough you should be able to achieve very good uptime. In all likelihood you will want to add additional magic, like sharing some information about clients across the reverse proxy nodes in case you need session stickiness; but this is pretty much it in a nutshell.

Solution 2:

This is the wrong approach. AWS and other cloud providers do this, but they have IP pools to draw from. I can bet you don't.

The approach you want is to have users point their domains with an A record to your public IP. A single IP for all clients.

On your side you use hostname redirection to forward them to the appropriate appliacation/vm/container or whatever you're using.

Note. This works with HTTP for example, but won't work on other protocols that do not support hostnames.

As for load balancing. There are various options. You could use DNS, just have the A record point to multiple IPs, clients will round robin those. Or setup a virtual IP (VIP) with keepalived for example. Also give a look to HAProxy for a more involved and powerful solution.

There are two main ways to setup load balancers with high availability in mind. active/active active/passive. Spreading load between two proxies, or have one proxy in standby in case the active one fails.