Design a product likes system for a marketplace of brands and retailers
FaireSoftware Engineer · OnsiteLast updated
Design the backend for product likes on a marketplace where retailers like or dislike products, list the products they liked and see like counts in search results, while brands see the likes on their own products. Tests data modeling for two access directions, counter maintenance, idempotent writes and scaling the search read path.
Design the backend for product likes on a marketplace where brands list products and retailers browse them. The system must support four features:
- A retailer can like or dislike a product.
- A retailer can see the products they have liked.
- When a retailer searches, each product in the search results shows its likes.
- A brand can see the likes on each of its products.
Constraints and Clarifications
- Not given: the number of retailers, brands and products, like traffic, search traffic, and how fresh the counts must be. Ask, or state your assumptions.
- The source does not say whether "dislike" undoes a like or is a separate negative reaction. Settle it with the interviewer.
Clarifying Questions
- Does "dislike" mean removing a like, or a separate negative reaction that is stored and counted? Can a retailer hold a like and a dislike on the same product at once?
- In search results, does a retailer see only the like count, or also whether they themselves have liked each product?
- Does a brand see only counts, or also which retailers liked each product, and over what time period?
- Must counts be exact and update instantly, or may they lag by a few seconds?
- In what order are a retailer's liked products listed, and how long can that list get?
- What happens to likes when a product is removed or a retailer closes their account?
Hints
Hint 1
Two very different read paths: Listing one retailer's liked products and counting the likes on one product read the same facts in opposite directions. Decide what each path reads, and whether one table with the right indexes can serve both.
Hint 2
A results page asks about many products at once: A search page needs like information for dozens of products in a single request. Think about where those numbers live so that rendering a page never counts rows on the fly, and how fresh they really need to be.
Follow-up questions
- A popular product receives a sudden burst of likes. How do you keep its counter from becoming a write hotspot?
- Retailers want to sort search results by number of likes. What changes, given that the search index now depends on counts?
- A brand asks for likes over time, broken down by type of retailer. Do you query the main store, or build something else?
- After an outage, the counters and the reaction records disagree. How do you detect and repair the drift?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.