Skip to content

How to design Snapchat messaging

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Practice this question

The problem

Ephemeral messaging sends a photo, video or line of text to a friend or a small group, shows it, and then removes it. Snap's own help page describes servers designed to delete a snap once all of its recipients have viewed it, and to delete unopened snaps after about a month. The design underneath is the ordinary chat design, with stateful chat servers on WebSockets and a durable inbox, plus two additions that carry the round: media bytes go straight to blob storage and come back through short-lived signed links, and a view receipt starts a retried delete that removes the message row and each media object, with a bucket lifecycle rule as the backstop for messages nobody opened. The idea the answer turns on is that deletion is a promise about each copy, so you name each place a copy can live before you say how it goes away.

Clarifying questions

AskWhy it mattersA typical answer

In a group, does the message disappear when the first person views it or when everyone has?

It decides what the view receipt table has to hold and when the delete can fire. Per-recipient deletion needs one receipt per person and a count against the participant list.

When all of the recipients have viewed it. Until then, people who haven't opened it can still open it, so the message and its media stay.

How long do we keep a message that nobody opens?

It sets the backstop timer on the media bucket and on the message store, and it is the one case where a message is deleted without having been delivered.

Up to 30 days, as in the chat design this builds on.

How strict is 'deleted'? Best effort, or must no server be able to hand it out after the view?

A best-effort delete is a row removal and a bucket rule. A strict one forces you to list each copy, including replicas and caches, and to serve media in a way that leaves no copy you can't reach.

Strict. Once viewed, nothing on our side may hand it out again, whether a server, a replica or a cache. That rules out long-lived links and makes a CDN a liability.

What is the scale, and how much of it is media?

The message rate sizes the store and the delete pipeline; the share that is media decides whether the bytes may pass through the chat servers at all.

About 200 million active users sending about 20 messages each a day, roughly 40,000 messages a second, and most of the bytes are photos and video.

Does the sender learn that a message was delivered and opened?

An opened receipt is the same event that triggers deletion, so it comes almost for free; a delivered receipt needs a client ack on the inbox.

Yes to both. The viewed event already travels over the WebSocket; show it to the sender as well.

Can a recipient save or replay a snap, or must the sender be told about a screenshot?

Save and replay change the deletion rule for a message; a screenshot notice is a client-side event the server relays. Each one adds something to track, whether a state on the message or an event to deliver.

Out of the first pass. Screenshot notice is a good stretch question, so keep a place for it.

The requirements menu

RequirementScopeWhy

Send a photo, video or text to a friend or a small group

Core

The product. Text rides over the WebSocket; photos and video are the bulk of the bytes and get their own path.

Receive it in real time, or on next open if offline

Core

The chat design: a live connection for people online, a durable inbox and a push notification for people who aren't.

Delete the message and its media once every recipient has viewed it

Core

What makes the app what it is. The design has to touch the row, the inbox and each media object, and prove each one is gone.

Delete unopened messages after a fixed time

Core

The backstop. Without it, a message nobody opens would sit in storage for good, and a failed delete would have nothing to catch it.

Show the sender when the message was delivered and when it was opened

Optional

Worth taking: the viewed event already exists for deletion, so showing it to the sender costs one extra push over the sender's connection.

Let a recipient save a snap in the chat so it is kept after viewing

Optional

Snapchat has this feature. Leave it unless asked: it adds a state where a viewed message is kept, which complicates the delete rule you are about to defend.

Notify the sender if a recipient screenshots their snap

Optional

The stretch question for this design. It is a client event relayed to the sender, not a server-side control, so name it and park it.

Let the sender choose a longer timer, such as a day after viewing

Optional

Snap offers timers like this. It turns the delete trigger from 'all viewed' into 'all viewed plus a delay', which is a scheduled job rather than an immediate one. Mention it, don't build it.

End-to-end encryption of message content

Out of scope

It changes who can transcode (nobody but the clients) and what the server stores. Say that it would push processing to the phone, then set it aside.

Stories

Out of scope

One-to-many media with a time limit instead of a view count. A different fan-out and a different delete rule; a separate round.

Discover and maps

Out of scope

Publisher content and location features have their own read paths. They may share accounts and storage with messaging, but nothing in the messaging design depends on them.

Filters and lenses

Out of scope

Rendering on the phone before upload. The server sees a finished file either way.

Friend suggestions

Out of scope

A graph and ranking problem. The messaging design just needs to know who is in a conversation.

Non-functional requirements

RequirementWhat it forces

Deletion is strict: after viewing, no copy can be fetched from any server, replica or cache

You keep a list of each place a copy can land on your side (message table, replicas, inbox, bucket, any edge cache) and the delete touches each one; the phone is listed too, though the app's own cleanup is the most you can ask of it. Media is served from the bucket through links that die in minutes, the viewed check reads the primary rather than a replica, and a CDN is left out because it adds copies to purge.

Low latency: under 500 ms to online recipients, as in the chat design

A persistent WebSocket per client, stateful chat servers that know which connection belongs to whom, and pub/sub between servers so a message finds the recipient's server without a database round trip. Media bytes are kept off this path entirely; the message carries a key.

Media-heavy: most bytes are photos and video, not text

Phones upload straight to blob storage with presigned URLs and download with signed ones, so the chat servers move kilobytes of metadata while the bucket moves the bytes. Processing (transcoding) runs off a queue, not inline.

Every message is delivered before it is deleted

Deletion is triggered by view receipts, not by a timer that starts at send. The one exception is the unopened-message limit of 30 days, which is long enough that an offline recipient has time to come back. A message whose media is still processing is held, not sent half-finished.

Estimates

QuantityWorkingResultWhat it sizes

Messages a day

200 million users × 20 messages each = 4 billion messages a day

About 4 billion messages a day

The daily write volume on the message store and the inbox, and the number of view receipts you expect back.

Average message rate

4 billion ÷ 86,400 seconds in a day ≈ 46,000 a second; the interviewer's figure rounds this to about 40,000

About 40,000 to 46,000 messages a second on average, higher at peak

The write rate the chat servers and message store must take, and the read rate on the primary if each media fetch checks the viewed flag there.

Deletes a second

Each message is deleted once, so at steady state deletes match sends: about 40,000 rows a second. If a video keeps an original plus two playable versions, that is three objects for one message: 40,000 × 3 = 120,000

About 40,000 row deletes and up to about 120,000 object deletes a second

The delete pipeline: queue throughput, worker count, and the bucket's delete rate. This is the number the deletion promise rests on.

Upper bound on the unopened backlog

4 billion a day × 30 days = 120 billion messages, if nobody opened anything

A ceiling of 120 billion message rows; the real backlog is the unopened share, which the interviewer's numbers don't give

Why the retention limit matters to the store even though most messages are deleted far sooner, and why the lifecycle rule is a real cost saver rather than a formality.

Window a leaked signed link stays usable

5 minutes × 60 = 300 seconds. The storage provider's own console hands out download links that expire after 300 seconds

At most about 300 seconds from signing in which a forwarded link can still work, less if the object is deleted first

The lifetime on the media download URL: long enough for a phone on a slow network to fetch a video, short enough that a copied link is useless by the time anyone shares it.

Core entities

EntityWhat it holds

User

A person with an account and the devices the app runs on.

Conversation

A one-to-one chat or a small group; its participant list is what 'all recipients have viewed' is counted against.

Message

One row per message: who sent it, what it carries, when it expires and what state it is in.

View receipt

One row per recipient per message, created at delivery and updated when the recipient opens it; completeness of viewed_at across the participant list fires the delete.

Media object

The bytes in blob storage, under a key prefix per message so the original and each transcoded version can be found and deleted together.

The API

EndpointNotes

WebSocket sendMessage { conversation_id, text?, media_key? } → { message_id }

The chat server assigns the id, writes the row and the inbox entry, and publishes to each recipient's channel. Send a client-generated request id with it so a retry after a dropped connection doesn't create two messages. If media_key is present and its state is still pending, the message is stored but not delivered until the transcoder reports ready.

POST /media → { presigned_upload_url, media_key }

The server picks the key and signs a PUT URL for it with a short expiry; the phone uploads the bytes straight to the bucket. Chat servers don't see the file. The key is namespaced per message so the transcoder's outputs can sit under the same prefix.

GET /messages/{id}/media → { signed_url }, short-lived

Checks on the primary, not a replica, that the caller is a recipient, that the message state is sent and that this caller has no viewed_at yet. Then signs a download URL good for minutes (the example figure is 5), pointing at the playable version. After the caller's view receipt lands, this call returns 410 Gone.

WebSocket viewed { message_id }

Writes the receipt keyed by (message_id, recipient_id), so a duplicate is a no-op. If receipts now cover all participants other than the sender, the server moves the message to all_viewed and enqueues a delete job. The sender gets an opened receipt over their own connection.

The high-level design

viewedSenderChatRecipientMessages

Step 1 of 4

The chat core: servers, connections, a durable store

Start with the chat design the question builds on. Each phone holds a WebSocket to a chat server; the server writes the message row and an inbox entry, then pushes it to the recipient's server (pub/sub between servers, since a recipient may be connected elsewhere) and on to the recipient. If the recipient is offline the inbox holds it and a push notification wakes the device; on reconnect the client pulls what it missed. The recipient's viewed event comes back over the same connection and is written next to the message. The persistent connection, rather than polling, is what the under 500 ms target asks for. This covers text, but it has no answer for media or for deletion yet.

senduploaddeliverviewedfetchwritedonedeletedeletemediaoutputreadyexpirySenderChat serverBucketRecipientMessagesDelete jobsWorkerMedia jobsTranscoderLifecycle
The whole design

What breaks first

The deep dives

Making deletion real. Bob opens Alice's snap and closes it. At that moment, where does a copy of the snap exist, and how does each one go away, including when a delete call fails or a replica is a second behind?

A concept that helps here: Retries and dead-letter queuesA concept that helps here: Replication and read replicas

The media path. Alice records a long video and sends it to a few friends. Walk the bytes from her phone to each friend's screen: upload, processing and playback, and say what happens when processing fails.

A concept that helps here: Blob storage and presigned uploadsA concept that helps here: Transcoding and adaptive streamingA concept that helps here: Retries and dead-letter queues

Concepts this guide uses

Sources

  1. Snapchat Support: When does Snapchat delete Snaps and Chats?
  2. Snap: Privacy principles
  3. Amazon Simple Storage Service User Guide: Download and upload objects with presigned URLs
  4. Amazon Simple Storage Service User Guide: Uploading objects with presigned URLs
  5. AWS Prescriptive Guidance: How AWS services use presigned URLs
  6. Amazon Simple Storage Service User Guide: Expiring objects
  7. Amazon Simple Storage Service User Guide: Event Notifications
  8. Amazon Simple Storage Service User Guide: Event notification types and destinations
  9. Amazon SQS Developer Guide: Using dead-letter queues in Amazon SQS
  10. AWS re:Post: How do I remove cached files from CloudFront?
  11. AWS Elemental MediaConvert User Guide: What is AWS Elemental MediaConvert?
  12. Apple Developer Documentation: userDidTakeScreenshotNotification
  13. Prisma: Do I need a read replica?
  14. DEV Community: Design WhatsApp, the chat system design interview walkthrough
  15. AlgoMaster: Design WhatsApp
Sign in to report a mistake