

Outgoing Emails
HTTP Server → Queue → Email Worker → Gmail API → DB
Incoming Emails
IMAP Worker → Queue
↓
Label Assigner
↓
Tagged Queue
↓
Storage Worker
↓
PostgreSQL Elasticsearch
FLOW 1 — Outgoing Emails (HTTP Server → Queue → Worker → Gmail API)
1. HTTP Server
- User sends an email from your app.
- Server pushes the email request into a queue (Rabbitmq).
- This ensures:
- High throughput
- Durability
- No blocking of HTTP request
- Retry logic independent of API failures
2. Worker (Email Sender Worker)
This worker does 3 things:
a) Consume message from queue
- Reads the queued email event.
- Does not lose the event because:
- ACK only after Gmail API success
- Retry + DLQ if failing
b) Store the email body & metadata into DB
- Before sending, it stores:
- from, to
- subject
- HTML body
- attachments (optional)
- status = "PENDING"
- timestamp