DEV Community

Cover image for An Interviewer Asked Me How Amazon Recommends Products Without Login
Anita Kapal
Anita Kapal

Posted on

An Interviewer Asked Me How Amazon Recommends Products Without Login

Recently in an interview I was asked one interesting question:

How does a platform like Amazon recommend products to user when user is not logged in?

I answered something like:
Amazon can use cookies to identify user and also when users search for products Amazon saves that information in key-value format like this product is searched by many users and recommends based on that

After the interview, I kept thinking about it my answer was not completely wrong but I felt that the interviewer was expecting something more. So I searched for it and learned more about it. This is how I will answer the same question now.

My Original Answer

Even if the user is not logged in, Amazon can store an anonymous user in this browser using cookies or local storage.
For example:
anonymous_user_abc123 searched "wireless mouse" anonymous_user_abc123 viewed "Logitech

yes cookies or session IDs are part of the answer, but the more important question is:
After identifying an anonymous session, how amazon decide what to recommend?

What I Missed

A better answer should include these parts:

  1. Anonymous user tracking
  2. Session-based behaviour
  3. Item-to-item recommendations
  4. Merging anonymous activity after user login

Let me explain each one
1. Anonymous User Tracking
Even without login Amazon can create a temporary anonymous profile based on:
cookie ID
session ID
device/browser information
IP-level location
current browsing history

For example if i open Amazon and search for "running shoes" then click on some few products like Nike and Adidas shoes, Amazon can understand this anonymous user session is interested in running shoes related products.
So the system will build a short-term profile like:

anonymous_user_abc123:
interested_categories: shoes, fitness searched_terms: running shoes viewed_products: Nike shoes, Adidas shoes possible_intent: buying sports shoes

This profile is temporary, but it is still useful

2. Session-Based Recommendations

For a user who is not logged in, Amazon will be depend on the current session. That means latest user actions become very important.

For example:
User searches: "iPhone 15 case"
User views: transparent iPhone case

Now Amazon can recommend products:
MagSafe charger
screen protector
phone stand

This is called session based recommendation system does not know the user but based on what this session is doing right now, these products are more relevent.

3. Item-to-Item Recomendations

This is probably the most important thing I missed in my interview answer. Amazon does not always need a full user profile to recommend products. Sometimes, the current product itself is enough.

For example, if a user is viewing an iPhone, Amazon can recommend:
iPhone case
screen protector
charger

Why?
Because many users who viewed or bought an iPhone also bought these related products. This is understood as item-to-item collaborative filtering. Instead of asking "What does this user like?" System asks, " What products are related to the product this user is currently viewing?"
So even if the user is anonymous, Amazon can still recommend products based on product relationships.

This is where my original answer was weak.
I said this product has been searched by many users. But a better answer to say is: Amazon can use aggregate behavior from many users to build relationships between products, such as "frequently bought together," "customers also viewed," and "similar products."

4. What Happens After Login?
One good point to mention in an interview is profile merging.
Later, when the user logs in, Now Amazon may connect that anonymous session activity with the logged-in account. So the temporary anonymous behavior can become part of the user’s long-term recommendation profile.
This is useful because the system does not lose the user’s intent just because they started browsing before login

Final Learning

The main thing I learned from this interview question is that in system design or backend interviews, we should not stop at one keyword.

Saying "cookies" was not wrong, but it was incomplete.

A better answer connects multiple parts:
anonymous identification
event tracking
session behavior
item similarity
profile merging

This question also taught me that recommendation systems do not always need a logged-in user.
A lot can be done using the current session and aggregate behavior from other users.

So next time, instead of answering only from the storage perspective, I will answer from the complete system perspective.
And that is the difference between a partially correct answer and a strong interview answer.

Top comments (0)