Skip to content

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 endpoint

Smart 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:

QueueWorkersPurpose
critical6Webhooks, urgent tasks
default3Email/SMS delivery
low1Background syncs, domain verification

Task types:

TaskDescription
email:deliverySend email via selected provider
sms:deliverySend SMS via selected provider
webhook:dispatchCall user webhook endpoint
domain:verificationPoll 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)

TechTrans Lab