Design a Self-Destructing Broadcast Messaging System
System DesignModel answerLast updated
Design a messaging service where one sender dispatches a message to many recipients, each of whom can read it exactly once before it disappears permanently.
Scenario
You are designing a messaging feature for a mobile-first platform. The feature works like this: a sender composes a message, picks a list of recipients, and hits send. Each recipient gets their own private copy. The moment a recipient reads the message, that copy is gone — permanently and irreversibly — for that person. Other recipients are completely unaffected and can still read their own copies.
This is not a group chat. There is no shared thread, no read receipts visible to other recipients, and no way to retrieve content after it has been opened.
What to design
Cover all of the following areas. Spend about the same depth on each rather than over-indexing on any single layer.
API surface
- What endpoints exist and what do they do?
- How do you prevent accidental double-reads from caches, prefetchers, or HTTP retries?
Data model
- How do you represent a message body versus a per-recipient delivery?
- How do you ensure that "permanently unavailable" holds even for backups and cold storage, not just the primary database?
High-level architecture
- Which services exist, and how do they communicate?
- How does a newly created message reach each recipient's inbox?
Fan-out strategy
- Synchronous or asynchronous? At what threshold?
- How do you keep fan-out idempotent so worker retries are safe?
Read-once enforcement
- What write pattern guarantees exactly one successful open per recipient?
- What happens if the server commits the open but the response never reaches the client? How do you handle that edge case without silently destroying the message?
Deletion and retention
- When and how is content removed?
- How do you handle unread messages that were never opened?
Scaling and partitioning
- What are the natural partition keys?
- Where are the hot spots, and how do you mitigate them?
Failure handling and consistency trade-offs
- Where do you accept eventual consistency, and where do you need stronger guarantees?
- What breaks under network partition, and what is your recovery path?
Constraints and assumptions to state upfront
Clarify these before designing — the interviewer may adjust them:
- Up to 1,000 recipients per send; larger batches take an async path
- Text content up to ~4 KB; media (images, video) up to ~25 MB stored in a blob store
- A user may own multiple devices, but only the first open wins across all of them
- Unread messages expire after 30 days
- The sender can see per-recipient delivery state (sent, delivered, opened) but cannot re-read the content
- "Permanently unavailable" means unreadable at the application layer even if raw ciphertext bytes survive in a backup
What a strong answer looks like
A strong response opens with a short back-of-envelope sizing exercise that motivates architectural choices, works through each section above in order, calls out at least two non-obvious trade-offs (the response-loss problem on open, crypto-shredding vs. hard delete, etc.), and is concrete enough that an engineer could start implementing from the description.
Hints
Hint 1
Think carefully about which API verb you use for the open action and why a plain GET is dangerous here — what infrastructure automatically issues GETs that you cannot control?
Hint 2
The hardest correctness problem is not delivery, it is what happens when the server successfully commits the read-once transition but the network drops before the client receives the response. Walk through that failure scenario before you finalize your open endpoint design.
Hint 3
Deleting a row from the primary database does not make content 'permanently unavailable' if ciphertext copies live in read replicas, backups, or a CDN. Think about a key-management approach that makes surviving ciphertext useless for a specific recipient without touching every copy.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Step 1: Size the System First
Before any design, anchor the architecture with numbers.
| Signal | Estimate |
|---|---|
| Daily active users | 50 M |
| Sends per user per day | ~20 |
| Total sends per day | ~1 B (≈ 12 K/s avg, 40 K/s peak) |
| Avg recipients per send | 5 |
| Delivery rows written per day | ~5 B (≈ 60 K/s avg, 200 K/s peak) |
| Text stored before deletion | ~1 B × 2 KB ≈ 2 TB/day, but most rows live only hours |
Key takeaway: the system is write-heavy, has a very short data lifetime, and partitions naturally by recipient. Design decisions should reflect that; do not optimize for read throughput of old messages.
Step 2: API Design
POST /v1/messages
Header: Idempotency-Key: <client-generated UUID>
Body: { recipients: [user_id, ...], text?, media_ids: [...], ttl_sec }
→ 202 { message_id, deliveries: [{recipient_id, delivery_id}] }
GET /v1/inbox?cursor=…
→ list of delivery metadata: delivery_id, sender_id, sent_at, has_media
(no content ever appears here)
POST /v1/deliveries/{delivery_id}/open
Body: { device_id, open_request_id }
→ 200 { content, media_urls (short-lived signed URLs) }
→ 410 Gone (already opened or expired)
GET /v1/messages/{message_id}/status (sender only)
→ per-recipient state: PENDING | DELIVERED | OPENED | EXPIRED
WS /v1/stream
→ push events: { type: "new_delivery", delivery_id, sender_id }
(events carry no content)
Three decisions worth explaining explicitly:
- The inbox never returns content. This prevents any inadvertent caching or logging layer from capturing message bodies.
- Open is a POST, not a GET. HTTP GET is semantically idempotent; caches, prefetchers, and link-preview crawlers will issue GETs speculatively. A POST signals that this request has side effects and must not be replayed automatically.
- Push events carry only metadata. If content traveled over the WebSocket, a reconnect-and-replay scenario could deliver the message a second time before the client acknowledges the first.
Step 3: Data Model
Separate the shared message body from per-recipient delivery state. This is the central modeling decision.
messages (partition key: message_id)
message_id, sender_id, created_at, expires_at,
body_ciphertext, media_refs[], content_key_id
deliveries (partition key: recipient_id, sort key: delivery_id)
recipient_id, delivery_id, message_id, sender_id,
state: PENDING | DELIVERED | OPENED | EXPIRED,
wrapped_content_key, -- per-recipient encrypted key material
opened_by_device, open_request_id, opened_at, expires_at
sender_outbox (partition key: sender_id)
→ message_id, recipient_id, delivery_id, state
idempotency (key: sender_id + client_msg_id, TTL: 24 h)
→ message_id
Why per-recipient key wrapping? Hard-deleting a row from the primary database does not make content unreadable — raw ciphertext bytes live in read replicas, backups, and blob storage. The solution is crypto-shredding:
- The message body is encrypted once with a random content key (CK).
- Each delivery row stores that CK wrapped (encrypted) with a key specific to that recipient, managed by a KMS or by the recipient's device key in an E2E scheme.
- On open, the server deletes or nulls out that recipient's wrapped CK.
Even if the ciphertext persists in a backup forever, it is unreadable for that recipient — they have no key. And one recipient opening the message has zero effect on other recipients' wrapped keys.
Step 4: Architecture
Client ──► L7 Load Balancer ──► API Gateway (auth, rate limiting)
├─► Send Service ──► Message Store
│ ──► Kafka (fanout topic)
├─► Open Service ──► Delivery Store (conditional write)
└─► Inbox Service ──► Delivery Store
Fan-out Workers ◄── Kafka ──► Delivery Store ──► Kafka (notify topic)
Notify Workers ──► Session Registry (Redis) ──► WebSocket Gateways (online users)
└─► APNs / FCM (offline users)
Expiry Workers ──► Delivery Store, Message Store, Blob Store
Step 5: Fan-Out Strategy
Use fan-out on write — each recipient needs independent mutable state, so shared lazy-read approaches do not work here.
The Send Service writes the messages row and emits a fanout event to Kafka via a transactional outbox (event and DB write in the same transaction) to avoid the dual-write problem. It returns 202 immediately without waiting for fan-out to complete.
Fan-out workers consume the event and create one deliveries row per recipient. The delivery_id is deterministic: hash(message_id, recipient_id). This makes each worker upsert idempotent — retrying a worker after a crash does not create duplicate rows.
For lists with 5 or fewer recipients, fan-out can be done inline for lower latency. For larger lists, the Kafka message contains recipient chunks of ~100, spreading work across many worker instances.
Once a delivery row is created, a notify event is published. If the recipient is online (Session Registry has an active WebSocket gateway mapping), the event is routed there. If offline, it goes to APNs/FCM. Notifications are at-least-once; the client dedupes by delivery_id. Duplicates are harmless because no content travels in the push.
Step 6: Read-Once Enforcement
The open operation is a conditional compare-and-set on the delivery row:
UPDATE deliveries
SET state = 'OPENED',
opened_by_device = :device_id,
open_request_id = :req_id,
opened_at = now(),
wrapped_content_key = NULL
WHERE recipient_id = :r
AND delivery_id = :d
AND state IN ('PENDING', 'DELIVERED')
AND expires_at > now()
RETURNING message_id, <key material before NULL>
In DynamoDB or Cassandra this is a conditional update or lightweight transaction. In Postgres or Spanner it is a row-level transaction. If two devices race to open the same delivery, exactly one wins; the other receives 410.
The subtle failure case: The commit succeeds, the wrapped key is destroyed, but the network drops before the response reaches the client. Strict exactly-once semantics would mean the user's message is gone forever with no content ever displayed — a bad user experience.
The pragmatic compromise is a short-lived retry lease:
- If a second request arrives with the same
device_idandopen_request_idwithin a ~60-second window, the server returns the content again from a separately stored lease slot. - After the lease window, or if any different device or request ID arrives, the server returns 410.
This is a deliberate trade-off: you sacrifice strict single-view semantics for a bounded window in exchange for resilience to transient network failures. State this trade-off explicitly; interviewers will probe it.
Step 7: Deletion, Retention, and Scaling
Expiry: A background worker scans for deliveries where expires_at < now() and transitions them to EXPIRED, nulling out their wrapped keys. The shared messages row is deleted once all deliveries referencing it are in a terminal state (OPENED or EXPIRED).
Partitioning: The deliveries table partitions by recipient_id, which distributes inbox reads and open writes naturally. The messages table partitions by message_id. Senders with huge fan-out lists (celebrity accounts) are a hot-spot risk for the fan-out workers — mitigate with rate limiting at send time and worker parallelism.
Consistency trade-offs to state explicitly:
- Fan-out is eventually consistent. There is a window where the message exists but some delivery rows do not yet. This is acceptable.
- The open operation requires strong consistency (LWT or serializable transaction) on the delivery row for the read-once guarantee. This is non-negotiable.
- Notification delivery is best-effort. A missed push is recoverable via inbox polling on app foreground.
Common mistakes to avoid:
- Making
/opena GET endpoint (breaks the read-once contract via prefetchers). - Storing content in the push notification payload (replay risk on reconnect).
- Relying on row deletion alone for "permanent unavailability" (backups survive deletes; crypto-shredding does not).
- Forgetting the lost-response edge case and claiming a pure exactly-once guarantee.