Design the database for Instagram
PremiumDatabase designHard
- Social graph
- Story expiry
- Follow requests
Quick answer
This database design interview question asks you to design the database for Instagram. 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 for Instagram, a photo-sharing app. Users publish posts with 1 to 10 photos or clips in a fixed order, share stories that disappear after 24 hours, like, comment and follow other users. The hard parts are exact story expiry, private accounts and hot like counters.
Each post has a caption and hashtags, and comments allow one level of replies. A private account must approve each follow request before the requester sees anything. Photo and video files live in object storage; you design the tables that hold everything else.
What must the database for Instagram do?
- Post: Create a post with a caption, 1 to 10 media items in the order the author chose, a location and hashtags.
- Stories: Share a story (one photo or clip). Followers can see it for exactly 24 hours, then it disappears. The author sees who viewed each story.
How well must it do it?
- Correctness: A user cannot follow the same account twice, send two pending requests to the same account, or like the same post twice, even when a request is retried.
- Expiry: A story is never shown after 24 hours, even if the cleanup job is behind. Story and story view rows may be purged after 48 hours.
What scale should you design for?
Use these numbers in your estimates.
The scale numbers unlock with this questionUnlock
Key concepts
- Social graph
- Story expiry
- Follow requests
- Sharding
- Like counters
- Media metadata
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 Instagram and explain your choices the way you would in an interview.
- Is this question asked at entry level?
- It is marked Hard. It suits engineers preparing for senior interviews, where you are expected to drive the discussion and go deep on trade-offs.
- 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