1. Introduction
When building a globally distributed application, one of the important challenges is routing users to the appropriate data center.
Imagine you are building a global e-commerce application like Walmart or Amazon. Your application serves customers from different geographical locations:
- India
- Europe
- United States
- Australia
To improve application performance and reduce network latency, you deploy your application in multiple geographical regions.
For example:
|
Region |
Data Center |
|
Asia |
Singapore |
|
Europe |
Frankfurt |
|
North America |
Virginia |
Now, consider a user accessing your application from India. Instead of routing the user to the US data center, wouldn't it be better to route the user to Singapore?
Similarly:
- Users from Germany should ideally be routed to Frankfurt.
- Users from the USA should ideally be routed to Virginia.
This is where GeoDNS (Geographical DNS) comes into the picture. GeoDNS is a DNS routing technique that returns different IP addresses for the same domain name based on the geographical location of the client.
Its primary objective is to route users to the nearest or most appropriate regional endpoint, improving application response time and availability.
2. Understanding the problem GeoDNS solves
Let's first understand what happens without GeoDNS. Suppose your application is deployed in three geographical regions:
- Singapore
- Frankfurt
- Virginia
However, your DNS configuration returns only one IP address for all users. For example, when you hit www.example.com, it return this IP Address 30.1.0.10.
Here, assume 30.1.0.10 represents the US data center. Regardless of whether users access the application from India, Germany, or the USA, they are all routed to the US data center.
This creates unnecessary network latency for users who are geographically far away. An illustrative comparison looks like below.
|
User Location |
Data Center |
Approximate Latency |
|
India |
Virginia |
250 ms |
|
Germany |
Virginia |
120 ms |
|
USA |
Virginia |
20 ms |
These latency numbers are illustrative and depend on network conditions. With GeoDNS, we can return different IP addresses depending on the geographical location of the user.
|
User Location |
Selected Data Center |
|
India |
Singapore |
|
Germany |
Frankfurt |
|
USA |
Virginia |
This allows users to connect to a geographically closer application deployment.
3. How does GeoDNS work?
Before understanding GeoDNS, let's briefly understand DNS. DNS stands for Domain Name System.
When a user enters a domain name such as `www.example.com`, the browser needs to resolve that domain name into an IP address before establishing a connection with the server.
A simplified DNS resolution flow:
- The browser checks its local DNS cache.
- If the entry is unavailable, it queries the configured DNS resolver.
- The resolver obtains the answer from the authoritative DNS infrastructure, if necessary.
- The resolved IP address is returned to the browser.
- The browser establishes a connection with the returned IP address.
GeoDNS adds geographical intelligence to the authoritative DNS response. Instead of returning the same IP address to everyone, it returns an IP address based on the client's approximate geographical location.
Example
Suppose we configure the following DNS records:
|
Domain |
Region |
IP Address |
|
www.example.com |
Asia |
10.1.0.10 |
|
www.example.com |
Europe |
20.1.0.10 |
|
www.example.com |
North America |
30.1.0.10 |
Now consider three users:
User 1: India
- User opens www.example.com.
- A DNS query reaches the authoritative GeoDNS service.
- GeoDNS identifies the approximate location as India.
- It selects the Asia endpoint.
- It returns 10.1.0.10.
User 2: Germany
- User opens www.example.com.
- GeoDNS identifies the approximate location as Germany.
- It selects the Europe endpoint.
- It returns 20.1.0.10.
User 3: USA
- User opens www.example.com.
- GeoDNS identifies the approximate location as USA.
- It selects the North America endpoint.
- It returns 30.1.0.10.
GeoDNS identifies whether a DNS request is coming from India, the USA, Germany, etc., primarily by looking up the source IP address of the DNS query in an IP Geolocation Database.
An important point: GeoDNS does not forward HTTP requests to the selected server. It only returns the appropriate DNS response. The browser subsequently connects to the returned IP address.
4. How does GeoDNS know the client's geographical location?
This is an interesting question. DNS fundamentally works with domain names and IP addresses. An IP address does not directly contain geographical information.
So, how does GeoDNS determine whether a client is located in India, Germany, or the USA? The answer is IP Geolocation Databases.
GeoDNS providers maintain or use databases that map IP address ranges to approximate geographical locations.
For example:
|
IP address range |
Country |
Region |
City |
|
Illustrative range A |
India |
Karnataka |
Bangalore |
|
Illustrative range B |
Singapore |
Singapore |
Singapore |
|
Illustrative range C |
USA |
Virginia |
Ashburn |
These databases are built and updated using information from:
- Regional Internet Registries (RIRs).
- Internet Service Providers (ISPs).
- Network routing information.
- Commercial IP geolocation providers.
- Network operator updates.
When a DNS query arrives, GeoDNS can use the source IP address of the DNS resolver to estimate the client's location.
However, there is an important limitation.
5. How does GeoDNS know the geographical location of hosted servers?
This is another important question. We know how GeoDNS identifies the client's approximate location.
But how does it know where our application servers or data centers are located?
Does it automatically discover the location from the server IP address?
Generally, no.
The application or infrastructure team is responsible for configuring the geographical location of each regional endpoint when setting up GeoDNS.
Let's understand this with an example. Imagine your application is deployed in three AWS regions.
|
AWS region |
Geographical location |
Regional endpoint |
|
ap-southeast-1 |
Singapore |
Singapore Load Balancer |
|
eu-central-1 |
Frankfurt, Germany |
Frankfurt Load Balancer |
|
us-east-1 |
Virginia, USA |
Virginia Load Balancer |
Each region has its own regional load balancer that distributes traffic among application servers deployed in that region. The infrastructure team configures these regional endpoints in the GeoDNS service.
For example:
|
Domain |
Configured Location |
Regional endpoint |
|
www.example.com |
Asia |
Singapore Load Balancer |
|
www.example.com |
Europe |
Frankfurt Load Balancer |
|
www.example.com |
North America |
Virginia Load Balancer |
When a DNS query arrives:
- GeoDNS identifies the approximate client location.
- It checks the configured geographical locations of the regional endpoints.
- It applies the configured routing policy.
- It returns the appropriate regional endpoint.
The important distinction is:
- Client location identification: Handled by the GeoDNS provider.
- Regional endpoint location configuration: Handled by the application/infrastructure team.
- Endpoint selection: Handled by the GeoDNS routing policy.
6. End-to-end GeoDNS architecture
Let's combine everything we have learned. Imagine the following architecture:
Application infrastructure
- Singapore: Application servers + Regional Load Balancer.
- Frankfurt: Application servers + Regional Load Balancer.
- Virginia: Application servers + Regional Load Balancer.
GeoDNS configuration
The infrastructure team configures the regional endpoints and their geographical locations.
Request flow
- A user from India opens www.example.com.
- The browser initiates DNS resolution.
- The DNS resolver forwards the query to the authoritative DNS service.
- GeoDNS determines the approximate geographical location of the client using IP geolocation information or ECS.
- GeoDNS checks the configured regional endpoints.
- It selects the Singapore regional load balancer.
- The Singapore endpoint is returned as the DNS response.
- The browser connects to the Singapore load balancer.
- The regional load balancer forwards the request to an available application server.
This architecture allows global traffic distribution while keeping regional application traffic independently managed.
7. GeoDNS and Regional Load Balancers
An important system design concept is understanding the difference between global and regional load balancing. GeoDNS and regional load balancers solve two different problems.
GeoDNS: Global traffic distribution
It decides which geographical region should receive the request.
For example:
- India → Singapore.
- Germany → Frankfurt.
- USA → Virginia.
Regional Load Balancer: Traffic distribution within a region
Once the request reaches Singapore, the regional load balancer distributes traffic among application servers running in Singapore.
For example:
- Application Server 1.
- Application Server 2.
- Application Server 3.
The regional load balancer performs health checks and distributes incoming requests among healthy application instances. Therefore, the architecture looks like:
8. Important challenges with GeoDNS
GeoDNS provides geographical traffic distribution, but there are some important considerations.
8.1 DNS Caching and TTL
TTL stands for Time To Live. It specifies how long a DNS response can be cached.
Suppose:
- GeoDNS returns the Singapore endpoint.
- DNS TTL is configured as 300 seconds.
- The Singapore data center goes down.
The infrastructure team detects the failure and updates GeoDNS to return the Frankfurt endpoint. However, some clients may continue using the cached Singapore IP address until their DNS cache expires. This means DNS-based failover is not instantaneous.
A shorter TTL can reduce the potential delay, but it does not guarantee immediate failover because some resolvers and clients may cache DNS responses longer than the requested TTL.
8.2 Geographical location may not mean the lowest latency
Suppose an Indian user is geographically closer to Singapore.
However:
- Singapore servers are overloaded.
- Frankfurt servers have more available capacity.
- Network connectivity between India and Frankfurt is better.
In this case, routing to Singapore may not provide the best experience. Geographical routing does not necessarily guarantee the lowest network latency.
More advanced routing strategies consider:
- Network latency.
- Regional server health.
- Traffic load.
- Data center capacity.
- Availability.
8.3 Data consistency across regions
Suppose a user accesses the application through Singapore today and Virginia tomorrow. If both regions maintain independent databases, we need to consider data replication and consistency.
For example:
- A user updates their profile in Singapore.
- The user subsequently accesses the application through Virginia.
- The update might not yet be replicated to Virginia.
GeoDNS only routes requests. It does not replicate application data or guarantee consistency between databases. Therefore, multi-region application architecture requires a separate database replication and consistency strategy.
8.4 Uneven traffic distribution
Suppose 60% of your customers are located in India and Southeast Asia.
If all these users are routed to Singapore, that region may experience significantly more traffic than Frankfurt or Virginia.
Therefore, infrastructure teams must consider regional capacity and traffic distribution when designing the routing strategy.
9. GeoDNS vs other routing techniques
Several traffic routing techniques are commonly discussed in system design interviews.
|
Routing Technique |
How it works? |
|
Round Robin DNS |
Distributes DNS responses across multiple IP addresses |
|
GeoDNS |
Selects an endpoint based on geographical location |
|
Latency-based routing |
Selects an endpoint based on measured network latency |
|
Weighted routing |
Distributes traffic according to configured weights |
|
Global Load Balancer |
Applies global traffic management policies to select an appropriate endpoint |
GeoDNS vs Latency-based routing
Consider an Indian user. GeoDNS might route the user to Singapore because it is geographically closer.
However, latency-based routing might route the same user to Frankfurt if the measured network latency to Frankfurt is lower. Geographical proximity does not always mean network proximity.
10. Real-world implementations
Several cloud and DNS providers offer geographical routing capabilities.
10.1 AWS Route 53
Amazon Route 53 supports multiple routing policies, including:
- Simple routing.
- Weighted routing.
- Latency-based routing.
- Geolocation routing.
- Geoproximity routing.
- Failover routing.
- Multivalue answer routing.
Geolocation routing allows administrators to configure routing based on the geographical location of users. Geoproximity routing additionally supports bias adjustments to expand or shrink the geographical area served by an endpoint.
Documentation:
https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html
10.2 Cloudflare
Cloudflare provides load balancing and geographic traffic steering capabilities.
Documentation:
https://developers.cloudflare.com/load-balancing/
10.3 Azure Traffic Manager
Azure Traffic Manager supports geographical and performance-based DNS routing.
Documentation:
https://learn.microsoft.com/en-us/azure/traffic-manager/traffic-manager-routing-methods
11. GeoDNS in a System Design Interview
Consider this interview question. You are designing a global e-commerce application that serves customers from India, Europe, and the USA. How would you route users to the nearest data center?
A possible solution:
- Deploy application infrastructure in multiple geographical regions.
- Deploy a regional load balancer in each region.
- Configure GeoDNS with the geographical location of each regional endpoint.
- Use IP geolocation or ECS to estimate the client's location.
- Return the appropriate regional endpoint based on the configured routing policy.
- Configure regional health checks.
- Implement failover to another healthy region when a region becomes unavailable.
- Configure an appropriate DNS TTL.
- Implement database replication and consistency mechanisms across regions.
- Monitor regional traffic, latency, and availability.
A good system design answer should also discuss the limitations of DNS caching, geographical accuracy, and regional capacity.
12. Key Takeaways
- GeoDNS is a DNS-based geographical traffic routing technique.
- It returns different IP addresses for the same domain depending on the approximate client location.
- Client geographical location is generally identified using IP geolocation databases.
- The infrastructure team configures the geographical location of regional endpoints.
- Regional endpoints are typically regional load balancers.
- GeoDNS handles global traffic distribution.
- Regional load balancers distribute traffic within a region.
- DNS TTL and caching can delay failover.
- GeoDNS does not solve database replication or data consistency problems.
Remember this architecture:
Global Users → GeoDNS → Regional Load Balancer → Application Servers → Regional Database.
GeoDNS is one of the important building blocks for designing globally distributed applications.
You may like
Controlling Randomness in Java: Exploring the Role of Seeds in java.util.Random
Calculating initial capacity from expected size and load factor
A Beginner's Guide to UUID Types
Implementing LRU Cache in Java Using HashMap and Doubly Linked List

No comments:
Post a Comment