Design a Like/Unlike Service
Design a desired-state like service with repairable counts, a concrete schema and Redis key layout, and retailer, search and brand product views.
Problem statement
For this exercise, assume an authenticated user can like a durable content item, remove that like, and read both their current like state and the item's aggregate like count. Unlike means removing the user's existing like; it is not a separate negative reaction.
A retried command must preserve the requested final state and must never create more than one active like for the same user and item. The user's accepted like state is durable immediately, while the aggregate count may lag accepted changes by up to five seconds.
Design for highly skewed traffic in which one item can become hot. Interviewers expect detail here: be ready to give a concrete storage schema, the Redis key design, and the query pattern behind each read and write.
Exclude dislike reactions, reaction types, lists of users who liked an item, comments, recommendations, item creation or deletion, and active-active multi-region writes. For this exercise, assume an existing marketplace catalog identifies products and their current owning brand.
A retailer is an authenticated user: it can also page through its currently liked products and see aggregate like counts beside authorized product search results. A brand operator can inspect aggregate counts for products that the catalog currently says its brand owns.
The source calls the removal action dislike; here it means removing an existing like, not a separate negative reaction. These additional product views do not replace the existing general user/item API. Catalog ownership and caller authorization must be checked for a brand view; a cached like count cannot grant access.
Each returned count carries its projection version/as-of state, and a stale or unavailable projection must be explicit. The catalog/search service supplies product metadata and search hits; building search, catalog writes, purchases, brand-wide totals and identifying individual likers remain outside scope.
What to build
- An authenticated user can set an item's desired state to liked or not liked, with duplicate and retried requests producing one stable result.
- A client can read the caller's current like state and a freshness-labeled aggregate like count for an item. Authorized product-search hits can be hydrated in a bounded batch with the same count/freshness contract.
- A retailer can page through its currently liked products without receiving another retailer's relationship state.
- A brand operator can inspect freshness-labeled aggregate counts for products currently owned by that brand, with catalog-backed authorization.
At scalePractice assumption
- 20 million daily active users generate up to 100,000 like or unlike requests per second across the service.
- Item pages generate up to 1 million like-state and count reads per second, and one hot item can receive 10,000 mutations per second.
- An accepted desired-state mutation is durable, mutation latency should stay below 300 milliseconds at p95, and aggregate counts should include accepted changes within five seconds.
- Count reads may return a versioned cached projection, but counts must never become negative and a repair must be derivable from authoritative per-user like state.