System Design AI

Design an Email Service: The Junior, Senior and Staff Answer

Designing an email service is a classic system-design interview problem. It forces you to think about high-throughput request paths, durability of user data, and the trade-offs between latency and consistency. Below is a step-by-step walk-through of what the interviewer is looking for, the core numbers that drive the design, and how the answer evolves from a junior to a senior to a staff level.

What the Interviewer Is Testing

  • Scalability – Can you design a system that handles millions of emails per day?
  • Reliability – How do you guarantee delivery and avoid lost messages?
  • Data modeling – Do you understand how to store user mailboxes, drafts, and metadata?
  • Operational insight – Do you think about monitoring, alerting, and cost?
  • Communication – Can you explain each component clearly and justify choices?

Core Requirements and Driving Numbers

RequirementTypical Value (hedged)
Active users~10 million users
Emails sent per day~100 million (≈1 200 per second)
Latency SLA for sending< 1 second for 99 % of requests
Storage per userRoughly 5 GB of mail (attachments, drafts)
Write durabilityAt least "once" guarantee, preferably "exactly-once" for user-visible actions

These numbers are enough to drive architecture decisions. A system that must sustain roughly 1 200 send requests per second needs a horizontally scalable front-end, a queue to smooth bursts, and a durable store for both the email content and the user mailbox index.

Core Design – One Hop at a Time

Below is a prose description of the request path, the data model, and the key design choice.

1. Ingress – API Gateway + Load Balancer

The client (web or mobile) hits an Amazon API Gateway endpoint. API Gateway provides request throttling, authentication (via Cognito or JWT), and a thin layer of request validation. Behind it sits an Elastic Load Balancer (ELB) that distributes traffic to a fleet of Amazon EC2 or AWS Fargate containers running the email service.

2. Front-end Service

The front-end validates the sender, checks spam-policy limits, and writes a write-ahead log entry to an Amazon SQS queue. SQS decouples the request from downstream processing, allowing the front-end to respond quickly (< 1 second) while guaranteeing that the message will be retried if downstream services fail.

3. Processing Workers

A pool of AWS Lambda functions or EC2 workers poll the SQS queue. Each worker performs:

  • Content sanitization and attachment scanning (via Amazon S3 for temporary storage).
  • Persistence of the email metadata to Amazon DynamoDB (partition key = userId, sort key = timestamp#mailId, so two emails in the same instant never overwrite each other).
  • Delivery to the recipient’s mailbox (also DynamoDB) and a push to a Kafka on MSK topic that feeds outbound SMTP delivery and downstream analytics.

4. Mailbox Store

User mailboxes are stored in DynamoDB because it offers low-latency reads/writes and automatic scaling. The schema is simple:

JSON
{
 "userId": "string",
 "mailId": "uuid",
 "timestamp": "ISO8601",
 "subject": "string",
 "bodyKey": "s3://bucket/key",
 "status": "sent|delivered|read"
}

Attachments and large bodies live in S3; the DynamoDB item only stores a pointer.

5. Caching Layer

Frequently accessed mailbox indices (e.g., recent 50 messages) are cached in Amazon ElastiCache (Redis). The cache is populated on read-through and invalidated on write. This reduces DynamoDB read-capacity consumption and improves UI latency.

6. Outbound Delivery

For external SMTP delivery, a separate worker pulls from the Kafka topic and talks to third-party mail relays. Successful deliveries update the DynamoDB status; failures trigger a retry loop with exponential back-off.

7. Monitoring & Alerting

All components emit Amazon CloudWatch metrics. Critical alerts include SQS queue depth, Lambda error rates, DynamoDB throttling, and cache miss ratios.

What a Complete Junior Answer Covers

  • Lists the basic components: API Gateway, load balancer, SQS, DynamoDB, S3.
  • Draws a single request path from client to storage.
  • Mentions latency SLA and rough traffic numbers.
  • Provides a simple data model for email metadata.
  • Explains why durability matters (e.g., an accepted email is never lost).

What a Senior Answer Adds

  • Introduces ElastiCache for read-heavy mailbox queries.
  • Shows a queue-based worker model (Lambda or EC2) to smooth spikes.
  • Discusses idempotency keys to achieve exactly-once semantics.
  • Adds a Kafka on MSK stream for analytics and audit trails.
  • Covers basic failure handling: retry policies, dead-letter queues, and partial failures.
  • Provides a rough cost estimate (e.g., DynamoDB read/write units vs. expected QPS).

What a Staff Answer Adds

  • Failure modes: detailed discussion of data-center outage, network partition, and the loss of a whole region. Shows how DynamoDB global tables and cross-region S3 replication mitigate these (DynamoDB already replicates across Availability Zones, which covers a data-center outage but not a region).
  • Operational readiness: capacity planning, auto-scaling policies for EC2/Fargate, Lambda concurrency limits, and cache eviction strategies.
  • Cost optimization: use of DynamoDB on-demand vs. provisioned capacity, S3 lifecycle policies for old attachments, and spot instances for workers.
  • Trade-off defense: argues why DynamoDB was chosen over Aurora (lower latency, automatic scaling) despite higher per-GB cost, and why SQS was preferred to a pure Lambda-triggered flow (back-pressure handling).
  • Security: encryption at rest (KMS), TLS for API Gateway, IAM least-privilege roles.
  • Compliance: retention policies for email archives enforced with DynamoDB TTL, and explicit deletes for GDPR-style erasure requests (TTL removes expired items in the background, typically within a few days).

Common Mistakes That Sink the Question

MistakeWhy It Fails
Ignoring scale numbersLeads to under-provisioned components and unrealistic latency claims.
Using a monolithic designNo separation of concerns; cannot handle burst traffic or isolate failures.
Forgetting durabilityEmails are user-visible data; losing them breaks trust.
Over-engineering with unnecessary servicesAdds complexity without measurable benefit; interviewers look for justified trade-offs.
No monitoring planOperations team cannot detect or respond to issues; interviewers expect CloudWatch alarms.
Skipping idempotencyDuplicate sends appear during retries, a classic bug in email systems.

Quick Comparison of the Three Levels

AspectJunior AnswerSenior AnswerStaff Answer
Core componentsAPI GW, ELB, SQS, DynamoDB, S3Adds ElastiCache, Kafka on MSK, Lambda workersAdds DynamoDB global tables, cross-region S3 replication, spot workers
Failure handlingBasic retry on SQSDead-letter queue, idempotency keysDetailed outage scenarios, graceful degradation plans
Operational concernsMention CloudWatch metricsCapacity planning, auto-scaling policiesCost modeling, security, compliance, SLA budgeting
Depth of explanationHigh-level flowDetailed request path, caching strategyFull trade-off analysis, defense of every major choice

How to Practice This

  1. Sketch the request path on a blank canvas. Start with the client, then add API Gateway, load balancer, queue, workers, storage, and cache. Label each hop with its latency target.
  2. Write a brief rubric: list the junior, senior, and staff expectations. Use it to self-grade a practice attempt.
  3. Grade your sketch against your rubric for missing components or weak justifications. With Pro ($10/month), draw it on System Design AI’s practice canvas and have the Coach review it.

Questions people ask

What traffic volume should I assume for an email service interview?

A reasonable ballpark is 100 million emails per day, which translates to about 1 200 send requests per second. This drives the need for horizontal scaling and queue buffering.

Why choose DynamoDB over a relational database like Aurora?

DynamoDB offers single-digit millisecond latency at any scale, automatic sharding, and built-in TTL for email expiration. Aurora provides richer query capabilities but requires manual scaling and can become a bottleneck under bursty write loads.

How do I guarantee exactly-once delivery of an email?

Use an idempotency token generated by the client and stored with the email record. Workers persist with a conditional write on the token (for example, DynamoDB attribute_not_exists), so a duplicate fails cleanly instead of racing a separate check. Combined with SQS's at-least-once delivery, this gives exactly-once processing inside your system; delivery to external SMTP servers can still duplicate if a relay accepts a message and the connection drops before it confirms.

What is a common cost-saving technique for storing attachments?

Store large bodies and attachments in S3 with lifecycle rules that transition older objects to cheaper storage classes (e.g., Infrequent Access or Glacier) after a set period.