Design the database for a messaging app
PremiumDatabase designMedium
- Wide column store
- Partition key design
- Time bucketing
Quick answer
This database design interview question asks you to design the database for a messaging app. Aim for a design that stores data correctly and serves its main queries well, then explain the schema, keys, indexes and trade-offs. Interviewers want to see how you model entities, choose keys and design for the real access patterns.
The problem
Design the database behind a mobile messaging app like WhatsApp, with one-to-one chats and groups of up to 1,024 members. The hard parts are 800 million messages a day, a fast chat list with unread counts, history paging and read receipts.
When the app opens it shows a chat list: the most recent conversations, each with its last message and an unread count. Tapping a chat shows the newest messages and loads older ones as the user scrolls. Senders see when a message was delivered and read.
What must the database for a messaging app do?
- Send: Send a text or media message to a conversation; a retried send must not create a duplicate.
- History: Load the newest 50 messages of a conversation, then older pages of 50.
How well must it do it?
- Order: Messages in one conversation appear in the same order for every member.
- Durability: A message acknowledged to the sender is never lost.
What scale should you design for?
Use these numbers in your estimates.
The scale numbers unlock with this questionUnlock
Key concepts
- Wide column store
- Partition key design
- Time bucketing
- Read watermarks
- Idempotent writes
- Unread counts
How you’ll practise
- Access patterns
- Entities
- Schema
- Indexes and queries
- Scale and consistency
- Wrap-up
Lala, personalized to you, gives a hint when you ask and reviews your design when you are ready.
What do interviewers look for?
In any database design round.
- Lists the entities and how they relate before writing tables
- Designs the schema around the main access patterns
- Chooses primary keys, foreign keys and indexes with reasons
- Explains where to normalise and where to denormalise
- Considers integrity, transactions and concurrent writes
- Plans for growth: partitioning, archiving and migrations
Questions people ask about this interview question
- Which design type is this question?
- It is a database design question. You design the database for a messaging app and explain your choices the way you would in an interview.
- Is this question asked at entry level?
- It is marked Medium. Entry-level engineers can practise it, but it expects you to reason about requirements and trade-offs, not only list components.
- What should I cover first?
- Start with the entities and the main queries the database must answer. Agree on scope with the interviewer before you design anything.
- Can I practise it for free?
- It is a premium question. Sign up and unlock it once for 10 credits; it then stays unlocked. When you finish, Lala, your personalized AI mentor, can review your design for 30 credits.
Related questions
Updated · Written by the SevyDevy team