Practice/Roblox/Design a Like/Unlike Feature
System DesignMust
Design a system that allows users to favorite and unfavorite items, check whether they have favorited a specific item, view the total favorite count for any item, and browse their personal list of favorited items. This pattern appears everywhere -- liking posts on social media, favoriting products on e-commerce platforms, or bookmarking games on Roblox.
While the user interaction is simple (tap a heart icon), the backend must solve complex distributed systems problems at scale. When a viral item receives millions of favorites in minutes, a single database row tracking the count becomes a write bottleneck. The system must handle concurrent updates without losing data, serve read-heavy traffic (users checking favorite status and counts) with sub-50ms latency, and store billions of user-item relationships efficiently. You also need to prevent a user from favoriting the same item twice, even when retries and network issues cause duplicate requests.
Interviewers use this question to evaluate your understanding of high-throughput data modeling, counter sharding for hot keys, caching strategies with tight consistency requirements, and idempotent write operations.
Based on real interview experiences, these are the areas interviewers probe most deeply:
You need an efficient representation of the many-to-many relationship between users and items that supports fast lookups in both directions: "did user X favorite item Y?" and "what has user X favorited?"
Hints to consider:
(userId, itemId) for O(1) status lookups, and maintain separate aggregate count records per itemWhen a popular item receives millions of favorites in minutes, a single counter row becomes a write bottleneck. Naive increment operations will cause lock contention and cascading failures.
Hints to consider:
INCRBY) first, then flush to durable storage in batchesWith 2 million read QPS, nearly all traffic must be served from cache, but stale counts frustrate users and stale favorite status causes confusing UI states.
Hints to consider:
INCRBY and DECRBY for real-time count updates in the cache layer to minimize staleness windowsNetwork retries, double-taps, and multi-device usage can cause duplicate favorite requests. Your system must handle these without corrupting counts.
Hints to consider:
NONE to FAVORITED, FAVORITED to NONE) rather than blind increment/decrement operationsuserId, itemId) to prevent duplicate records regardless of retry behaviorConfirm the scope and constraints with the interviewer. Ask about the read-to-write ratio and peak traffic profile. Clarify how fresh favorite counts need to be (5-second staleness is typical). Verify that users must see their own favorites reflected immediately (read-your-writes consistency). Estimate the data cardinality: how many users, how many items, and how many total favorites over time. Ask whether the system should support batch favorite checks (e.g., "which of these 20 items has user X favorited?") for rendering feed pages efficiently. Clarify if counts are public and whether there are privacy or rate-limiting concerns.