Design disappearing stories like Instagram's
hard 50 minPeople post photos and short videos that vanish after 24 hours, and viewers tap through them from a row of circles.
Video lesson · Chapter 1 of 5
A phone publishes a twenty-four-hour story
Theory
Read or listen first. About 2 min.
What it is
A story is a photo or short video that followers can see for 24 hours. A row of circles, the tray, shows which followed accounts have something to watch. Tapping a circle plays that person's items in order.
Two features make it different from a feed. Everything has an end time, which touches the database, every cache and the files themselves. And viewing is sequential, so the app knows what comes next and can fetch it early.
Why it exists
People share more casually when a post does not stay on their profile for ever. The end time is a promise to the author, so showing a story late is a broken promise, not a cache detail.
It is a good interview question because the first answer ("use a TTL") is only a quarter right. Expired rows, files, caches and half-watched videos each behave differently.
A short history
2007
Flajolet, Fusy, Gandouet and Meunier publish HyperLogLog, a small sketch that estimates how many different items were seen.
October 2013
Snapchat introduces "My Story", snaps arranged in time order for friends.
2 August 2016
Instagram announces Stories: photos and videos that disappear after 24 hours, shown in a bar above the feed with a coloured ring for something new.
August 2017
RFC 8216 documents HTTP Live Streaming, which splits video into short files a CDN can cache.
January 2019
Instagram Stories is reported to be used by 500 million people a day.
Words to know
- Tray
- The row of circles: followed accounts with at least one live story.
- TTL
- Time to live: a lifetime attached to stored data.
- Expiry check
- Comparing the end time with now on every read.
- Active index
- A small table of who has live stories, and until when.
- Seen mark
- The last item of an author this viewer watched.
- Signed URL
- A media address with an end time and a signature, so it cannot be shared for long.
- Prefetch
- Downloading the next item before it is asked for.
- HyperLogLog
- A sketch that estimates distinct viewers in up to 12 KB.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
Understand it
Picture it
Chalk drawings on the pavement
Closing and washing are two different jobs. Only closing has to be on time.
Scope
What are we building?
A service like Instagram Stories: upload, a personal tray, sequential viewing, a seen-by list, and an end after 24 hours. The company's real system is not described here.
Similar applications
| Product | The twist |
|---|---|
| Snapchat Stories | Introduced the format in 2013 |
| WhatsApp Status | Shared with phone contacts instead of followers |
| Facebook Stories | The same idea beside a feed |
| YouTube Shorts | Vertical video without an end time |
| TikTok | Vertical video chosen by recommendation, not by follows |
Why it is interesting
Ending
Five places hold a story. They must agree that it is over.
Tray
Who has something new, out of 500 follows, in 200 ms.
Instant play
Half a second from tap to first frame, on mobile networks.
Counting
25 billion views a day, each person once.
The finished system
Where the design ends up
This is the last version. Design starts with one service and one database and shows which number forces each box.
The whole system
Where to read what
| Question | Interview tab | Concept page that owns the idea |
|---|---|---|
| What must it do? | Scope | Scoping |
| How big is it? | Numbers | Back of the envelope |
| What is the interface? | API and data | File uploads, idempotency |
| How does it grow? | Design | Object storage, CDN |
| What is hard? | Deep dives | Cache TTL, sharded counters |
| Why this choice? | Explain | Push and pull |
| Can I do it aloud? | Mock | 45 minutes |
The neighbour problem is the news feed, where copying to followers wins. Here it does not, and the numbers show why.
Summary
The whole topic in one minute.
A story's end time is checked on every read. Lifetimes in databases, caches and object storage clean up later, at their own pace, and none of them is exact.
The tray is cheap because the list of accounts with live stories is small: 200 million entries of 40 bytes is 8 GB, so each tray server keeps it and looks up the 500 accounts a viewer follows. Media goes straight to object storage and out through a CDN. Views are events, made unique by key, counted exactly when few and estimated when many.
- Check the end time on every read; let TTLs clean up.
- The list of accounts with live stories is 8 GB. Keep it near and pull.
- Media never passes through our services.
- A view has the key (story, viewer), so repeats cost nothing.
- Exact counts for small stories, HyperLogLog for a few huge ones.
- Private media needs short-lived signed addresses, not secret names.
Sources
- Instagram: introducing Instagram Stories (2016)
- Amazon S3: lifecycle rules and rounding to midnight UTC
- Amazon S3: expiring objects and removal delay
- Apache Cassandra: tombstones and TTL
- Apache Cassandra: time window compaction
- Apache Cassandra: counter columns
- Redis: HyperLogLog
- Amazon CloudFront: signed URLs
- Wikipedia: Instagram
- Wikipedia: Snapchat