Library / Blogs
Salesforce Blog
Read the latest articles on the Salesforce Engineering blog. Go behind the cloud with Salesforce Engineers.
By Salesforce engineers · Salesforce · Added 2026-10-12
All content belongs to Salesforce engineers / Salesforce. We only link to it and give credit. Report a problem
Learn this article
About 37 min left. Your work is saved as you go.
What you are about to study
Salesforce wrote this to explain how they thought about a problem. You should know the basics: caching, queues and replication.
Ideas you will meet
- Distributed Systems
- Consensus, time, failure and the fundamentals of scale-out.
What we already know about this
Our own lessons on these ideas. Read them here before you start, so it makes sense.
Real-World Systems · 11 minDesign an email system (Gmail)How a message travels between providers over SMTP, how spam and spoofing are filtered, and how a mailbox is stored and searched at huge scale.Read here
The problem
An email system receives and sends messages for billions of mailboxes, stores them for years, keeps spam out, and lets users search and organise (labels, threads).
Requirements
- Reliable delivery: a message is never silently lost.
- Interoperability with every other mail provider.
- Spam, phishing and virus filtering.
- Large attachments, fast search, and strong privacy.
How email moves between providers
Email uses SMTP to send between servers. The key ideas:
- MX records in DNS tell you which servers accept mail for a domain.
- Delivery is store-and-forward: a server accepts a message, persists it, and passes it on, retrying if the next hop is down.
- Clients usually read mail through IMAP (or POP3) or through a provider's web and mobile API.
100%Figure SDA-RWS-02-1 · Servers talk SMTP to each other; readers fetch with IMAP or POP · © forcsguy.com
Image: Tim Sheerman-Chase · CC BY 2.0 · Source · Wikimedia Commons: Old Post Sorting Office, PortsmouthArchitecture
100%Figure SDA-RWS-02-2 · Email delivery architecture · © forcsguy.com
Sending
- The client sends the message to its provider's submission server (with authentication).
- The message is saved and put on an outbound queue, so slow recipients never slow the sender.
- A worker finds the recipient domain's MX hosts, connects with SMTP, and delivers. The worker signs the message (DKIM).
- Temporary failures are retried with backoff for days; permanent failures generate a bounce message.
Receiving
- The incoming server accepts the connection and verifies the sender with SPF, DKIM and DMARC.
- Filters score the message for spam, phishing and malware (rules, reputation, and machine learning).
- The message is written to the user's mailbox: metadata in a scalable database, bodies and attachments in object storage, and an entry in the search index.
- Clients are told (push, IMAP IDLE) that new mail arrived.
100%Figure SDA-RWS-02-3 · Where a received message is stored and how readers are told · © forcsguy.com
Fighting spam and spoofing
Mechanism What it does SPF The domain lists which servers may send for it DKIM The sender signs the message; receivers check the signature DMARC The domain says what to do when SPF or DKIM fail, and gets reports Reputation Track sending behaviour per IP and domain; rate-limit new senders Content filters Spam classifiers, link and attachment scanning Storage design
- A mailbox is append-heavy and read by recent items. Partition by user id, so one user's mail sits together.
- Keep metadata (labels, flags, thread id, snippet) separate from large bodies and attachments.
- Threads group messages by headers (References, In-Reply-To) and subject.
- Search uses an inverted index per user, updated as mail arrives.
- Deduplicate identical large attachments with content hashes.
- Keep multiple replicas and backups: email is people's records.
Scale and reliability
- Queues absorb bursts, for example newsletter sends.
- Rate-limit outgoing mail per account to stop compromised accounts spamming.
- Spread incoming servers across regions; MX records can list several with priorities.
- Privacy: encrypt in transit (TLS between servers) and at rest, and control internal access carefully.
Real-world reading
Related reading
- Marc Brooker's BlogMarc Brooker · brooker.co.zaBlogs
- NATS ServerNATS · CNCF / NATSGitHub
- Confluent BlogConfluent engineers · ConfluentBlogs
- Elastic BlogElastic engineers · ElasticBlogs
Show 6 moreShow fewer
- Moving Core Business Search to Elasticsearch at YelpYelp engineers · YelpCase Studies
- Domain-Driven Design ReferenceEric Evans · Domain LanguageBooks
- Moderating Promotional Spam and Inappropriate Content in Photos at Scale at YelpScale at Yelp engineers · Scale at YelpCase Studies
- Google Research BlogGoogle researchers · GoogleBlogs
- Khan Academy Engineering BlogKhan Academy engineers · Khan AcademyBlogs
- Salesforce BlogSalesforce engineers · SalesforceBlogs
Go deeper on this
A path through videos, articles, other case studies and code on the same ideas as Salesforce Blog.
Warm upGet the vocabulary first.
Books · Free from the author
Concurrent and Distributed Systems (Cambridge lecture notes)
Eight lectures on time, broadcast, replication, consensus and transactions, with notes, slides and video. Free from the author under CC BY-SA.
University of CambridgeIntermediate
Books · Free from the author
Computer Networks: A Systems Approach
How networks are built and why: protocols, routing, congestion control and the internet's architecture. The authors publish it free online under CC BY 4.0.
Systems ApproachIntermediate
WatchHow others solve the same problem, on video.
Videos belong to their creators and play from YouTube. More on YouTube (opens in a new tab)
ReadEngineers explain it in their own words.
Blogs · Free from the author · Read here
Scalable Web Architecture and Distributed Systems
A full chapter on the building blocks of large websites: availability, performance, reliability, scalability, caches, proxies, indexes, load balancers and queues. Free to read here under CC BY 3.0.
The Architecture of Open Source ApplicationsBeginner40 min
Papers · Read here
Facebook’s photo storage
This paper describes Haystack, an object storage system optimized for Facebook’s Photos application. Facebook currently stores over 260 billion images, which translates to over 20 petabytes of data.
USENIXIntermediate
See it in another companyThe same ideas, a different system.
Case Studies · Read here
Aroma: Using ML for Code Recommendation at Facebook
Thousands of engineers write the code to create our apps, which serve billions of people worldwide. This is no trivial task—our services have grown so diverse and complex that the codebase contains…
FacebookIntermediate
Case Studies · Read here
Brooklin: Distributed Service for Near Real-Time Data Streaming at LinkedIn
Brooklin—a distributed service for streaming data in near real-time and at scale—has been running in production at LinkedIn since 2016, powering thousands of data streams and over 2 trillion messages per day. Today, w...
LinkedInIntermediate
Read the codeSee how it looks when it is real.
GitHub
Engineering Blogs
A huge directory of company engineering blogs to learn from real production systems.
kilimchoiIntermediate
GitHub
Awesome Scalability
Curated reading list of articles on the architecture of scalable, reliable systems.
binhnguyennusIntermediate
Keep learning
Loading community…