Geo-DNS: Geographic DNS Routing with Cloudflare, AWS, Nginx

Introduction

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1284
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1240
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1032
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1104
  • image_website-_0.webp
    Website development for Red Pear
    553

Introduction

Imagine: your site is hosted in Europe, and users from Australia complain about slowness. While the DNS resolver returns an IP, 200 ms pass — this can be reduced to 50 ms with Geo-DNS (geographic routing). We have been configuring geographic and latency-based routing for years for projects ranging from startups to enterprise. Our engineers are Cloudflare and AWS certified, guaranteeing quality implementation. In this article — practical configurations for Cloudflare, AWS Route53, and Nginx GeoIP used in production. The setup pays for itself within 3–6 months by reducing TTFB by 40–60%, and savings on DNS traffic and CDN can reach hundreds of dollars per month. Get a consultation from a Geo-DNS engineer — we will evaluate your project.

Problems that Geo-DNS solves

Without Geo-DNS, users experience high latency — DNS queries travel to the parent DNS thousands of kilometers away, causing TTFB over 500 ms for remote regions, reducing conversion by 20%. Traffic is unevenly distributed to a single server, creating unnecessary load. When a data center in a region fails, users are left without service due to lack of failover. Geo-DNS addresses all this at the DNS resolution level, before the TCP connection is established.

Comparison of Geo-DNS providers

Provider Routing type Setup complexity Default TTL Failover Price
Cloudflare Load Balancing Geo + Latency Low 30-300 s Automatic, with health checks Paid (Pro+)
AWS Route53 Geolocation Geographic Medium 60 s (can be lower) Health checks, manual setup Paid per query
AWS Route53 Latency By latency Medium 60 s Automatic Paid per query
Nginx + GeoIP2 Geographic High N/A (application level) Depends on upstream Free (except database)

Cloudflare Load Balancing is 2x faster to configure than a custom Nginx setup, and TTFB is reduced by 50%.

How to choose between Cloudflare and AWS Route53?

Cloudflare Load Balancing is easier to set up and includes built-in monitoring. It is suitable for quick starts and small projects. AWS Route53 offers more flexibility with latency-based routing, allowing routing based on actual latency rather than geography. This is especially useful with heterogeneous network infrastructure. If you need full control, choose Nginx with GeoIP2, but manual updates of the MaxMind database are required.

Configuring Cloudflare Load Balancing (Geo-steering)

Cloudflare offers geo-steering out of the box. You specify pools for regions (e.g., ENAM — East Coast US, WEU — Western Europe), and the load balancer automatically directs traffic. Example configuration via API:

curl -X POST "https://api.cloudflare.com/client/v4/zones/{zone_id}/load_balancers" \ -H "Authorization: Bearer {token}" \ -H "Content-Type: application/json" \ --data '{ "name": "api.mysite.com", "fallback_pool": "us-east-1-pool", "default_pools": ["us-east-1-pool"], "region_pools": { "ENAM": ["us-east-1-pool"], "WNAM": ["us-west-2-pool"], "EEU": ["eu-central-1-pool"], "WEU": ["eu-west-1-pool"], "SEAS": ["ap-southeast-1-pool"], "NEAS": ["ap-northeast-1-pool"] }, "steering_policy": "geo", "session_affinity": "ip_cookie", "session_affinity_ttl": 300 }' 

Cloudflare documentation recommends using session affinity to maintain user sessions.

Configuring AWS Route53

Geolocation Routing

For precise routing by country or continent, use geolocation records. Example Terraform:

resource "aws_route53_record" "api_eu" { zone_id = var.zone_id name = "api.mysite.com" type = "A" set_identifier = "eu-users" geolocation_routing_policy { continent = "EU" } alias { name = aws_lb.eu_west_1.dns_name zone_id = aws_lb.eu_west_1.zone_id evaluate_target_health = true } } resource "aws_route53_record" "api_default" { zone_id = var.zone_id name = "api.mysite.com" type = "A" set_identifier = "default" geolocation_routing_policy { country = "*" } alias { name = aws_lb.us_east_1.dns_name zone_id = aws_lb.us_east_1.zone_id evaluate_target_health = true } } 

Why latency-based routing is better?

Latency-based routing considers not geographic distance but network latency — traffic from Europe might be faster to a data center in Virginia than in Frankfurt if backbones are congested. AWS automatically selects the fastest region. This approach gives more accurate distribution, especially for mobile users.

Example configuration:

resource "aws_route53_record" "api_latency_eu" { zone_id = var.zone_id name = "api.mysite.com" type = "A" set_identifier = "eu-west-1" latency_routing_policy { region = "eu-west-1" } alias { name = aws_lb.eu.dns_name zone_id = aws_lb.eu.zone_id evaluate_target_health = true } } 

Configuring Nginx with GeoIP2

If you want full control over routing, use Nginx with the geoip2 module and MaxMind GeoLite2 database. It is free and flexible.

Nginx configuration

Install the module and download the database (updated monthly). Then configure country mapping to backends:

load_module modules/ngx_http_geoip2_module.so; http { geoip2 /etc/nginx/geoip/GeoLite2-Country.mmdb { $geoip2_country_code country iso_code; $geoip2_country_name country names en; } map $geoip2_country_code $backend { default http://us-backend:3000; RU http://ru-backend:3000; UA http://eu-backend:3000; "~^(DE|AT|CH)" http://eu-backend:3000; "~^(GB|IE|FR)" http://eu-backend:3000; } server { listen 80; location / { proxy_pass $backend; proxy_set_header X-Country-Code $geoip2_country_code; proxy_set_header X-Real-IP $remote_addr; } } } 

You can also implement automatic redirect to a language version based on GeoIP.

TTL and DNS caching

Recommended TTL Scenario
30 s Critical services, instant failover
300 s (5 min) Universal value
3600 s (1 hour) Static resources

Cloudflare Load Balancing automatically reduces TTL during health check failover.

How Geo-DNS affects TTFB and Core Web Vitals?

Initial DNS latency directly impacts TTFB, which is a Core Web Vitals metric. Geo-DNS reduces TTFB by 40–60%, improving LCP and overall user experience. Google considers TTFB in ranking, so implementing Geo-DNS can indirectly boost search positions. This is especially important for sites with a global audience — a 100 ms reduction in TTFB can increase conversion by 5%.

Process for setting up Geo-DNS

We take a systematic approach:

  1. Audit the current DNS zone, analyze user geography (from Nginx logs or CDN).
  2. Design — select provider, pool scheme, TTL.
  3. Implementation — configure DNS via Terraform or Cloudflare API, set up health checks.
  4. Testing — verify from different points (via VPN, AWS Lightsail in various regions, dig from public DNS).
  5. Monitoring — set up alerts for latency changes or failures.

What is included in the result

  • A working Geo-DNS scheme with documentation.
  • Access to all providers (Cloudflare, AWS, control panel).
  • Team training: how to add new regions, change TTL.
  • Support for 14 days after implementation.

Our engineers hold Cloudflare and AWS certifications and have completed 50+ content delivery optimization projects. The setup pays for itself in 3–6 months by reducing TTFB by 40–60% and decreasing CDN traffic.

How to test Geo-DNS

Use dig with a specific resolver:

dig @8.8.8.8 api.mysite.com # USA dig @1.1.1.1 api.mysite.com # Europe dig @77.88.8.8 api.mysite.com # Russia 

If routing is configured correctly, the responses will differ in IP addresses.

Get a consultation on Geo-DNS — our engineers will help you choose the optimal routing scheme. Order an audit of your current DNS setup and find out how much you can save.