Josh Choo's blog

Peculiarities of DNS address ordering and getaddrinfo

13 September 2021

When I played around with DNS load balancing in a Docker Compose environment, I initially thought that the Docker DNS server (127.0.0.11) performed round robin load balancing by shuffling the list of IP addresses when it resolves a host. I assumed that the client (i.e. NGINX in that example) would always select the first IP address from the resolved shuffled IP addresses. This approach means that the client wouldn't need to handle shuffling, caching, and iterating through the host's IP addresses, which achieves a form of "poor man's load balancing".

I shared my assumption with my manager and he offered a different view. He shared Daniel Stenberg's (creator of cURL) article on DNS round robin, which challenged my assumption and led me down a rabbit hole of digging through RFCs and source code. I gleaned the following learnings from Daniel's article:

References