Skip to main content
BLUEPRINT #02Production Case Studies

Design Discord's Trillions of Messages Storage β€” Cassandra to ScyllaDB Architecture

Target AWS Architecture:
10-Stage Structure:1. Requirements→2. Sizing→3. Topology→4. Data Model→5. AWS Topology→6. Deep-Dive→7. Failures→8. SRE Playbooks

1. Problem Statement & Scope Clarification

System Mission

Design Discord's real-time messaging storage engine capable of persisting trillions of chat messages across millions of guilds (servers) and channels. The platform must maintain consistent <5Β ms< 5\text{ ms} P99P99 read latencies, handle extreme write spikes (e.g., millions of messages/sec during major gaming events or Midjourney bot usage), and eliminate unpredictable JVM Garbage Collection pauses.

Functional Requirements

  1. Chat Message Ingestion (SendMessage): Persist chat messages with strict millisecond-level monotonicity per channel.
  2. Channel Message History (FetchMessages): Retrieve batches of 50βˆ’10050-100 messages before/after a given with P99<5Β msP99 < 5\text{ ms}.
  3. Message Edit & Delete Mutations: Support atomic updates and soft-deletes without creating read-degrading tombstone storms.
  4. Isolation: Prevent mega-channels (e.g., 500,000500,000 active users in a single bot channel) from starving neighboring channels sharing the same database node.

Non-Functional Requirements (SLAs & SLOs)

  • High Availability: 99.999%99.999\% read/write availability across multi-AZ clusters.
  • Ultra-Low Read Latency: P50<1.5Β msP50 < 1.5\text{ ms}, P99<5.0Β msP99 < 5.0\text{ ms} (eliminating 2-second tail latency spikes).
  • Linear Horizontal Scalability: Add storage nodes seamlessly without stopping traffic.

2. Capacity & Scale Estimation (Back-of-the-Envelope Math)

Traffic & Storage Scale

  • Total Persisted Messages: >1,000,000,000,000> 1,000,000,000,000 (1Β TrillionΒ messages1\text{ Trillion messages}).
  • Peak Ingestion Rate: 5,000,000Β Messages/sec5,000,000\text{ Messages/sec}.
  • Average Message Size: 250Β bytes250\text{ bytes} (, Author ID, Channel ID, Text, Embed metadata).
  • Total Raw Storage: TotalΒ RawΒ Storage=1012Γ—250Β bytes=250Β TB\text{Total Raw Storage} = 10^{12} \times 250\text{ bytes} = 250\text{ TB}
  • Replication Factor (RF = 3): TotalΒ ClusterΒ Storage=250Β TBΓ—3=750Β TBΒ NVMeΒ SSD\text{Total Cluster Storage} = 250\text{ TB} \times 3 = \mathbf{750\text{ TB NVMe SSD}}

3. High-Level Architecture & Component Mapping

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

4. API Interface Design & Wire Protocol

protobuf
syntax = "proto3";

package discord.messages.v1;

service MessageStoreService {
  rpc SendMessage (SendMessageRequest) returns (SendMessageResponse);
  rpc FetchMessages (FetchMessagesRequest) returns (FetchMessagesResponse);
}

message MessageRecord {
  int64 message_id = 1; // Discord Snowflake
  int64 channel_id = 2;
  int64 author_id = 3;
  string content = 4;
  int64 created_at_epoch_ms = 5;
  bool is_pinned = 6;
}

message FetchMessagesRequest {
  int64 channel_id = 1;
  int64 before_message_id = 2;
  int32 limit = 3; // Default 50, Max 100
}

message FetchMessagesResponse {
  repeated MessageRecord messages = 1;
}

Part 2: Production Deep-Dive Locked1 Coin = 24 Hours

Unlock Complete Architecture & Production Runbooks

Your Balance:40 Coins

You have explored the free architectural preview (~41%). Spend 1 Coin to unlock the remaining 6 production deep-dive sections for a full 24 hours.

Sections Included in This 24-Hour Pass:
5. Data Model & Database Schema
6. Deep-Dive: Why Cassandra Failed & Why ScyllaDB Succeeded
7. In-Memory Routing & Rust Data Services (Singleflight Coalescing)
8. Reliability & Hot Partition Sharding
9. Comprehensive Trade-off Matrix
10. Real-World Engineering Failure Modes & Post-Mortem Lessons
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure