Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

System Design (High-Level Design)  Module 24 – Case studies: messaging, real time and collaboration

Design a chat app like WhatsApp: groups and E2EE

Extend chat to groups, photos and end-to-end encryption: group fan-out, media sent once by reference, group keys, a key set per device and presence.

  • Advanced
  • 30 minutes
  • Examples run with Python 3.14.8, Pyodide 314.0.7, Node.js 24.21.0 and quickjs 0.32.0
  • By MySmartCoPilot
Free intro, Pro: 6 of 30 minutes free
Free: Groups multiply deliveries, and media carries the bytes. With a pass: the other 13 sections and 3 interview answers, about 24 minutes.

What you will learn

  • Estimate group traffic, media bandwidth and media storage from stated assumptions
  • Scale group messaging and media sharing to groups of a thousand members
  • Explain how end-to-end encryption changes the server's role
  • Design multi-device keys and presence for groups

Before you start

What you’ll learn · Before you start

What you will learn

  • Estimate group traffic, media bandwidth and media storage from stated assumptions
  • Scale group messaging and media sharing to groups of a thousand members
  • Explain how end-to-end encryption changes the server's role
  • Design multi-device keys and presence for groups

Before you start

On this page

Groups of up to 1,000 members, photos and end-to-end encryption change a chat design in three places. A group message must reach every device of every member, so the server either adds a small entry to each device’s mailbox or, for large groups, keeps one group log that devices read from their own cursors. A photo is encrypted on the phone and uploaded once; messages carry only its id, its key and its hash, and a CDN serves the ciphertext to whoever fetches it. And with Encryption in which only the communicating devices hold the keys: the servers that store and route the messages see ciphertext and metadata, never the content. the server no longer reads messages at all. Devices hold the keys. The server publishes public keys and lists of devices, stores and routes ciphertext, and can no longer search, preview or filter what people write. Presence and typing stay soft state that expires within seconds. The design builds on the delivery lesson and keeps its rules.

Not affiliated

Based on public information about WhatsApp. MySmartCoPilot is not affiliated with WhatsApp, and WhatsApp’s real architecture may differ from what this lesson describes.

Groups multiply deliveries, and media carries the bytes

Ask these first; the answer this lesson assumes follows each question:

  • How large can a group be? Up to 1,000 members, though most are far smaller. Broadcast channels with millions of followers are another product.
  • Which media? Photos, voice notes and videos, compressed on the phone before they are sent.
  • What is end-to-end encrypted? Everything: one-to-one chats, groups, media, and the history copied to a new device. The server still sees who writes to whom, and when.
  • How many devices? A phone and up to four linked laptops or browsers per person, each with its own keys.
  • What about presence? “Online” and “typing” in one-to-one chats; in groups, typing and a count of members online.

People create groups, add and remove members, send text and media to them, forward media, link a new device and see who is typing. The design is judged by four promises: a removed member cannot read what is sent after the removal; the server never holds a key that decrypts a message; a group message reaches online members within a second; and a forward never uploads the media again.

The estimate sheet for groups and media Python · estimate/group_media_sheet.py
# The estimate sheet for groups and media (lesson system-design-hld/design-chat-groups-media-e2ee), on top of the
# one-to-one service of the delivery lesson: 200 million people a day. Every constant is an assumption with a name, so
# you can put your own numbers in and run it again. Sizes are decimal (1 PB = 10**15 bytes).
DAY = 86_400
PEAK = 3  # the evening peak against the daily average

GROUP_MESSAGES = 3_000_000_000  # group messages a day
DEVICES_PER_MESSAGE = 66.2  # devices a group message must reach, averaged over a mix of groups of 8 to 1,000
CIPHERTEXT_BYTES = 300  # one encrypted group message with its headers

MEDIA_ITEMS = 1_000_000_000  # photos, voice notes and videos sent a day, in chats and groups
MEDIA_MIX = [("photo", 0.85, 120_000), ("voice note", 0.12, 30_000), ("video", 0.03, 6_000_000)]  # share, bytes
DOWNLOADS_EACH = 8  # devices that download each media item, on average
KEEP_DAYS = 30  # a media blob is kept 30 days after it was last sent or forwarded

avg_bytes = sum(share * size for _, share, size in MEDIA_MIX)
deliveries = GROUP_MESSAGES * DEVICES_PER_MESSAGE
gbit = lambda bytes_a_day, peak=1: bytes_a_day * 8 * peak / DAY / 10**9

print("Groups and media: the estimate sheet")
print(f"  Group messages  {GROUP_MESSAGES / DAY:,.0f}/s on average, {GROUP_MESSAGES / DAY * PEAK:,.0f}/s at the peak")
print(f"  Deliveries      {deliveries / 10**9:,.0f} billion device deliveries a day, {deliveries / DAY * PEAK / 10**6:.1f} million/s at the peak")
print(f"  Group traffic   {gbit(deliveries * CIPHERTEXT_BYTES, PEAK):.1f} Gbit/s out at the peak, text only")
print(f"  Media           {avg_bytes / 1000:,.1f} KB per item on average; videos are {0.03 * 6_000_000 / avg_bytes:.0%} of the bytes")
up = MEDIA_ITEMS * avg_bytes
print(f"  Uploads         {up / 10**12:,.1f} TB a day: {gbit(up):,.1f} Gbit/s on average, {gbit(up, PEAK):,.1f} at the peak")
print(f"  Downloads       {up * DOWNLOADS_EACH / 10**15:,.2f} PB a day: {gbit(up * DOWNLOADS_EACH, PEAK):,.0f} Gbit/s at the peak")
print(f"  Media stored    {up * KEEP_DAYS / 10**15:,.1f} PB for {KEEP_DAYS} days of uploads, before replicas or erasure coding")

Output

Groups and media: the estimate sheet
  Group messages  34,722/s on average, 104,167/s at the peak
  Deliveries      199 billion device deliveries a day, 6.9 million/s at the peak
  Group traffic   16.6 Gbit/s out at the peak, text only
  Media           285.6 KB per item on average; videos are 63% of the bytes
  Uploads         285.6 TB a day: 26.4 Gbit/s on average, 79.3 at the peak
  Downloads       2.28 PB a day: 635 Gbit/s at the peak
  Media stored    8.6 PB for 30 days of uploads, before replicas or erasure coding

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 group_media_sheet.py

The sheet sets the shape of the design. At the peak, 104,167 group messages a second become 6.9 million device deliveries a second, and the text alone is small: 16.6 Gbit/s. Media is the bulk of the traffic. Uploads reach 79 Gbit/s at the peak and downloads 635 Gbit/s, which only a CDN carries, and videos make 63 % of the bytes. Keeping blobs for 30 days after they were last sent or forwarded holds 8.6 PB before replication.

Checkpoint

Check the estimate

  1. Question 1 of 2 3 billion group messages a day each reach 66.2 devices on average. How many million device deliveries a second is that at a peak of three times the average?

    Type a number.

    A hint

    Deliveries a day, divided by 86,400, times the peak factor.

    Show the answer: Question 1 of 2

    Answer: 6.9 million a second (anything from 6.21 to 7.59 counts)

    3,000,000,000 × 66.2 = 198.6 billion deliveries a day; ÷ 86,400 ≈ 2.3 million a second on average, and × 3 ≈ 6.9 million a second at the peak. Most of them happen later, when devices sync, but every one of them is a read.

  2. Question 2 of 2 Media items are 85 % photos of 120 KB, 12 % voice notes of 30 KB and 3 % videos of 6 MB. What is the average size of an item, in kilobytes (1 KB = 1,000 bytes)?

    Type a number.

    Show the answer: Question 2 of 2

    Answer: 285.6 KB (anything from 257 to 314.2 counts)

    0.85 × 120 + 0.12 × 30 + 0.03 × 6,000 = 102 + 3.6 + 180 = 285.6 KB. The videos are 3 % of the items but 180 of the 285.6 KB, 63 % of the bytes, so video settings decide the bandwidth.

The first design

Group chat with encryption: devices encrypt; gateways lead to messages, a key directory, presence and media tokens.Members' deviceseach with its own keysGatewaysconnections and APIMessage servicenumbers, routes ciphertextDevice mailboxesand group logsKey directoryidentity keys, prekeys,device listsPresencesoft stateMedia servicesigns upload anddownload tokensCDNBlob storeciphertext only1. ciphertext, and requestsfor keys and tokens2. keys of new devices3. messages4. store per deviceor per group5. pushonline, typing6. upload anddownload tokenstokens it checks7. encrypted media,with a tokenon a miss

Groups, media and end-to-end encryption: what the devices do and what the server keeps

Text description of the diagram

The members' devices each hold their own keys, encrypt every message and decrypt what they receive.

  1. Devices send ciphertext, and requests for keys and tokens, to the gateways, which hold their connections and serve the API.
  2. Before a device writes to a device it has no session with, the gateway fetches that device's keys from the key directory, which publishes identity keys, prekeys and every account's list of devices.
  3. Messages go to the message service, which numbers them and routes ciphertext without reading it.
  4. The message service stores each message in the mailbox of every device that must receive it, or once in the group's log.
  5. It pushes messages back through the gateways to the devices that are connected.

Presence and typing indicators go to a presence service as soft state that expires within seconds.

  1. For photos and videos, the media service signs short-lived upload and download tokens, which the CDN checks.
  2. Devices upload and download encrypted media through the CDN with those tokens. The CDN fetches from the blob store on a miss, and the blob store holds ciphertext only.

Follow one group message through it. The sender’s device fetches keys for any device it has not written to before, encrypts the message, and sends ciphertext through its gateway. The message service numbers it in the group’s sequence, stores it once per device or once per group, and pushes it to connected devices. Media takes its own path: the device uploads ciphertext with a signed token, and members download it from the CDN with tokens of their own. Step through it:

Interactive · step by step One group message and one photo through the first design Step through a member writing to a group and sending a photo, from the device to the other members.
One group message and one photo through the first design, step 7 of 7. Showing Sender's device, Key directory, Gateway, Media service, Message service, Mailboxes or a log, Members' devices, CDN and blob store.Sender's deviceKey directorypublic keys, device listsGatewayMedia servicesigns tokensMessage servicenumbers, routes ciphertextMailboxes or a logMembers' devicesCDN and blob storeciphertext only

The drawing shows the whole scene; its 7 steps are listed below.

Every step as text
  1. Keys for new devices. Before it encrypts, the sender's device fetches the public keys of any group device it has not written to before.
  2. Ciphertext only. The device encrypts the message itself and sends only ciphertext through its gateway. Nothing on the way can read it.
  3. Numbered and stored. The message service numbers the message in the group's sequence and stores it once per device or once per group.
  4. Pushed to whoever is online. It pushes the message to the members' devices that are connected; the others find it when they sync.
  5. A photo, uploaded once. A photo takes its own path. The device encrypts it, gets a signed upload token through the gateway, and uploads the ciphertext once.
  6. Fetched by reference. Members download the ciphertext from the CDN with tokens of their own. The message they received carries the photo's key and hash, so only they can decrypt it.
  7. What the server holds. The server published keys and device lists, stored and routed ciphertext, and signed tokens. It never held a key that decrypts the message or the photo.

The questions this design has to answer:

  • When should a group message go into every device’s mailbox, and when into one group log?
  • How does a photo reach 1,000 members with one upload, fetched only by people who have its key?
  • What can the server still do once it cannot read any message?
  • How does a sender reach a member with five devices, and what if its list of devices is out of date?
  • What does removing one member cost with sender keys, and what with MLS, the IETF’s group protocol?
  • What do presence and typing cost in a group of 1,000?
  • What breaks first at ten times the traffic?

Two choices decide most of the rest, one about delivery and one about keys. A device mailbox receives a small entry for each message its device must get. A group log stores each message once, and devices read it from their own cursors. Sender keys let a member encrypt each group message once, after sending its key to every member’s device in pairs. MLS is the IETF’s standard protocol for group keys, built for large groups whose members change.

Checkpoint

Check the first design

  1. Question 1 of 2 With end-to-end encryption, which of these does the chat server still hold?

    Choose every answer that is right.

    Show the answer: Question 1 of 2

    Answer:

    • Public identity keys and prekeys of every device
    • Who sent a message to whom, and when
    • The ciphertext of messages until devices fetch them

    The server publishes public keys, stores and routes ciphertext, and still sees who writes to whom, and when. It never holds a key that decrypts content, so it cannot index or search what people write.

  2. Question 2 of 2 A member sends a photo to a group of 1,000. How many times is the photo uploaded, and how do the others get it?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Once, as ciphertext; the message carries its id, key and hash, and members fetch it from the CDN with tokens of their own

    The phone encrypts the photo and uploads it once. The group message carries the blob's id, its key and its hash, and every member downloads the same ciphertext from the CDN with a token of their own.

Device mailboxes or one group log, with the writes counted Pro: opens with a Pro, Premium or Ultimate pass

In this part:

  • Media sent once and fetched by reference, with expiring tokens
  • What end-to-end encryption leaves the server doing
  • Group keys: sender keys against MLS, with the cost of a removal counted
  • Many devices per person: a key set each, and a list the server checks
  • Presence and typing in groups, with the deliveries counted
  • Failure drills: removals in flight, stale lists, lost uploads
  • Bottlenecks at 10× and 100×, and the designs rejected
  • The seven questions, answered
  • What each level should reach, and a timed rehearsal
  • Practise: plan a send with sender keys
    • Decide who gets a sender key before a group message
  • Interview questions
    • What does end-to-end encryption change about a chat server's job?
    • A member removed from an encrypted group of 500 says that her laptop kept showing new group messages for a few minutes after the removal. Groups use sender keys. How can that happen, and what do you change so that it cannot?
    • Media downloads now cost more than the rest of your chat service together. Photos and videos are end-to-end encrypted, so the server can neither see nor recompress them. Where does the egress come from, and how do you cut it without weakening the encryption?
    • Product wants end-to-end encrypted groups of up to 50,000 members, with people joining and leaving all day. Your groups use sender keys today. Would you keep them or move to MLS? Defend the choice with numbers, and say what the server must add.
  • Key takeaways

4 diagrams · 2 runnable examples (JavaScript, Python) · 1 exercise with sample tests · 3 interview answers · about 46 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Read a complete sample first: Design a chat app like WhatsApp: delivery

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.