How can I load balance incoming emails across multiple servers using MX records?

Summary

Utilizing multiple MX records for load balancing incoming email offers a basic level of distribution but presents several challenges. The RFC specifies a round-robin approach for MX records with equal priority, however, sender-side caching, varied ISP behaviors, and uneven respect for multiple MX records by mail servers can lead to unpredictable and uneven load distribution. While suitable for small organizations as a free and readily available solution, experts and documentation recommend dedicated load balancers with health checks for more robust environments. Alternatives include using a single MX record with multiple A records or employing geo-location load balancing. Importantly, using MX records with different priorities configures failover, not load balancing. Security implications, particularly when using multiple A records, must also be considered.

Key findings

  • Basic Load Balancing: Multiple MX records with the same priority provide a basic means of load balancing.
  • Unpredictable Distribution: Sender-side caching, varied ISP behaviors, and mail server implementations can make load distribution unpredictable.
  • Limitations of DNS Load Balancing: DNS-based load balancing is limited by caching, lack of health checks, and uneven distribution.
  • Preferred Solutions: Dedicated load balancers with health checks are recommended for robust and reliable load balancing.
  • Failover vs. Load Balancing: MX records with different priorities configure failover, not load balancing.
  • Security Implications: Using multiple A records exposes potential security vulnerabilities.

Key considerations

  • ISP Variability: Be aware of how different ISPs handle multiple MX records, as behavior can vary.
  • Caching Effects: Understand how caching can affect load distribution and consider methods to mitigate its impact.
  • Server Health Monitoring: Implement server health monitoring for reliable load balancing, especially when using dedicated load balancers.
  • Alternative Configurations: Consider using a single MX record with multiple A records or geo-location load balancing for potential improvements.
  • Cost and Complexity: Weigh the cost and complexity of implementing dedicated load balancers against the benefits for your specific needs.
  • RFC Compliance: Ensure sending servers comply with RFC 5321 for random selection of MX records with equal priority.

What email marketers say
18Marketer opinions

Using multiple MX records to load balance incoming email involves trade-offs. While it's a valid strategy, especially for smaller organizations, DNS-based load balancing has limitations. The RFC specifies that servers should attempt connections in a round-robin fashion, but sender-side caching and varying ISP behaviors can make this unpredictable. Some mail servers might not respect multiple MX records equally, leading to uneven distribution. For robust environments, experts recommend using dedicated load balancers with health checks. Combining MX records with load balancers or using multiple A records pointing to different servers are also options. Furthermore, using MX records with different priorities act as failovers if the higher priority servers are unavailable. Consideration should also be given to security implications with multiple A records. Geo-location load balancing can also improve email delivery and performance.

Key opinions

  • Basic Load Balancing: Multiple MX records with the same priority is a valid strategy for basic load balancing.
  • Predictability Issues: Sender-side caching and varying ISP behaviors can make load distribution unpredictable.
  • Uneven Distribution: Not all mail servers respect multiple MX records equally, leading to uneven distribution.
  • Advanced Load Balancing: Dedicated load balancers with health checks are preferred for robust environments.
  • Failover Mechanism: MX records with different priorities serve as failovers if higher priority servers are unavailable.
  • Security Implications: Consider security implications when using multiple A records as bad actors can target specific servers.

Key considerations

  • Caching Issues: DNS round robin may be unreliable due to caching, causing unequal distribution.
  • Server Health: DNS-based load balancing doesn't actively monitor server health.
  • Implementation Complexity: Implementing a solution with load balancers adds complexity.
  • Cost: Hardware and software costs may increase with advanced solutions like load balancers.
  • Geo-Location: Consider geo-location load balancing for improved delivery and performance by directing email to the nearest server.
  • Alternative Configurations: Using a single MX record with multiple A records can force better round-robin distribution.
Marketer view

Marketer from Email Geeks clarifies that DNS does allow multiple A records for the same host, and provides <http://www.google.com|www.google.com> as an example.

November 2021 - Email Geeks
Marketer view

Email marketer from cPanel Forum warns that not all mail servers respect multiple MX records equally, and some might always try the first one they resolve. This can lead to uneven load distribution.

June 2023 - cPanel Forum
Marketer view

Email marketer from ServerFault responds that setting up multiple MX records with the same priority will load balance incoming email, however, some mail servers may only try the first one they resolve. Lower priority records provide redundancy if the primary mail server is unavailable.

February 2022 - ServerFault
Marketer view

Email marketer from EmailSecurityBlog responds that DNS round robin load balancing may not be reliable. Some mail servers may cache the IP address of the first server they connect to, causing unequal distribution. Other methods may be better.

May 2023 - EmailSecurityBlog
Marketer view

Marketer from Email Geeks suggests that DNS servers and resolvers' behavior influences load balancing, and to contact the provider if there are concerns.

October 2023 - Email Geeks
Marketer view

Email marketer from MXToolbox Forum responds that a good approach is to use multiple MX records pointing to load balancers. These load balancers then distribute traffic to the actual mail servers. This allows for better control and monitoring.

February 2024 - MXToolbox Forum
Marketer view

Marketer from Email Geeks confirms that using multiple email servers in MX with the same priority is a valid strategy for incoming load balancing.

June 2024 - Email Geeks
Marketer view

Marketer from Email Geeks shares a customer experience where ISPs tend to resolve to the same server initially with high probability, varying by ISP (Gmail, Microsoft, European).

July 2024 - Email Geeks
Marketer view

Email marketer from WebHostingTalk shares that geo-location load balancing can improve email delivery and performance. By directing email to the nearest server, response times are faster, and reliability is increased.

October 2024 - WebHostingTalk
Marketer view

Email marketer from StackOverflow explains that MX records with different priorities act as failovers. If the server with the highest priority is unavailable, the sending server will attempt delivery to the server with the next highest priority. Using same priority means servers will be chosen randomly.

June 2022 - StackOverflow
Marketer view

Email marketer from StackExchange suggests that using DNS for email load balancing has limitations. While it distributes the load, it doesn't actively monitor server health. Using a dedicated load balancer offers more control and monitoring capabilities.

August 2024 - StackExchange
Marketer view

Marketer from Email Geeks states DNS load balancing is basic, unsuitable for carrier-level, but free, readily available, and "good enough" for small organizations.

August 2022 - Email Geeks
Marketer view

Marketer from Email Geeks explains the security implications of using multiple A records, stating bad actors can target one, unlike using HAProxy. He also details how Gmail likely uses VIPs and a large server infrastructure.

May 2024 - Email Geeks
Marketer view

Marketer from Email Geeks warns about not using Cloudflare's RR hiding when using multiple A records, as each record needs to be resolvable to the actual destination IP.

April 2024 - Email Geeks
Marketer view

Email marketer from Reddit shares that using multiple MX records for load balancing is a basic method. It's simple to set up but doesn't provide sophisticated features like health checks or session persistence. It is also not immediate failover.

November 2022 - Reddit
Marketer view

Marketer from Email Geeks suggests that RFC says round robin, but sender-side caching makes it not consistently predictable.

January 2025 - Email Geeks
Marketer view

Marketer from Email Geeks suggests avoiding chance when load balancing and shares concerns around allowing direct access to all three servers. Suggests solutions such as HAProxy.

September 2022 - Email Geeks
Marketer view

Marketer from Email Geeks suggests using a single MX record pointing to a host with multiple A records (one for each server) to potentially force better round-robin distribution.

April 2022 - Email Geeks

What the experts say
2Expert opinions

Experts indicate that while MX records can facilitate basic load balancing, DNS-based methods possess limitations, notably caching issues and the absence of real-time server health monitoring. For robust environments, dedicated load balancers are preferred. MX records can also be configured for automatic failover in the event of server failures, providing redundancy but not load balancing.

Key opinions

  • Basic Load Balancing: MX records can be used for basic load balancing, but have limitations.
  • Limitations of DNS: DNS-based methods have limitations like caching issues and no real-time server health monitoring.
  • Preferred Solution: Dedicated load balancers are preferred for robust environments.
  • Failover Configuration: MX records can be configured for automatic failover, but this is not load balancing.

Key considerations

  • Caching Issues: DNS caching can lead to uneven load distribution.
  • Lack of Monitoring: DNS-based methods lack real-time server health monitoring.
  • Alternative Solutions: Consider using dedicated load balancers for more sophisticated load balancing.
  • Failover vs. Load Balancing: Understand the difference between configuring MX records for failover and for load balancing, as they serve different purposes.
Expert view

Expert from Word to the Wise explains how to configure your domains and MX records to automatically reroute mail in a failure. This article focuses on how to make your MX records failover, not for load balancing.

July 2023 - Word to the Wise
Expert view

Expert from Spam Resource explains that while MX records can be used for basic load balancing, DNS-based methods have limitations, particularly with caching. Load distribution might not be even, and it doesn't account for server health in real-time. More sophisticated solutions involving dedicated load balancers are usually preferred for robust environments.

March 2024 - Spam Resource

What the documentation says
5Technical articles

Technical documentation from Microsoft, DigitalOcean, RFC Editor, Exim Wiki, and PowerDNS collectively explains that incoming email can be load balanced using multiple MX records. MX records with the lowest preference number (highest priority) are attempted first. When multiple MX records share the same priority, SMTP clients and MTAs like Exim and PowerDNS should attempt connections in a random or arbitrary order to distribute the load. This behavior is outlined in RFC 5321.

Key findings

  • Priority Matters: MX records with lower preference numbers (higher priority) are tried first.
  • Same Priority Handling: When MX records have the same priority, servers should try them in a random/arbitrary order.
  • Load Distribution: Using multiple MX records with the same priority can distribute the incoming email load across multiple servers.
  • RFC Compliance: RFC 5321 recommends random order for MX records with equal preference.

Key considerations

  • Server Behavior: Ensure sending servers adhere to RFC 5321 and randomize MX record order with equal priority.
  • Testing: Test the MX record configuration to confirm that email load is being distributed as expected.
  • Priority Assignment: Carefully assign priorities to MX records to define failover behavior.
  • Algorithm Variability: Be aware that specific algorithms for randomized selection of servers may vary between MTAs.
Technical article

Documentation from Microsoft Learn explains that MX records with the lowest preference number (highest priority) are tried first. If multiple MX records have the same preference number, they are tried in an arbitrary order.

May 2022 - Microsoft Learn
Technical article

Documentation from Exim Wiki explains that Exim, a Mail Transfer Agent, tries MX records in order of preference. When multiple records have the same preference value, Exim randomizes the list before attempting delivery.

August 2023 - Exim Wiki
Technical article

Documentation from RFC Editor explains that when multiple MX records have the same preference value, the SMTP client SHOULD try them in a random order. This helps distribute the load across multiple mail servers.

November 2024 - RFC Editor
Technical article

Documentation from DigitalOcean explains that you can load balance incoming email by specifying multiple MX records with the same priority. This tells sending servers that they can try any of these servers to deliver the email.

February 2025 - DigitalOcean
Technical article

Documentation from PowerDNS shares that when mail servers have the same MX priority, the mail servers should try to connect to them in random order, and that they do not implement any specific algorithm.

October 2022 - PowerDNS