Skip to content

Add dnsResolver configuration option for randomized DNS load balancing#3577

Open
pavansai1 wants to merge 4 commits intoapple:mainfrom
pavansai1:random-DNS
Open

Add dnsResolver configuration option for randomized DNS load balancing#3577
pavansai1 wants to merge 4 commits intoapple:mainfrom
pavansai1:random-DNS

Conversation

@pavansai1
Copy link
Copy Markdown

Motivation:

When connecting to services with multiple DNS records (e.g. Kubernetes headless services), getaddrinfo returns addresses in a deterministic order, causing all connections to go to the same backend. SwiftNIO now provides a RandomizedDNSResolver that shuffles results.

Modifications:

Add a dnsResolver property to HTTPClient.Configuration with two options: .system (default, current behavior) and randomized (uses NIO's RandomizedDNSResolver to shuffle DNS results). Apply the resolver to ClientBootstrap during connection creation.

Result:

Users can opt into randomized DNS resolution by setting config.dnsResolver = .randomized, enabling load distribution across multiple backend IPs while preserving the default behavior.

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Apr 17, 2026
Copy link
Copy Markdown
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thank you @pavansai1!

@Lukasa Lukasa enabled auto-merge (squash) April 17, 2026 20:07
auto-merge was automatically disabled May 5, 2026 04:23

Head branch was pushed to by a user without write access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants