Suped

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

18 marketer 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.

27 Nov 2022 - 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.

24 Nov 2024 - cPanel Forum

What the experts say

2 expert 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.

9 Mar 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.

8 Jul 2024 - Spam Resource

What the documentation says

5 technical 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.

4 Feb 2023 - 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.

6 Sep 2022 - Exim Wiki

Start improving your email deliverability today

Sign up