Discord Message Storage
Discord’s account describes moving its message store from Cassandra to ScyllaDB and adding Rust data services.
Discord’s account describes moving its message store from Cassandra to ScyllaDB and adding Rust data services. Messages are partitioned by channel and time bucket. Request coalescing and channel-based routing reduce duplicate concurrent reads before they reach storage. The migration included dual writes and comparison reads. The account makes clear that changing the database alone did not eliminate hot-partition concerns. Source publication: 2023-03-06. The walkthrough below is an original interview exercise, not an undocumented claim about the company.
Coalesce only identical authorized reads
For an independent history exercise, 100 callers request channel c7, bucket October, after message 90, limit 20. If authorization scope and representation version are identical, one in-flight source read can supply their shared result. A request for a different cursor, tenant or visibility scope is not the same key. A failed shared future must clear safely and let callers apply a bounded retry policy.
key=(tenant,channel,bucket,cursor,limit,scope,version)
100 identical reads -> one bounded source request
different scope -> separate authorized pathRead the diagram
key=(tenant,channel,bucket,cursor,limit,scope,version); 100 identical reads -> one bounded source request; different scope -> separate authorized path
Partition/bucket sizing, compaction debt and long reads can create noisy-neighbor pressure. Coalescing identical work reduces duplication but does not fix all storage layout problems. In a migration, compare message IDs, bodies/order, revisions and tombstones at a consistent boundary. Equal counts can hide a deleted message copied back or a missing message replaced by a duplicate. Keep copy checkpoints and a cutover/rollback authority.
Show answer and explanation
Answer: Coalescing by channel alone risks returning the wrong page or exposing another authorization scope. The linked first-party account defines the historical storage transition; these fixture counts are teaching inputs.
Step-by-step reasoning
1. Choose the history access path
In a new chat service exercise, list the newest 50 messages in one channel. A partition key of channel plus bounded time bucket supports this query and limits partition growth. A global message ID table alone requires a secondary access path for channel history.
2. Separate coalescing from caching
Coalescing shares work only while an identical read is in flight. Caching reuses a completed result later. The former need not choose a long freshness interval, but requests must agree on authorization, projection and consistency requirements before sharing a result.
3. Apply backpressure before storage
Cap in-flight reads per channel and globally. If 10,000 users open one announcement, one shared fetch can satisfy many, but a stream of distinct reads still needs admission control. Use separate metrics for requests received, storage queries issued and callers waiting.
4. Migrate without assuming equality
For an independent migration, dual-write through a durable source or reconciliation process, backfill historical ranges, and compare sampled reads including deletes. Define the cutover and rollback authority. A passing count comparison is weaker than comparing message content, order and tombstones.
Contracts and state
The following sketch makes the decision boundary concrete. Field names and capacity assumptions are illustrative; adapt them to the stated product contract.
messages(channel_id, time_bucket, message_id, body)
read_key(channel_id, bucket, cursor, limit, auth_scope)
inflight(read_key -> shared future)
migration(range_id, checkpoint, validation_status)Worked example
Original exercise: 1,000 authorized readers request the same page during a 40 ms storage read. With routing and a shared in-flight entry, the service can issue one read for that page. If every reader requests a different cursor, coalescing provides little benefit; concurrency limits must still protect storage.
Failure walkthrough
Original failure probe: the shared read times out. Complete every subscriber with a bounded error, remove the in-flight entry and limit retries. Leaving the failed future in the map permanently poisons that page. One caller cancelling must not cancel work still needed by other subscribers.
Read the diagram
Readers request the same page → Route by channel → Join one in-flight task → Fetch storage once → Complete all authorized subscribers
Decisions and trade-offs
| Decision | Useful when | Cost to explain |
|---|---|---|
| Adopt the mechanism | The same workload constraint is demonstrated | Validate with your own measurements |
| Keep a simpler design | Your scale and guarantees are already met | Monitor the trigger for changing it |
Check your understanding
Why can hot partitions remain after adopting a faster database?
Show answer and explanation
Answer: A faster engine raises capacity but does not remove skew. One key can still exceed a node’s service budget. Routing, coalescing, admission control and a suitable partition model address different parts of that problem.
Primary documentation
Read the first-party engineering account or official technical reference. Company engineering posts describe the scope and date of that publication; the interview reconstruction and scenarios here are original teaching examples.
Continue the connection
Study WhatsApp and explain which guarantee from this lesson carries into that topic.
Decision review: Discord Message Storage
Discord Message Storage: What it is
This case studies the published message-storage migration and the request-handling mechanisms discussed in that account.
Discord Message Storage: Why it is needed
A popular channel can overload a partition, and many concurrent identical reads may duplicate storage work.
Discord Message Storage: When to use it
Use the account to reason about partition access and coalescing, while retaining its historical date and system boundary.
Discord Message Storage: How to use it
For our model, route compatible requests to shared in-flight state, key it by the full storage-result contract and enforce per-caller current authorization before disclosure. Bound subscriber counts, timeouts and retries.
Discord Message Storage: Compare an alternative
A cache reuses results across time; coalescing shares concurrent work. Unique cursors or incompatible permission-dependent results may remove the sharing benefit.
Discord Message Storage: Published evidence and limits
First-party engineering article — published 2023-03-06.
The account discusses channel/time-bucket message storage, operational problems, migration and request coalescing.
This is the published subsystem account, not a complete current Discord topology or authorization protocol. Exercise rates and policies are ours.
Discord Message Storage: Worked decision exercise
The following inputs and policies are original exercise assumptions; they are not measurements or undisclosed company behavior.
One thousand compatible readers request the same page during one 40 ms storage read. Under the declared routing/shared-entry assumption one read can serve them. Readers with different page contracts cannot be merged merely because they share a channel.
Read the diagram
Exercise: 1000 compatible readers during one 40 ms read; One shared entry can issue one storage read under routing assumptions; Different cursor or result contract gets separate work; Cancellation detaches one subscriber; failure is bounded
What if one caller cancels or the shared storage request fails?
Show answer and explanation
Answer: Cancellation detaches that subscriber without blindly cancelling work still needed by others. A failed shared future must expire/be removed under the bounded protocol, and every subscriber gets a bounded outcome. Retry identity and coalescing do not bypass current permission.
Discord Message Storage: Check the design
Measure coalescing ratio, unique-request ratio, queue wait, failure fanout and subscriber memory. Do not report the fixture’s 40 ms as Discord latency.