Paths Subjects Questions Quizzes Pricing Search
Intermediate Open Pro

Choosing a Shard Key for a Messaging Table

You are sharding a messages table for a chat product: 2 billion messages per day, retention 1 year. Columns: message_id, conversation_id, sender_id, created_at, body. Dominant queries: fetch the last 50 messages of a conversation; append a message; occasionally list all messages a user sent in a date range. Candidate shard keys proposed by the team: created_at, sender_id, conversation_id, message_id (random UUID).

  1. Evaluate each candidate against cardinality, access-pattern locality and hot spots.
  2. Pick one and design the ID and index scheme around it.
  3. A group conversation with 200,000 members becomes extremely active. What breaks and how do you handle it?

Share this question

← Back to Database Replication & Sharding practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.