How do I set up global load balancing using Digital Ocean DNS and Nginx?

后端 未结 4 1197
悲哀的现实
悲哀的现实 2021-01-29 21:48

UPDATE: See the answer I\'ve provided below for the solution I eventually got set up on AWS.

I\'m currently experimenting w

4条回答
  •  生来不讨喜
    2021-01-29 22:51

    The Goal: Offer highly-available service to my users by routing all connections to the closest 'cluster' of servers in SFO, NYC, LON, and eventually Singapore.

    The global-balancing layer then routes the request to theleast connected server...

    If I'm reading your configuration correctly, you're actually proxying from your global balancers to the balancers at each region. This does not meet your goal of routing users to the nearest region.

    There are three ways that I know of to get what you're looking for:

    1. 30x Redirect
      Your global balancers receive the HTTP request and then redirect it to a server group in or near the region it thinks the request is coming from, based on IP address. This sounds like what you were trying to set up. This method has side effects for some applications, and also increases the time it takes for a user to get data since you're adding a ton of overhead. This only makes sense if the resources you're redirecting to are very large, and the local regional cluster will be able to serve much more efficiently.

    2. Anycast (taking advantage of BGP routing)
      This is what the big players like Akamai use for their CDN. Basically, there are multiple servers out on the internet with the exact same routable IP address. Suppose I have servers in several regions, and they have the IP address of 192.0.2.1. If I'm in the US and try to connect to 192.0.2.1, and someone is in Europe that tries to connect to 192.0.2.1, it's likely that we'll be routed to the nearest server. This uses the internet's own routing to find the best path (based on network conditions) for the traffic. Unfortunately, you can't just use this method. You need your own AS number, and physical hardware. If you find a VPS provider that lets you have a chunk of their Anycast block, let me know!

    3. Geo-DNS
      There are some DNS providers that provide a service often marketed as "Geo-DNS". They have a bunch of DNS servers hosted on anycast addresses which can route traffic to your nearest servers. If a client queries a European DNS server, it should return the address for your European region servers, vs. some in other regions. There are many variations on the Geo DNS services. Others simply maintain a geo-IP database and return the server for the region they think is closer, just like the redirect method but for DNS before the HTTP request is ever made. This is usually the good option, for price and ease of use.

    Do subsequent requests get routed to the same IP?

    Many load balancers have a "stickiness" option that says requests from the same network address should be routed to the same end server (provided that end server is still up and running).

    What about sessions?

    This is exactly why you would want that stickiness. When it comes to session data, you are going to have to find a way to keep all your servers up-to-date. Realistically, this isn't always guaranteed. How you handle it depends on your application. Can you keep a Redis instance or whatever out there for all your servers to reliably hit from around the world? Do you really need that session data in every region? Or can you have your main application servers dealing with session data in one location?

    Any DNS Examples?

    Post separate questions for these. Everyone's "successful setup" looks differently.

    What about SSL/TLS?

    If you're proxying data, only your global balancers need to handle HTTPS. If you're redirecting, then all the servers need to handle it.

提交回复
热议问题