Using a Content Delivery Network (CDN) is one of the most effective ways of increasing the performance of delivering static content to your end users. CDNs operate by caching your static content in a globally distributed network and delivering that same content to your end users at the nearest point of presence. There is nothing magical about why CDNs are fast, they simply use the laws of physics. It takes a shorter amount of time to walk one block than it does one mile. Networks operate using the same principles.
While this is great for static content, the solution is not so simple when it comes to interacting with dynamic web applications, APIs and databases. In order to deliver your dynamic application to your end users at the nearest point of presence, you not only need to have a server running as close to the end user as possible, you also need an intelligent way to make sure that the user is routed to the correct server when they are making requests. FlexBalancers allow you to do just this.
Discussing the complexities of operating a globally distributed system is out of scope for the purpose of this article. Assuming that your application is able to operate in this fashion, then using a FlexBalancer will give you the ability to configure intelligent routing for your globally distributed application in minutes.
I set up a simple proof of concept using three Virtual Machines hosted on DigitalOcean in three separate geographic regions. One was in North America, one was in Europe, and the third was in Asia. Each of these virtual machines ran a simple application that would respond with which location the request was being served from. Once the machines were provisioned, I logged into PerfOps and created a new FlexBalancer.
Configuring the FlexBalancer to geographically balance your application is very simple. Using the Smart UI, all you need to do is create a new answer that will map a hostname or IP address to a specific geography. The Smart UI allows you to configure specific continents, regions, countries, and even cities when determining where to route your end users. The resulting rule set will look something like this:
Once you have configured your routing rules, you can save the configuration and it will take effect immediately. The last step of this configuration is to add a CNAME record to your application to point to your FlexBalancer. Once the DNS has propagated, all traffic will be routed correctly based on geography through your FlexBalancer to your specific application.
In my proof of concept, I was able to curl the FlexBalancer and see that traffic was being routed correctly based on the country that the request originated from.
In addition to providing a fast and simple way to configure geographic load balancing, PerfOps also provides us with a way to test out our configuration in real time using test servers in nearly every country around the globe.
This can be very useful in debugging your configuration, or giving you a sense of where you should potentially invest additional infrastructure if your user base is concentrated in a specific part of the world. I ran a latency test to see what the results of my new FlexBalancer configuration looked like.
The results aligned pretty well with my expectations. It looks like people in the Eastern US, Europe, and Southern Asia would receive the best results. This makes sense because my application servers were deployed to New York City, Frankfurt, and Singapore. I was able to drill into the specific results and get some additional insights.
For instance, I can see that the highest latency came from the following places.
Likewise, I could see that the lowest latency was in the following places
Based on these results, if I had customers in Australia, China, and Brazil then I may consider deploying some additional back-end infrastructure to those three locations to ensure that those customers have the best possible experience with my application.
In addition, once I have deployed this infrastructure, all I would need to do is add some additional answers to my FlexBalancer configuration in order to immediately begin serving those users with a server closer to them.