BLUEPRINT #04Media & Streaming
Design a Distributed Email Service
Referenced Architecture Primitives (6)
Click any primitive to study its algorithmic deep dive10-Stage Structure:1. Requirementsβ2. Sizingβ3. Topologyβ4. Data Modelβ5. AWS Topologyβ6. Deep-Diveβ7. Failuresβ8. SRE Playbooks
1. Problem Statement & Scope
System Mission
Design a massively scalable, secure, and highly available distributed email infrastructure capable of handling tens of billions of daily inbound and outbound messages, supporting standard protocols (SMTP, IMAP, POP3, JMAP), real-time spam and malware filtering, cryptographic sender authentication (SPF, DKIM, DMARC), decoupled blob storage for attachments, and sub-second full-text mailbox search.
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Functional Requirements
- Inbound Email Ingestion (MX): Accept incoming RFC 5322 MIME messages over SMTP (Port 25/587 with STARTTLS).
- Outbound Email Dispatch: Queue, sign with DKIM private keys, and reliably deliver outbound emails to external recipient MX hosts.
- Mailbox Hierarchy & Threading: Support user folders (Inbox, Sent, Trash, Drafts, Custom Labels), read/unread status, and conversation threading via
In-Reply-ToandReferencesheaders. - Decoupled Storage & Attachments: Separate lightweight mailbox metadata from large raw MIME bodies and binary attachments (up to ).
- Full-Text Search: Sub-second search across email subjects, sender addresses, recipient lists, and message body contents.
- Security & Spam Filtering: Verify SPF, DKIM, and DMARC alignment; evaluate incoming payloads against real-time IP reputation lists and Bayesian spam classifiers.
Non-Functional Requirements (SLAs/SLOs)
- High Availability: uptime SLA for mail access and delivery ( downtime/year).
- Data Durability: Zero data loss ( durability for committed emails; 11 9s durability via Amazon S3).
- Delivery Latency: Outbound mail delivered to recipient MX in (); Inbound mail visible in user inbox in .
- Mailbox Read Latency: Rendering first 50 folder messages in ().
- Search Query Latency: Full-text query across 100,000 user emails in .
Out-of-Scope
- Real-time collaborative calendar and scheduling suites (CalDAV/iCalendar protocols).
- Web-based video conferencing integrations.
2. Capacity & Scale Estimation
Traffic & Throughput Calculations
- Active Mailboxes: accounts.
- Daily Inbound & Outbound Emails: emails/day.
Storage Sizing & Bandwidth Math
- Average Email Size: (Metadata: , Text Body: , Attachments: average).
- Storage Tier Allocation:
- DynamoDB Metadata (Hot): .
- Amazon S3 Raw MIME & Attachments: .
- OpenSearch Search Inverted Index: Indexing subject + body text () with 1 primary + 1 replica .
- Network Egress / Ingress Bandwidth:
3. High-Level Architecture & AWS Component Mapping
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Component Responsibility Breakdown
| Component | AWS Technology | Operational Role & Configuration |
|---|---|---|
| Inbound SMTP Gateway | Amazon SES (Inbound) | Receives incoming SMTP traffic on port 25 with STARTTLS, performs initial SPF/DKIM verification, streams raw RFC 5322 MIME payloads directly to S3. |
| Raw Payload Store | Amazon S3 | Content-addressable storage layout: s3://mail-raw-blobs/<user_id>/<year>/<month>/<message_id>.eml. Encrypted via AWS KMS. S3 Lifecycle moves mail to S3 Infrequent Access. |
| MIME Parser Fleet | Amazon ECS Fargate | Decouples MIME body parts, extracts plain-text/HTML, unpacks attachments, computes thread hashes (References/In-Reply-To), and populates DynamoDB + OpenSearch. |
| Mailbox Database | Amazon DynamoDB | High-performance single-table design storing folder views, thread indexes, read/unread statuses, and attachment manifests with single-digit millisecond latency. |
| Search Engine | Amazon OpenSearch Service | Managed distributed BM25 search cluster indexing email subjects, sender/recipient addresses, and tokenized message bodies. |
| Outbound Dispatcher | Amazon SES Dedicated IPs | Enforces outbound rate limiting, signs messages with 2048-bit DKIM RSA keys, handles automatic IP warming pools and bounce/complaint processing. |
4. API Interface Design & Wire Protocols
1. Send Outbound Email (REST API)
httpPOST /v1/mail/messages/send HTTP/1.1 Host: mail.production.aws.internal Authorization: Bearer <jwt_token> Content-Type: application/json { "to": ["architect@distributed-systems.org"], "cc": ["lead-sre@company.com"], "subject": "System Design Architecture Review: LSM vs B-Trees", "body_html": "<p>Team, attached is the revised proposal for the write-optimized storage engine.</p>", "body_plain": "Team, attached is the revised proposal for the write-optimized storage engine.", "in_reply_to": "<msg_88129a@distributed-systems.org>", "attachments": [ { "file_name": "lsm_benchmark_results.pdf", "content_type": "application/pdf", "s3_temp_upload_key": "temp-uploads/user_101/tmp_pdf_998124" } ] }
Response: 202 Accepted
json{ "message_id": "<msg_20260904_998124756@mail.aws.internal>", "status": "QUEUED_FOR_DELIVERY", "queued_at": 1718000050123 }
2. List Folder Messages (Cursor Pagination)
httpGET /v1/mail/folders/INBOX/messages?limit=25&cursor=eyJkYXRlIjoxNzE4MDAwMDAwLCJtc2dfaWQiOiJtc2dfMTAxIn0= HTTP/1.1 Host: mail.production.aws.internal Authorization: Bearer <jwt_token>
Response: 200 OK
json{ "folder": "INBOX", "unread_count": 4, "total_count": 1420, "messages": [ { "message_id": "msg_20260904_998124756", "thread_id": "thread_abc123xyz", "from": {"name": "Alice Wang", "email": "alice@cloud.org"}, "subject": "System Design Architecture Review", "snippet": "Team, attached is the revised proposal for the write-optimized...", "has_attachments": true, "is_read": false, "received_at": 1718000050000 } ], "next_cursor": "eyJkYXRlIjoxNzE3OTk5MDAwLCJtc2dfaWQiOiJtc2dfMDk5In0=" }
5. Data Models & Storage Architecture
Interactive Architecture DiagramSynthesizing vector architecture diagram...
DynamoDB Single-Table Schema (MailboxCoreTable)
Partition Key (PK) | Sort Key (SK) | Attributes & Payloads | GSI1-PK / GSI1-SK |
|---|---|---|---|
USER#<user_id> | FOLDER#INBOX#DATE#<timestamp>#MSG#<msg_id> | thread_id, from, subject_preview, is_read: false, s3_key, has_att: true | THREAD#<thread_id> / DATE#<timestamp> |
USER#<user_id> | FOLDER#SENT#DATE#<timestamp>#MSG#<msg_id> | thread_id, to: [...], subject_preview, s3_key | THREAD#<thread_id> / DATE#<timestamp> |
USER#<user_id> | FOLDER_STATS#INBOX | unread_count: 14, total_count: 1250, updated_at: 1718000050 | β |
USER#<user_id> | MSG_DETAIL#<msg_id> | s3_mime_key, body_preview, headers_json, attachments_list | β |
Part 2: Production Deep-Dive Locked1 Coin = 24 Hours
Unlock Complete Architecture & Production Runbooks
Your Balance:40 Coins
You have explored the free architectural preview (~45%). Spend 1 Coin to unlock the remaining 6 production deep-dive sections for a full 24 hours.
Sections Included in This 24-Hour Pass:
6. Core Algorithms & Deep-Dive Workflows
7. Architectural Trade-Off Matrix & Primitive Links
8. Critical Failure Modes, Resiliency & Edge Cases
9. Production Pitfalls & Anti-Patterns (The "Top 5 Gotchas")
10. Production Runbook & Observability Guide
11. System Design Interview Rubric & Deep-Dive Strategy
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure