04
API Design
Three surfaces: the SMTP edge (internet-facing protocol, not HTTP), the web/mobile API (HTTP+JSON for client apps), and IMAP/POP (legacy clients). Real engineering attention goes into SMTP edge and the web API.
SMTPsmtp.gmail.com:25 — receive from internet
Standard SMTP conversation: HELO → MAIL FROM → RCPT TO → DATA. Sender verification (SPF lookup on sender domain), DKIM signature check, DMARC policy enforcement all happen here. Most spam rejected at SMTP-time before even accepting bytes.
GET/api/v1/messages?q=from:boss&labelIds=INBOX&maxResults=50
List messages matching a query. Gmail's query syntax is the primary API. Returns message stubs with metadata + snippets. Backed by per-user Elasticsearch-equivalent.
GET/api/v1/messages/{id}?format=full
Fetch full message including body, headers, and attachment refs. Sent separately from listing so list operations are fast + body is lazy-loaded.
POST/api/v1/messages/send
Submit outgoing message (web UI). Server does DKIM-sign, store in "Sent", enqueue for outbound SMTP delivery. Returns message_id immediately; delivery happens async.
POST/api/v1/messages/{id}/modify
Add/remove labels (marking read = remove UNREAD label). Strong-consistency in user's per-user datastore; fast path for UI responsiveness.
GET/api/v1/threads/{id}
Fetch full conversation (all replies in a thread). Thread ID is computed server-side from Message-ID chain.
POST/api/v1/messages/{id}/report-spam
User reports spam. Not just moves the message — feeds back into the spam classifier (user signal). This is how the filter improves over time.