Wrap Up
In this chapter, we have presented a design for building large-scale email servers. We started by gathering requirements and doing some back-of-the-envelope calculations to get a good idea of the scale. In the high-level design, we discussed how traditional email servers were designed and why they cannot satisfy modern use cases. We also discussed email APIs and high-level designs for sending and receiving flows. Finally, we dived deep into metadata database design, email deliverability, search, and scalability.
If there is extra time at the end of the interview, here are a few additional talking points:
-
Fault tolerance. Many parts of the system can fail, and you can talk about how to handle node failures, network issues, event delays, etc.
-
Compliance. Email service works all around the world and there are legal regulations to comply with. For instance, we need to handle and store personally identifiable information (PII) from Europe in a way that complies with General Data Protection Regulation (GDPR) 29. Legal intercept is another typical feature in this area 30.
-
Security. Email security is important because emails contain sensitive information. Gmail provides safety features such as phishing protections, safe browsing, proactive alerts, account safety, confidential mode, and email encryption 31.
-
Optimizations. Sometimes, the same email is sent to multiple recipients, and the same email attachment is stored several times in the object store (S3) in the group emails. One optimization we could do is to check the existence of the attachment in storage, before performing the expensive save operation.
Congratulations on getting this far! Now give yourself a pat on the back. Good job!
Chapter summary
Reference Materials
- Number of Active Gmail Users: https://financesonline.com/number-of-active-gmail-users/
- Outlook: https://en.wikipedia.org/wiki/Outlook.com
- How Many Emails Are Sent Per Day in 2021?: https://review42.com/resources/how-many-emails-are-sent-per-day/
- RFC 1939 - Post Office Protocol - Version 3: http://www.faqs.org/rfcs/rfc1939.html
- ActiveSync: https://en.wikipedia.org/wiki/ActiveSync
- Email attachment: https://en.wikipedia.org/wiki/Email_attachment
- MIME: https://en.wikipedia.org/wiki/MIME
- Threading: https://en.wikipedia.org/wiki/Conversation_threading
- IMAP LIST Extension for Special-Use Mailboxes: https://datatracker.ietf.org/doc/html/rfc6154
- Apache James: https://james.apache.org/
- A JSON Meta Application Protocol (JMAP) Subprotocol for WebSocket: https://datatracker.ietf.org/doc/rfc8887/
- Cassandra Limitations: https://cwiki.apache.org/confluence/display/CASSANDRA2/CassandraLimitations
- Inverted index: https://en.wikipedia.org/wiki/Inverted_index
- Exponential backoff: https://en.wikipedia.org/wiki/Exponential_backoff
- QQ Email System Optimization (in Chinese): https://www.slideshare.net/areyouok/06-qq-5431919
- IOPS: https://en.wikipedia.org/wiki/IOPS
- UUID and timeuuid types: https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/uuid_type_r.html
- Message threading: https://www.jwz.org/doc/threading.html
- Global spam volume: https://www.statista.com/statistics/420391/spam-email-traffic-share/
- Warming up dedicated IP addresses: https://docs.aws.amazon.com/ses/latest/dg/dedicated-ip-warming.html
- 2018 Data Breach Investigations Report: https://enterprise.verizon.com/resources/reports/DBIR_2018_Report.pdf
- Sender Policy Framework: https://en.wikipedia.org/wiki/Sender_Policy_Framework
- DomainKeys Identified Mail: https://en.wikipedia.org/wiki/DomainKeys_Identified_Mail
- Domain-based Message Authentication, Reporting & Conformance: https://dmarc.org/
- DB-Engines Ranking of Search Engines: https://db-engines.com/en/ranking/search+engine
- Refactoring practice: build full-text search of QQ mailbox based on Tencent Cloud Elasticsearch: https://www.programmersought.com/article/24097547237/
- Log-structured merge-tree: https://en.wikipedia.org/wiki/Log-structured_merge-tree
- Microsoft Exchange Conference 2014 Search in Exchange: https://www.youtube.com/watch?v=5EXGCSzzQak&t=2173s
- General Data Protection Regulation: https://en.wikipedia.org/wiki/General_Data_Protection_Regulation
- Lawful interception: https://en.wikipedia.org/wiki/Lawful_interception
- Email safety: https://safety.google/intl/en_us/gmail/
Finished reading?
Mark it complete to track your progress.