Build a Self-Destructing Inbox Platform for Throwaway Addresses
System DesignModel answerLast updated
Design a service that hands out short-lived, unguessable receive-only email addresses, ingests mail at scale, and exposes it through a web UI and API before wiping it.
Problem
Design a throwaway inbox platform. A user requests a random email address that works for a short time (default around 10 minutes), receives messages sent to it, reads them in a browser or via an API, and then everything disappears automatically.
The service is receive-only: it never sends mail. Users typically sign up for something elsewhere and need a verification code quickly.
What to cover
- Requirements and scale assumptions. State functional and non-functional goals, and estimate traffic, message volume, and live data size for millions of inboxes per day.
- API design. Create, extend, list, read, delete, and a real-time push channel. Explain how reads are authorized.
- Address generation and lifetime rules. How addresses are produced, whether they can be reused, how extensions work, and what the mail server does after expiry.
- Inbound mail path. DNS/MX setup, the inbound SMTP tier, early recipient validation, and how mail moves into durable storage without being lost.
- Data model. Inbox registry, message storage, per-message expiry, and indexing for the access patterns you identify.
- Abuse and spam controls. Both on the SMTP side and on the inbox-creation API side.
- Privacy and security. Isolation between inboxes, safe rendering of HTML and links, and attachment handling.
- Deletion and compliance. Background cleanup and guarantees that expired data is truly gone.
- Observability, availability vs. consistency trade-offs, and cost controls.
Provide a high-level architecture diagram (in text) and justify your main choices.
Hints
Hint 1
Do the capacity math first: live data is arrival rate x lifetime x average size. You will find storage is small, so the real costs lie elsewhere (bandwidth, spam, domain reputation).
Hint 2
Reject unknown or expired recipients at the RCPT stage, before the message body is transferred, and acknowledge accepted mail only after it is durably written to a log or queue.
Hint 3
Separate the public address from the secret used to read it, never recycle addresses, and make reads check the inbox's current expiry rather than relying only on storage-level TTL.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and scale
Functional
- Create an unguessable address with a default lifetime of 10 minutes, extendable up to a cap (say 60 minutes).
- Receive inbound mail only; no outbound relay, which removes most abuse risk.
- List and read messages via web UI and REST, with near-real-time push.
- Manual delete plus automatic hard delete at expiry.
Non-functional
- Latency: users wait on codes, so aim for p99 under ~5 s from SMTP acceptance to visible in the UI.
- Ingress availability matters most: a rejected mail is a failed signup.
- Strong privacy: no cross-inbox access, real deletion.
Back-of-envelope (assumptions)
- 5M inboxes/day x ~3 legitimate messages = 15M messages/day, about 175/s average, about 2k/s at a 10x peak.
- Total SMTP connections, including spam and unknown recipients, may be ~10x higher: roughly 20k connections/s at peak.
- Average message 50 KB, hard cap 10 MB.
- Live data = rate x lifetime x size: 175 x 600 s x 50 KB is about 5 GB; even a pessimistic 2k/s x 3600 s is about 360 GB.
Conclusion: storage is cheap. The expensive parts are ingress bandwidth, spam filtering, and keeping sending domains off blocklists.
2. API
POST /v1/inboxes {ttl_seconds} -> {inbox_id, address, token, expires_at}
POST /v1/inboxes/{id}/extend {ttl_seconds} -> {expires_at}
GET /v1/inboxes/{id}/messages?cursor=...
GET /v1/messages/{id}
GET /v1/messages/{id}/attachments/{aid} -> redirect to short-lived signed URL
DELETE /v1/inboxes/{id}
GET /v1/inboxes/{id}/stream (SSE or WebSocket)
The address is effectively public (anyone may send to it), so reading requires a separate bearer token, stored server-side only as a hash and scoped to one inbox.
3. Addresses and lifetime
- Local part: ~12 base32 characters from a CSPRNG (about 60 bits), so addresses can't be enumerated.
- Rotate across a pool of domains (e.g. ~20), since many sites block known disposable domains.
- Never reuse an address. A recycled address could leak password-reset mail intended for a previous holder. The 60-bit space makes collisions negligible; optionally keep hashed tombstones.
expires_atis set at creation; extensions are capped by an absolute maximum.- After expiry the MTA answers with a permanent
550 5.1.1, not a 4xx, so senders don't retry for days. - Add a ~30 s grace window to absorb clock skew between API and MTAs.
4. Architecture
Sender MTA -> MX (multi-region, L4 LB) -> Inbound MTA fleet
| RCPT check -> Redis inbox registry
v
Kafka `inbound-mail` (key = inbox_id)
v
Processors (MIME parse, spam score, sanitize, AV scan)
| | |
Wide-column DB Object store Redis (recent headers,
(metadata, small (large bodies, pub/sub for push)
bodies, TTL) attachments)
v
Stateless API/Web tier -> users
Ingress
- Several equal-priority MX records across regions, behind L4 load balancers; offer STARTTLS; advertise
SIZEso senders learn the 10 MB cap early. - Validate at
RCPT TOagainst a Redis registry (optionally behind a Bloom filter). Unknown or expired recipients are refused beforeDATA, saving the most bandwidth. - Durable handoff: return
250only after the queue acknowledges the write with full replication. If downstream is degraded, the queue buffers and nothing is lost. - Ordering: partition by
inbox_idfor per-inbox order; processors scale up to the partition count (provision ~200 for headroom).
5. Data model
Inbox registry (Redis, replicated, key TTL = expiry + grace):
inbox:{id} -> {address, domain, token_hash, created_at, expires_at, key_id, msg_count}
Messages (wide-column store, partition key inbox_id, clustering by received_at descending), holding sender, subject, snippet, size, spam score, auth results, and an encrypted inline body for small messages; large bodies and attachments go to object storage.
Per-message TTL: give each row a TTL of the maximum inbox lifetime plus grace, and gate reads on the inbox's current expires_at. That avoids rewriting TTLs when an inbox is extended. Time-window compaction suits this well, since whole files expire together and can be dropped cheaply.
Indexing: the only query is "messages of inbox X, newest first", which the partition and clustering keys serve directly. Embed the inbox ID in message IDs so single-message fetches need no secondary index.
6. Deep dives
Abuse and spam
- SMTP: per-IP and per-ASN rate limits, DNSBL checks, SPF/DKIM/DMARC recorded as annotations rather than hard rejects (legit senders are often misconfigured), per-inbox caps (e.g. 50 messages, 25 MB). Avoid greylisting; it delays verification codes by minutes.
- API: token-bucket limits on inbox creation per IP/key in Redis, CAPTCHA or proof-of-work on anomalies, higher quotas for paid tiers.
- Never relay outbound; monitor the domain pool for blocklisting.
Privacy and security
- Isolation: tokens scoped to one inbox, no list-all endpoint, every query keyed by
inbox_idand checked against the token hash. - HTML: server-side allowlist sanitization (no scripts, forms, iframes, event handlers); render in a sandboxed iframe on a separate cookieless origin with strict CSP; proxy remote images (blocked by default) to defeat tracking pixels; route links through an interstitial warning page.
- Attachments: size and type limits, antivirus scanning, stored encrypted, served only via short-lived signed URLs with
Content-Disposition: attachment. - Encrypt message bodies with per-inbox data keys; destroying the key makes the data unrecoverable even if a replica or backup lingers (crypto-shredding).
Deletion and compliance
- Storage-level TTL is the safety net; an explicit cleanup worker driven by expiry events deletes object-store blobs, cache entries, and keys.
- Keep backups short-lived or exclude message bodies; log only metadata with no content.
Observability
- Metrics: SMTP accept/reject ratios, queue lag, SMTP-to-visible latency (p50/p99), processor error rate, blocklist status per domain.
- Alerts on consumer lag and rising 4xx rates; synthetic probes that send mail to a test inbox end to end.
7. Trade-offs
- Availability over consistency on ingress: accept into the replicated log even if the registry is briefly stale; the read path re-checks expiry.
- Durability vs. latency: waiting for full replication adds milliseconds but prevents silent loss.
- Strictness vs. deliverability: soft-failing SPF/DKIM keeps verification mail flowing at the cost of more spam to filter.
8. Cost controls
- Early RCPT rejection and connection rate limiting cut bandwidth.
- Small TTL-bound data set; keep hot data in memory, offload large blobs to cheap object storage with lifecycle rules.
- Autoscale processors on queue lag; reserve capacity for MTAs because spam spikes are bursty.
Common mistakes
- Sizing for storage rather than for connection volume and spam.
- Returning 4xx for expired inboxes, which triggers days of retries.
- Recycling addresses, enabling account-takeover via reset emails.
- Rendering raw HTML on the main origin.
- Acknowledging mail before it is durably persisted.