Skip to content
SD-38 · Back to the write-up

Design a Social Marketplace

Listings live in a database; a change stream copies live ones into a geo and text index, hot searches come from a cache, and photos come from a CDN.

Follow a request

Clients
Edge
Services
Pipeline
Data
Buyer or sellerApp or web
Image CDNPhoto sizes
Result cacheHot searches
Photo storageOriginals
Listing serviceWrite + view
Search serviceQuery + rank
Review workersTrust and safety
Change streamRow changes
IndexerStream → index
Listings DB16 shards
Search index8 region shards
1user → search · GET /search?q=bikeA buyer searches “bike” under $200 within 20 km.1 / 7

The numbers, at a glance

For every write……there are about 40 searches
1 write ≈ 500/s40 searches ≈ 20,000/s
Searches reaching the indexWith a 60-second result cache
So 8 region shards at 2,000 queries a second each have room to spare.
Photo bytes are most of the trafficPeak, per second

A search, in order

Cache miss shown. On a hit, steps 3 and 4 disappear.

Buyer
Search service
Result cache
Search index
Image CDN
1 GET /search?q=bike
2 GET cell + query
3 miss
4 geo + text, top 500
5 500 ids + scores
6 SET page, 60 s
7 24 results
8 GET thumbnails
9 photos from edge
RequestResponseAsync, does not block

How the index follows the database

The decision that keeps sold items out of search.

Dual write
Drifts
PATCH sold
UPDATE rowindex write fails
sold bike in search
+ Simple, no extra system.− A failed second write leaves the index wrong.
Nightly rebuild
Too stale
PATCH sold
UPDATE row
index fixed tomorrow
+ Always consistent after a run.− Up to a day behind.
Change stream
Our pick
PATCH sold
UPDATE row
change log → indexer
removed in seconds
+ Every committed change, in order, within seconds.− A stream and an indexer to run.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 50 searches/sMake it work
Buyer
App server
DatabasePhoto storage
One service, SQL search, photos streamed by the app.
Stage 2 · ≈ 2,000 searches/sReal search
Buyer
Listing serviceSearch service
Change streamIndexer
Listings DBSearch index
A geo and text index kept in sync by a change stream.
Stage 3 · ≈ 20,000 searches/sServe the crowd
BuyerImage CDN
Listing serviceSearch serviceResult cache
Change streamIndexer
Listings DB × 16Index × 8 regions
Image CDN, a 60-second result cache, 8 region shards.
Stage 4 · + 175 new listings/sKeep it safe
BuyerImage CDN
Listing serviceSearch serviceResult cache
Change streamIndexerReview workers
Listings DBSearch index
New listings stay pending until review workers clear them.
Was this walkthrough useful?Your vote tells us what to improve next.