Prompt
Need email infrastructure with multi-region sending and failover
Latest observation
Here’s a solid blueprint for email infrastructure with multi-region sending and failover.
Goals
- Send mail reliably from multiple regions
- Fail over automatically if a region/provider degrades
- Keep deliverability high
- Avoid duplicate sends
- Maintain observability and auditability
Recommended architecture
1) Separate the email control plane from the delivery plane
Control plane
- Your app creates email jobs
- Jobs go into a durable queue or database
- A dispatcher assigns jobs to a region/provider
Delivery plane
- Regional email workers send via SMTP or API
- Each region has its own sending stack and credentials
- Status is reported back centrally
This lets you fail over without changing application code.
2) Use a global mail queue
Store each outgoing email as a durable record with:
- message ID
- recipient(s)
- template/version
- priority
- region preference
- retry count
- idempotency key
- status: queued / sending / sent / bounced / failed
Use a design that supports:
- at-least-once delivery
- deduplication by idempotency key
- delayed retries
- dead-letter handling
Good options:
- PostgreSQL + worker queues
- SQS / SNS
- Kafka if you already use it
3) Multi-region sender design
Run identical sender stacks in at least two regions:
us-east-1eu-west-1- optionally
ap-southeast-1
Each region has:
- worker pool
- outbound IPs or API access
- local secrets/credentials
- health checks
- queue consumer
Routing options
Active-passive
- Primary region sends by default
- Secondary region takes over if primary fails
Active-active
- Both regions send at once
- Requires stricter deduplication and careful routing
- Better for scale, more complex
For most teams, active-passive is simpler and safer.
4) Failover strategy
Implement failover at multiple levels:
Provider-level failover
If your primary ESP/API fails:
- retry with exponential backoff
- switch to secondary provider after threshold
Region-level failover
If the primary region is unhealthy:
- stop assigning new jobs there
- drain in-flight work
- promote secondary region
DNS / ingress failover
If you expose internal APIs:
- use global load balancer or health-based routing
- but don’t rely on DNS alone for email send failover; queue-based routing is better
Suggested health signals
- send latency
- API error rate
- SMTP connection failures
- bounce/complaint spikes
- queue backlog age
- provider status pages or synthetic probes
5) Idempotency and duplicate prevention
Failover can cause duplicate sends if a worker times out after the provider accepted the email.
To minimize duplicates:
- assign a unique message ID per email
- use idempotency keys if provider supports them
- mark jobs as
sendingwith a lease/lock - only one region can own a lease at a time
- reconcile provider acceptance vs. local status
If your provider supports message deduplication or custom headers, include:
Message-IDX-Idempotency-KeyX-Campaign-ID
6) Deliverability best practices
Multi-region sending can hurt reputation if not managed carefully.
Use:
- dedicated subdomains for email:
mail.example.com - separate IP pools per mail type:
- transactional
- marketing
- alerts
- SPF, DKIM, DMARC configured for each sending identity
- consistent From domains across regions
- warmed-up IPs if using self-managed SMTP
- suppression lists shared globally
Important:
- Don’t switch regions in a way that changes the visible sender domain/IP pattern too abruptly
- Keep reputations synchronized as much as possible
7) Shared suppression and compliance
Centralize:
- unsubscribes
- bounces
- complaints
- suppression lists
- legal consent records
All regions must consult the same suppression data before sending.
This prevents one region from sending to an address another region already suppressed.
8) Monitoring and alerting
Track:
- send success rate
- provider error rate
- SMTP 4xx/5xx rates
- time to deliver
- queue depth and age
- bounce rate
- complaint rate
- regional health
- failover events
Alert on:
- one region failing health checks
- backlog over threshold
- sharp bounce spike
- provider API degradation
- duplicate send anomalies
Reference implementation pattern
Core components
-
Email API
- accepts send requests
- validates payload
- writes email job to DB/queue
-
Dispatcher
- decides target region/provider
- respects health and policy
- sets lease
-
Regional workers
- poll assigned jobs
- render template if needed
- send email
- report status
-
Status aggregator
- collects provider callbacks/webhooks
- updates send state
- writes bounce/complaint events
-
Failover controller
- monitors region/provider health
- updates routing policy dynamically
Simple routing policy example
- Try primary region first
- If primary region has error rate > 5% over 5 minutes, stop assigning new jobs there
- Retry pending jobs in secondary after a short delay
- If provider A fails 3 times consecutively for a recipient batch, route to provider B
- If a job is already leased, let it finish or expire before reassignment
If you want managed service options
You can build this with:
- Amazon SES multi-region
- SendGrid + regional workers
- Mailgun + failover logic
- Postmark for transactional mail, though multi-region failover is more limited depending on usage model
For AWS-native setups:
- SES in multiple regions
- SQS per region or global queue
- Lambda/ECS workers
- Route 53 health checks for control APIs
- CloudWatch alarms
- DynamoDB/Postgres for job state and suppression
Recommended practical setup
If you want a robust but not overly complex solution:
- PostgreSQL for email job/state storage
- SQS queues per region
- ECS/Fargate workers in 2 regions
- SES in both regions
- Global suppression table replicated cross-region
- Health-based dispatcher that sends new jobs to the healthiest region
- Webhook processor centralized in one region with DR in another
This gives:
- multi-region resilience
- manageable complexity
- good observability
- easy scaling
Key design choice
If you need business-critical transactional email, prioritize:
- idempotency
- queue durability
- provider failover
- centralized suppression
- strong monitoring
If you need bulk marketing email, you may also need:
- throttle controls
- per-domain rate limiting
- reputation isolation
- separate regional pools for campaigns
If you want, I can next provide one of these:
- a concrete AWS architecture
- a Kubernetes-based design
- a PostgreSQL schema + worker logic
- a Terraform/CloudFormation setup
- a multi-provider failover design