Architecture
Overview
Dispatch runs as three components: an API server, a background worker, and an SMTP server.
┌──────────────────┐
│ Cloudflare │
│ (DNS + CDN) │
└────────┬─────────┘
│
┌────────┴───┐ ┌──────────┐ ┌───────────┐
│ API Server│ │ Worker │ │ SMTP │
│ (Gin) │ │ (Asynq) │ │ Server │
└────────┬───┘ └────┬─────┘ └────┬──────┘
└─────┬─────┘─────────────┘
│
┌───────────┼───────────┐
│ │ │
┌──┴──────┐ ┌──┴──────┐ ┌──┴─────┐
│PostgreSQL│ │ Redis │ │ S3 │
└─────────┘ └─────────┘ └────────┘Message Sending Flow
Client (REST API / SMTP)
↓
API Server validates & creates message record
↓
Enqueue to Asynq task queue (Redis)
↓
Worker picks up task
↓
ConfigurableSmartRouter selects provider
↓
Provider adapter sends (SES, Resend, MailerSend, etc.)
↓
Update message status in DB
↓
Dispatch webhook to user's endpointSmart Provider Routing
The ConfigurableSmartRouter selects the best provider based on:
- Priority — configured weight per provider
- Cost — cost-per-message optimization
- Region — geographic routing for latency
- Status — only routes to enabled/healthy providers
Supported email providers: AWS SES, Resend, MailerSend, SMTP relay, Console (testing). Supported SMS providers: AWS SNS, Twilio, Plivo, Vonage.
Task Queue
Background jobs run on Asynq (Redis-backed) with priority queues:
| Queue | Workers | Purpose |
|---|---|---|
| critical | 6 | Webhooks, urgent tasks |
| default | 3 | Email/SMS delivery |
| low | 1 | Background syncs, domain verification |
Task types:
| Task | Description |
|---|---|
| email:delivery | Send email via selected provider |
| sms:delivery | Send SMS via selected provider |
| webhook:dispatch | Call user webhook endpoint |
| domain:verification | Poll DNS for domain verification |
Authentication
Three authentication methods:
- JWT — User dashboard sessions (24h expiry)
- API Key — Third-party integrations with quota enforcement
- WebAuthn — Passwordless login via passkeys (FIDO2)