System Design: E-commerce Product Search (Walnut Mart Search: Stock, Ranking and the Product Graph)
We design product search for a large US retailer with stores, a website and an app. Our retailer is called Walnut Mart, and our design is Walnut Mart Search. It covers:
- the search box;
- the results page with its ads;
- the "Goes well with" rows beside a product.
As in any system design interview, the numbers are assumptions for planning. Every number here is our own assumption, and the design is our own. All times are Central Time.
How to read this post. It takes about 90 minutes in full, so it is built to be read in parts:
1. Requirements
1.1 What we are building
Maya Collins is a nurse in Dallas. Her Walnut Mart app is set to pick up orders at store #2280 in Lake Highlands, near her home.
On Black Friday, Friday 27 Nov 2026, the deal prices start at 06:00. At 06:40 she is on a short break near the end of her night shift.
She wants breakfast she can pick up on her way home. She types with one thumb: "hi protien brekfast under $10".
- 06:40:14.000 She taps search.
- 06:40:14.190 40 results appear. The first is product P118, Walnut Greek yogurt. It costs $5.48 and is labeled "Pickup today". In place 3 is a protein shake, product P650, labeled "Sponsored".
- Two matching products are missing, on purpose:
- Product P411 is protein breakfast bars. Its $9.49 deal price had been loaded for her area by mistake. A pricing analyst fixed it to $11.49 four seconds earlier, so it is over her limit.
- Product P512 is high-protein oatmeal cups. It sold its last units at #2280 at 06:39:50.
- 06:40:31 She opens P118. A "Goes well with" row shows two products. First is product P305, blueberries. Second is product P204, almond granola.
- 06:41:02 She already has fruit at home, so she skips the blueberries. She adds P118 and P204 to her cart. A "Complete your cart" row fills in 40 ms.
- 06:43:20 Checkout holds her units at #2280 for 10 minutes.
The hard part: search may show only what Maya can get at #2280, at the price she will pay. Meanwhile, stock and prices change thousands of times a second.
1.2 Words we use
These words appear in many places. Words used in one place are explained where they appear.
| Word | Meaning |
|---|---|
| Offer | One seller's price and delivery terms for a product. Most products have one offer, from Walnut Mart itself. A marketplace seller sells on our site and ships the order itself. |
| Node | A place that holds stock: a store such as #2280, a fulfillment center such as center DFW-3, or a seller's warehouse. A fulfillment center is a warehouse that ships online orders. |
| Fulfillment mode | How the shopper gets it: pickup at one store, same-day delivery from a nearby store, shipping from a center, or marketplace, where the seller ships. The app sends it as "mode". |
| Node set | The nodes that can serve this shopper in her mode. For Maya's pickup it is {#2280}. |
| Price zone | A group of stores that share one set of prices. #2280 is in price zone 14. |
| Head, tail | How common a query, the words typed, is: "milk" is head, "keto oatmeal under $2 pickup" tail. Maya's typing is tail; corrected, "high protein breakfast" is head. |
| Index, document | An index, like a book's, is built ahead of time so matches are found without reading every product. A document is one product's entry: title, type and other text. |
| Shard, replica | A shard is one slice of the index: shard 7 holds 3 million products. A replica is one full copy of a shard, run by one program on its own machine. |
| Tier A, Tier B | Tier A: the 60 million products people buy, in 20 shards, asked on every search. Tier B: the other 440 million, in 55 shards, asked only sometimes. |
| Bitmap | One shard's in-stock list for one node: one bit per product, 1 means "at least 1 unit here". |
| Vector | A list of numbers that stands for meaning. A query and a product whose vectors point the same way mean similar things. |
| Candidate, tile | A candidate is a found product that may still reach the page. A tile is one result's box: title, image, price and a label such as "Pickup today". |
| Model, feature | A model is a program that learned from past examples to guess, such as "will Maya buy this?". A feature is one fact it reads, such as a rating. |
| L1, L2 | The two ranking models. L1 is cheap and runs inside each shard; L2 is careful and orders the best 1,000. |
| LLM | A large language model: a very big model that reads and writes text. It is too slow for live searches, so it works at night. |
| Query cache | A table of what common queries mean, built each night by the LLM. It is not a store of recent answers. |
| Result cache | Recent answer lists, shared by every shopper with the same query, store and filters, kept 30 seconds. |
| Exact check | The check of the top 50 against exact stock counts, exact prices and free pickup slots, after ranking. |
| Gateway | Our internet-facing servers. Every app call passes them: they check sign-in and block bots. |
| Event stream, partition | A Kafka-style log of every change, in order. It is split into partitions, ordered slices that different programs read. |
| Fast lane, document lane | Each shard's two partitions in the Event stream. The fast lane carries stock bits and prices; the document lane carries whole product documents. |
| Price epoch | A counter that moves when scheduled prices start, so cached answers with old prices stop matching. |
| Pod, p99 | A pod is one running copy of a program; a service runs as many pods. p99 is the time within which 99 of every 100 requests finish; p50 is the middle time. |
We run in 3 US regions, each in 3 availability zones. An availability zone is a separate building with its own power.
IDs in this post
Every ID below is made up for Maya's story. The start of each ID says what kind of thing it names.
| ID | What it names | Example |
|---|---|---|
| P118 | A product ID: one thing we sell | P118, Walnut Greek yogurt |
| #2280 | A store number: one Walnut Mart store | #2280 in Lake Highlands, Maya's pickup store |
| DFW-3 | A fulfillment center ID: one warehouse that ships online orders | DFW-3, a center in Fort Worth |
| S-3307 | A seller ID: one marketplace seller | S-3307, Lone Star Pantry |
| sh_5531 | A shopper ID: one Walnut Mart account | Maya |
| q_7731 | A search ID: one search, made by the app | Maya's search at 06:40:14 |
| H-48213 | A delivery cell ID: one hexagon of the same-day delivery map | The cell of Maya's home |
| price zone 14 | A price zone number: a group of stores that share one set of prices | Zone 14, which holds #2280 |
| shard 7 | A shard number: one slice of the search index | Shard 7, which holds P118, P411 and P512 |
| sequence 88,410 | A sequence number: it grows by one with each stock change of one product at one node | The sale of the last P512 at #2280 |
| US#P118 | A partition key: the market, then the product | US#P118, the row of the yogurt's ready lists |
| STORE#2280, COMPLEMENT#P204 | A sort key: the kind of row, then a store or a product | STORE#2280, P118's stock row at #2280 |
| 2026-11-26 | A Query cache version: named for the night that built it | The version in use on Black Friday |
| epoch 42 | A price epoch: a counter that moves when scheduled prices start | 41 before 06:00, 42 after |
| /v1 | Version 1 of our API, at the start of each path | POST /v1/search |
1.3 Every kind of request and change
The story follows one search. Walnut Mart handles much more than that. Each row names the part that handles it, and the other team or outside company that takes part.
| Kind | What it is | How often or how fast | Which part handles it | Other team or outside company |
|---|---|---|---|---|
| Typeahead | Suggestions while she types, such as "high protein breakfast" after "hi prot" | 500,000 calls a second at peak, 5 per search; p99 50 ms | Walnut Typeahead, an index of suggestions in every server's memory, rebuilt each night. The Search Autocomplete post designs it | A bought CDN keeps answers for texts of 1 to 4 characters near shoppers |
| Keyword search, spelling fixed | Typed words become fixed words and a list of products. Maya's search is this kind | 100,000 a second after 06:00 on Black Friday; p99 300 ms | The Query understanding service and the Query cache, then the index shards | None |
| Filters and facets | A filter narrows the results; a facet is a filter with its count, such as "Walnut (212)" | On most searches, with no extra call | Each shard counts its filtered matches, and the Retrieval service adds them up | None |
| Sort by price | "Price, low to high", by the price at her store | A price change reaches the index within 10 seconds | Zone prices in each shard's memory | The Price system, another team's, which decides prices |
| Sponsored products | Labeled ads in places 3, 8, 16 and 28, such as the protein shake P650 | An auction on every search, within 25 ms | The Ads service, beside the search; the exact check drops an ad not on the shelf | Advertisers, through the ads system, another team's |
| Recommendation rows | "Goes well with" shows products used together; "Out of stock? Try" shows ones that can replace it; "Complete your cart" fills a cart | 250,000 row requests a second; p99 80 ms | The Recommendation service, ready lists, and a walk in memory for a cart | None |
| A new listing | A seller lists a product, such as Lone Star Pantry's granola P990 at 21:00 Thursday | Searchable within 5 minutes at p99; one seller may upload 5 million at once | The Catalog service, the Indexer and each shard's document lane | Marketplace sellers, through their feeds |
| Recalls | A product that must leave search at once | Gone from every shard within 60 seconds | A blocked-products list that every shard reads | None: our own admins add it |
| Price changes | Scheduled deal prices, and fixes such as P411's at 06:40:10 | 30 million deal prices start at 06:00:00; a change reaches the Offer store within 2 seconds and the index within 10 | The Price updater, the Offer store and each shard's fast lane | The Price system |
| Stock changes | A sale or a delivery changes a count, such as the last P512 at 06:39:50 | 23,000 a second on average, 230,000 after 06:00 | The Stock updater, the exact counts, and a bit on the fast lane when the state flips | The stores' point-of-sale and inventory systems; the Order service holds units at checkout |
| Marketplace offers | A seller's own price and shipping for a product | Mostly in Tier B, asked on about 15% of searches | Offers in the Offer store, and one "some seller has stock" bitmap per shard | Marketplace sellers |
| Bots | Programs that copy our prices or watch deep deals | About 40% of search requests at the Gateway on Black Friday | The Gateway's bot score and limits | None |
This post follows Maya's pickup search in depth, because stock at one store is the hardest case. The other kinds use the same parts.
1.4 Functional requirements
- Search by words, with spelling fixed, returning only products the shopper can get in her mode at her store.
- Filter and sort by price, brand, rating and diet. Show facets: filters with counts, such as "Walnut (212)". Keep paging stable.
- Show the price she will pay and an honest label. Labels are "Pickup today", "Limited stock", "Delivery today" and "Arrives Tue". When our stock data is too old, the label is "Check availability".
- Show sponsored products: labeled ads in a few fixed places.
- Recommend products from what her store has. Complements go with this one; substitutes can replace it.
- Make new listings searchable within minutes; remove recalled products within a minute.
- Log what was shown and what the shopper did, so models can learn.
Out of scope:
- payment and orders;
- store operations;
- seller onboarding;
- the system that decides prices.
1.5 Non-functional requirements
- Fast. Search p50 120 ms and p99 300 ms of server time. Typeahead (suggestions while typing) p99 50 ms. A recommendation row p99 80 ms.
- Honest about stock. "Pickup today" means the result passed a stock check when the page was built, on data normally under 10 seconds old. Only checkout makes the final, strong check.
- Honest about price. The tile shows the current price. A change reaches the Offer store (our price store) within 2 seconds and the index within 10 seconds, at p99.
- Fresh catalog. A new listing is searchable within 5 minutes at p99.
- Available. 99.95% of searches answered in a month; a simpler page counts. Recommendations never block search.
- Survives a region. If one region is lost, the other two carry the full load.
1.6 Back of the envelope
These are rough sums, the kind a candidate does at a whiteboard in a few minutes. Every number is our own assumption.
| Number | How we get it | Result | What it decides |
|---|---|---|---|
| Searches | Normal day: 600 million รท 86,400 s โ 6,900 a second. Black Friday after 06:00, after the Gateway blocks bots: we plan for 100,000, about 14 times that. The Result cache answers 40 in 100, so 100,000 ร 60% reach the index | 100,000 a second, 14 times the average; 60,000 reach the index | Size for the 06:00 hour. L1 must not be personal, so its answers can be shared |
| Shards | One shard holds about 3 million products, about 1.5 GB of vectors, as the retrieval deep dive shows. 60 million รท 3 million = 20. Every search that reaches the index asks all 20: 60,000 ร 20 | 20 Tier A shards; 1.2 million shard requests a second | Shard requests are the first bottleneck. The other 440 million products go in a second tier, asked only sometimes |
| Rank every candidate carefully? | 10,000 candidates (500 from each of 20 shards) ร 20 ยตs = 200 ms of CPU a search; ร 100,000 a second | 20,000 cores, just for scoring | A cheap L1 first, inside each shard; the careful L2 only on the best 1,000 |
| Filter stock after ranking? | #2280 carries 120,000 of Tier A's 60 million, 1 in 500; 1,000 รท 500 | about 2 of the top 1,000 left | Stock is filtered inside each shard, before the search |
| Stock changes | 2 billion a day รท 86,400 s; ร 10 after 06:00 | 23,000 a second; 230,000 after 06:00 | Too many to rewrite documents. Stock lives beside the documents, in memory |
| A large language model (LLM) per search? | About 300 ms a query, against 20 ms for the whole step that reads the words: 300 รท 20 = 15. And 100,000 ร 0.3 s = 30,000 queries would be in flight at once | 15 times too slow | The LLM works only at night, to fill the Query cache |
| Product graph | 100 million products ร at most 50 links = 5 billion links; ร 6 bytes a link = 30 GB, + 1.6 GB of offsets | 5 billion links, about 32 GB | One machine holds the whole graph, so a walk needs no network |
| Recommendations through search? | our planned 250,000 row requests a second ร 20 shards | 5 million shard requests a second | Rows get their own stores, not the index |
A ยตs is a millionth of a second.
What these numbers tell us: the hard parts are shard requests and ranking work, not data size. And stock must be filtered inside the index, because it changes faster than people search.