KatInterview

Self-Destructing Chat Messages: System Architecture

System DesignModel answer
MediumModel answerSystem Designmessagingdistributed-systemsreal-time

Last updated

Build a messaging platform where messages automatically vanish after being read, supporting multiple devices, offline scenarios, and abuse prevention.

Problem Context

You're building a privacy-focused messaging platform where users can send one-on-one messages that automatically delete themselves after the recipient reads them. The platform needs to work seamlessly across phones, tablets, and computers, handle spotty internet connections gracefully, and still allow users to flag harmful content.

Core Requirements

What the System Must Do

  • Auto-deletion modes: Messages should either vanish the moment they're closed, or remain visible for a countdown period (configurable between 5-60 seconds) that starts when first opened
  • Device synchronization: When someone reads a message on their phone, it should disappear from their laptop and tablet too—and the sender should see it's been read everywhere
  • Network resilience: Devices going offline and coming back online should catch up correctly without showing already-deleted messages or missing read status
  • Content reporting: Recipients need a mechanism to flag abusive messages even though the content is designed to self-destruct
  • Silent notifications: New message alerts shouldn't expose content through Apple or Google's notification infrastructure

Performance & Reliability Targets

  • Response time: Under 200 milliseconds for message delivery when recipients are online
  • Uptime: The system should maintain 99.99% availability
  • Deletion integrity: Once marked as read and expired, message content must be permanently removed from servers
  • Realistic limitations: Acknowledge what the system cannot prevent (screenshots, camera photos, hacked clients)

Usage Scale

Assume the platform serves:

  • 50 million people using it daily
  • Each person sends roughly 40 messages per day (approximately 2 billion messages daily, peaking at 75,000 messages per second)
  • Typical user has 2-3 active devices connected to their account

Design Considerations

Your architecture should address:

  1. System layout: Which components handle sending, storage, delivery, and deletion? How do clients maintain persistent connections?
  2. Authority and timing: Who decides when the countdown starts—the client or server? How do you synchronize this across devices?
  3. Storage strategy: How do you model message states? Which database technology supports automatic expiration? How do you guarantee permanent deletion?
  4. Edge case handling: What happens when messages arrive out of order? When a device reconnects mid-countdown? How can you enable abuse reports without keeping plaintext?

Hints

Hint 1

Think about who should own the timer—pure client-side won't sync devices, pure server-side adds latency. A hybrid approach might combine both strengths.

Hint 2

End-to-end encryption means servers only see encrypted blobs. For abuse reporting, research 'message franking' techniques that let recipients prove what was sent without servers storing plaintext.

Hint 3

Consider databases with native TTL features (like Cassandra or ScyllaDB) and look into crypto-shredding—deleting encryption keys rather than waiting for data to physically purge from all replicas.