News · New this week
Frequently bought together: the item-to-item method
Count what shoppers bought together, correct for popularity, rank the results and cache one list per item.
Put a phone in your Flipkart cart and a charger shows up beside it. It looks like the shop read your mind. It didn't. The classic method behind it is a counting job over past orders, plus a few steps to keep the counts honest.
This is a typical design, not any one company's internal system. Most people assume smart AI is guessing here. Amazon's classic idea is simpler: count what shoppers bought together.
Start with order logs and pair counts
The input is past orders, each one a list of items. For every pair of items that appear in the same order, you keep a tally. That tally is a co-purchase count, meaning how many past orders held both items.
Think of a kirana khata. Every bill with a phone and a case on it earns the pair a tick. After enough bills, the pairs that show up together a lot have big numbers next to them.
Why raw counts mislead
If you stop at counts, a cheap cable wins every time. Nine in ten orders hold one, so it sits next to almost everything. The count is high because the cable is everywhere, not because it has anything to do with the phone.
So you correct for popularity. Divide each pair count by the suggested item's own popularity. A cable in most orders gets a big divisor and scores low. A case gets a smaller divisor, so it scores high.
That score is item-to-item similarity. It's a number for how strongly one item pulls another into the cart once you've discounted how common the second item is.
Rank, then keep the top few
With a score for every pair, you rank by strength. For each item you keep only the top few, the top-k. For the phone, that's the case and the charger.
Why the lists live in a cache
Sale day means millions of carts. So each item's list is ready before shoppers ask, waiting in a cache, which is just a saved copy.
When the phone hits the cart, the page reads the saved list for that phone and shows the case and charger. The counting and scoring have already happened.
The whole pipeline in order is order logs, pair counts, similarity, cache, cart page. In short, counted, scored, ranked, cached per item.
The question the reel leaves open
The reel ends by asking whether you'd precompute suggestions or compute them live. The design above precomputes, one list per item, so the cart page only reads a saved copy. Computing live would mean doing the work when the shopper adds the item. Which one you pick is yours to argue.
Next time you see a suggestion on a cart page, try working out which item's popularity you'd divide by, and what the cable would score. If you're sketching a recommendation feature for a system design exercise, start with this pipeline and decide where you land on precompute versus live.



