If you search for apple.com from your browser, you'd notice that the site asks you to confirm your location and redirects you to the region-specific website.
When you are hosting an application that serves users globally, the users trying to access your application who are far away from the region(s) in which you published your application may experience higher latency or loading time.
So in order to reduce the latency, some websites directly redirect you to your region-based version of the site and give content (country's currency, special offers, etc.) as per your location.
This process is called Geo IP-based redirection. It detects the visitor's location from their IP address by matching it against a database of IPs and locations. It is one of the ways to reduce latency.
Let's learn how to enable regional-based routing for a website hosted on AWS so that your global users can experience low latency.
We will be using AWS Global accelerator for this purpose. Route 53 can also be used for the same.
1. Create public VPCs and instances.
Start by creating two VPCs - one in the US and one in the EU so that we can create EC2 instances in these regions and host our sample website in them.
2. Install a web server.
Follow the tutorial here and set up web servers in both instances. You can even automate it using tools like Ansible to save time.
Once you set up a web server, change some files of the web server in both of your instances so that you can understand which region it belongs to, for differentiating when we try to reach it later.
- US version
- EU version
3. Set up Load balancers (Optional).
Load balancers help us to redirect traffic to our instances. It will help prevent server overload and improve the availability of your website. This step is not necessary for our purpose here as there is not a lot of traffic coming into our websites.
4. Set up AWS Global Accelerator
AWS Global Accelerator helps you to improve the performance of your applications for local and global users.
It provides you with static IP addresses which serve as single fixed entry points for your clients. This means that it allocates IP addresses and associates them to the regional endpoints which you specify (Here, the public IP address of EC2 instances).
Let's move ahead and set up Global accelerator.
- First, you configure the listeners to identify which ports you want to listen to.
- Now set up endpoint groups and specify the amount of traffic you want to redirect.
- Next, we define the endpoints (Public IP addresses of EC2 instances) that we want to reach within each endpoint group.
Great! That creates our Global accelerator.
Now, when you try to access the endpoint of the accelerator, you will be redirected to the nearest region in which your website is hosted according to your location.
This is one of the ways of setting up geo-based routing using accelerator.
Route 53 is another service using which we can accomplish the same. But unlike Global accelerator, with Route 53 you can use Geolocation Routing Policy to even direct traffic only to regions of your desire (eg: Indian IP addresses reaching US endpoints instead of EU even though EU is nearer).
Follow to keep posted on my updates.