Using DNS to Gracefully Switch Network Services
Assume the service domain name is example.domain
, the original server IP is A
, and the new server IP is B
after migration or IP change. To keep users unaware, we can use DNS to gracefully switch network services.
- Original state:
example.domain
resolves to IPA
. - Transition state:
example.domain
resolves to both IPA
andB
. - New state:
example.domain
resolves to IPB
; IPA
is removed.
Note: When users receive two resolved addresses, the client picks one to connect to; if that fails, it tries the others, ensuring service availability.
Since DNS responses are cached, the transition state must last long enough for all caches to expire.
I’m migrating a DNS service, so I can accelerate the switch by adding “DNS rewrites” during the transition.
Rewrite rules for server A:
Rewrite rules for server B:
The expanded migration steps are:
- Original state:
example.domain
resolves to IPA
. - Transition state: in DNS
A
,example.domain
is rewritten toA
andB
; in DNSB
, it is rewritten toB
. - New state:
example.domain
resolves to IPB
; IPA
is removed.
Clients still querying DNS A
receive both addresses.
- With 50 % probability they pick DNS
A
. - With 50 % probability they switch to DNS
B
.- If DNS
B
fails, they fall back to DNSA
. - If DNS
B
is healthy, they see onlyB
and stay on DNSB
.
- If DNS
This gradually reduces load on DNS A
without abruptly terminating it, achieving a smoother migration.