The whole course ▾

System Design · Week 6 revision

Week 6 revision: Patterns

Updated 22 Oct 2026 · By Akshay, software engineer, India · 4 min read

Patterns week in ten minutes: feeds, search, nearby, contention and big jobs, then six questions to test yourself.

The video for this revision is coming soon.

New System Design videos go up at 6 pm. Subscribe on YouTube so you don't miss it.

Got a doubt? Ask in the comments under the video.Subscribe

Lesson 25Feeds and fan-out

Feeds and fan-out
Restaurant
app
Posts
service
Fan-out
queue
Fan-out
workers
Feed
cache
a list
per
customer
Customer
app
new post
fan out
add to
followers
read my list
SAY THIS IN THE INTERVIEW
Hybridfan-out:push
intofeedcaches,pull
forcelebrities,merged
atreadtime.

This week was five patterns, each one hiding inside famous interview questions. It began with a feed of restaurants, and a pizza chain with five million followers.

Lesson twenty-five. Pull builds a feed when it's opened: cheap writes, expensive reads. Push builds it in advance: the restaurant app posts, the posts service drops a job on a fan-out queue, and fan-out workers add the post to each follower's list in a feed cache, so the customer app reads one list. But one celebrity post means millions of writes. So the hybrid: push for most accounts, and for huge ones, merge their recent posts in when the feed is read.

The interview line: hybrid fan-out, push into followers' feed caches through a queue, pull for accounts above a follower threshold, merged at read time, with cursor pagination. And say the threshold as a number. Inactive users get pull too, which saves a lot of memory.

Search
Search in three lines
1
Inverted index: word -> dishes
2
Normalise: stems, synonyms, typos
3
Elasticsearch, synced by CDC
SAY THIS IN THE INTERVIEW
Aninvertedindexin
Elasticsearch,sharded
andreplicated,keptin
syncbyCDC.

Then a customer typed paneer, and waited four seconds.

Lesson twenty-six, in three lines. LIKE percent paneer scans every row, so search engines use an inverted index: each word mapped to the dishes that contain it, and a query intersects the lists. They normalise every word: lowercase, stems, synonyms, and fuzzy matches for typos. And the index lives in Elasticsearch, synced from the database by change data capture, while the database stays the source of truth.

The interview line: search runs on an inverted index in Elasticsearch, sharded and replicated, fed by change data capture, ranked by text relevance plus business boosts like distance and popularity. And typeahead is a separate job: precomputed suggestions per prefix.

Lesson 27Nearby

Nearby
Nearby in three lines
1
Two ranges are slow: use cells
2
Search the cell and 8 neighbours
3
Moving riders: in memory
SAY THIS IN THE INTERVIEW
Cellsinmemory;search
thecellandits
neighbours,thenfilterby
realdistance.

Then an order was ready, and we needed the free riders within two kilometres.

Lesson twenty-seven, in three lines. An index helps with one range, not latitude and longitude together, so turn the map into cells: geohashes, quadtrees for uneven cities, or Uber's hexagonal H3. Search the target's cell and its eight neighbours, then filter by real distance. And riders who move every four seconds, seventy-five thousand updates a second, live in memory, in a Redis geo index.

The interview line: geohash or H3 cells in an in-memory index, search the cell and its neighbours, then filter and sort by real distance. And never search just one cell. Redis even has geo commands built in.

Lessons 28 and 29Contention, and long jobs

Contention, and long jobs
Contention
1
Read, then write: a race
2
Conditional writes or version checks
3
Slow contention: holds that expire
Big files and long jobs
1
Multipart, resumable uploads
2
Jobs on a queue, each with a state
3
Heartbeats, checkpoints, limits

And to finish: two riders accepting one order, and two-gigabyte menu videos.

Lesson twenty-eight. Reading a value, deciding, then writing is a race: two riders both saw the order free. The fix is a conditional write, set the rider where the rider is still empty, or a version check, so exactly one request wins. Contention that lasts minutes, like a festival thali during checkout, uses holds that expire on their own. And if you truly need a distributed lock, give it a lease and a fencing token.

Lesson twenty-nine. Big uploads go straight to storage as multipart, resumable uploads, so a dropped connection costs one ten-megabyte part. Long work runs as jobs on a queue, each a record with a state and progress. And reliable jobs use heartbeats, checkpoints, time limits and retry limits. And the queue's timeout must outlast the job, or two workers do it at once.

What's nextNext week: case studies

Next week: case studies
Week 7: case studies
1
Design YouTube
2
Design Dropbox
3
Design a web crawler
4
Design search autocomplete
5
Design a notification system

Next week, every lesson is a famous system, designed from scratch with everything you know.

Design YouTube: upload, transcode, stream. Design Dropbox: files in sync on every device. Design a web crawler, politely, across billions of pages. Design search autocomplete, in under a hundred milliseconds. And design a notification system for push, text and email. Then Sunday's mock: Ticketmaster.

Test yourself

Test yourself
?
A customer follows 300 normal
restaurants and 2 huge chains. How is
their feed built?
Read their pushed list, then merge in the
two chains' recent posts.
?
Why feed the search index with
change data capture?
Every database change reaches the index,
without the app writing twice.
?
Cells are 5 km wide, but you search
500 metres around a restaurant.
What's the problem?
Too many riders per cell to filter: use
smaller cells.
?
Give the one-line fix for two riders
accepting the same order.
UPDATE orders SET rider = ? WHERE id =
421 AND rider IS NULL.
Test yourself (cont.)
?
A customer holds a festival thali,
then closes the app. What happens to
it?
Nothing at first; when the hold expires, the
thali goes back on offer.
?
A 2 GB upload drops at part 150 of
200. What does a resumable upload
do?
Continue from part 150: the first 149 parts
are already stored.
Quick check

A customer follows 300 normal restaurants and 2 huge chains. How is their feed built?

Show the answer

Read their pushed list, then merge in the two chains' recent posts.

Quick check

Why feed the search index with change data capture?

Show the answer

Every database change reaches the index, without the app writing twice.

Quick check

Cells are 5 km wide, but you search 500 metres around a restaurant. What's the problem?

Show the answer

Too many riders per cell to filter: use smaller cells.

Quick check

Give the one-line fix for two riders accepting the same order.

Show the answer

UPDATE orders SET rider = ? WHERE id = 421 AND rider IS NULL.

Quick check

A customer holds a festival thali, then closes the app. What happens to it?

Show the answer

Nothing at first; when the hold expires, the thali goes back on offer.

Quick check

A 2 GB upload drops at part 150 of 200. What does a resumable upload do?

Show the answer

Continue from part 150: the first 149 parts are already stored.

Practise with flashcardsYour progress stays on this device.
New System Design videos at 6 pm

Lessons on weekdays, the week's revision on Saturday, a mock interview on Sunday.