New Configuration Operator: Modulo
Discussed in https://github.com/stalwartlabs/stalwart/discussions/2860
Originally posted by njz-cvm February 24, 2026 Hello,
Right now, I'm setting up a Stalwart cluster with a Proxmox MTA. I would like to evenly distribute traffic between these relays, or at least close to even. Stalwart does support having as many relays as I'd like, but the configuration options do not easily permit this behavior. For example, take the following configuration.
[queue.strategy]
route = [ { if = "is_local_domain('', rcpt_domain)", then = "'local'" },
{ if = "retry_num > 1", then = "'relay0'" },
{ if = "retry_num > 2", then = "'relay1'" },
{ if = "retry_num > 3", then = "'relay2'" }]
[queue.route."relay0"]
type = "relay"
address = "r0.example.org"
port = 25
protocol = "smtp"
[queue.route."relay1"]
type = "relay"
address = "r1.example.org"
port = 25
protocol = "smtp"
[queue.route."relay2"]
type = "relay"
address = "r2.example.org"
port = 25
protocol = "smtp"This configuration provides failover and high availability, but only when relay0 is overwhelmed. Distributing traffic based on a semi-random value can alleviate this issue.
[queue.strategy]
route = [ { if = "is_local_domain('', rcpt_domain)", then = "'local'" },
{ if = "retry_num == 1 && (size % 3) == 0", then = "'relay0'" },
{ if = "retry_num == 1 && (size % 3) == 1", then = "'relay1'" },
{ if = "retry_num == 1 && (size % 3) == 2", then = "'relay2'" },
{ if = "retry_num > 1 && (size % 3) != 0", then = "'relay0'" },
{ if = "retry_num > 2 && (size % 3) != 1", then = "'relay1'" },
{ if = "retry_num > 3 && (size % 3) != 2", then = "'relay2'" }]If we assume size is random-enough for load balancer purposes, this system would spread traffic between MTAs while also maintaining failover. Or instead of size, a random integer variable could be added as a dynamic value, generated once per email, when needed.
Source: stalwartlabs/stalwart