Designing Feed and Favorites Features: A System Design and Engineering Practice Guide
This article presents a practical engineering approach to designing "feed" (activity) and "favorites" (bookmark) features for content applications. It covers how to define business boundaries and design goals, model feeds and favorites correctly, structure data, implement idempotent and atomic favorite writes with consistent counters, handle pagination and stable sorting, manage caching and consistency trade-offs, address privacy and abuse prevention, test concurrency and monitor correctness, and roll out the system in stages to avoid premature complexity. Readers will gain a field-tested methodology for building reliable user-content relationship systems.
1. Define the Data Boundaries and Design Goals First
The original source material for this article contained only two UI terms—“feed/activity” (动态) and “favorites” (收藏)—with no identifiable article title, technical description, or implementation details. This article therefore does not infer the original product’s capabilities, nor does it attribute the following content to the original page. Instead, it uses the generic functionality these two terms represent as a starting point for a set of engineering design methods suitable for content-oriented applications.
In typical products, a “feed” displays content updates or user actions, while “favorites” establish a long-term saved relationship between a user and content. Both involve content, but they differ significantly in data semantics, lifecycle, and access patterns.
The first step in design is not to immediately add API endpoints or database fields, but to answer three questions:
- Does the feed display the content itself, or events such as publishing and updating content?
- Does a favorite store a reference to the content, or a snapshot of the content at the time of favoriting?
- When content is deleted, hidden, or has its permissions changed, how should the feed and favorites behave?
These questions directly affect the subsequent data structures and consistency strategy. When the business semantics are unclear, more complex technical implementations usually lead to higher rework costs later.
2. Separate the Business Models for Feed and Favorites
1. Feed: Distinguish Current State from Historical Events
A feed can use two basic models.
The first is a content-list model. The system displays currently accessible content ordered by publish time or update time, with each list item directly referencing a content record. It is relatively simple to implement and suits scenarios like “recently published” or “recently updated.”
The second is an event model. The system records facts such as “content published” or “content updated,” then converts these events into displayable feed items. It suits businesses that need to express the process of actions, but it must handle duplicate events, ordering changes, and changes to the referenced object’s state.
For example, a historical “content was published” event may still exist while the corresponding content has been deleted. The existence of the event must not cause the original content to be shown to users without permission. Events describe historical facts; content permissions define the current access boundary. The two must be evaluated separately.
If there is no clear requirement for historical traceability, do not introduce complex event pipelines for the sake of formal completeness. Preferring the minimal model that meets the business goal is better for maintainability and troubleshooting.
2. Favorites: Separate Relationships from Statistics
The core of favorites is not a counter field, but the relationship between a user and content.
At minimum, the following states should be clearly defined:
- The user has not favorited the content;
- The user has favorited the content;
- The user has actively unfavorited the content;
- The favorited object is currently inaccessible.
“Inaccessible object” does not have to be treated as “favorite relationship deleted.” For a user’s personal list, you can keep a sanitized placeholder indicating the content is unavailable, or hide the item according to business rules. Whichever approach you choose, keep the rules consistent.
The favorite count is an aggregate result and cannot replace the relationship table. Whether a specific user has favorited a piece of content must be determined from the favorite relationship itself, not inferred from the total count.
3. Build a Clear Data Structure
The following fields illustrate a generic data model only; they do not represent any actual product interface or existing implementation.
1. Content Record
A content record may include:
- Content ID;
- Author ID;
- Current status;
- Visibility scope;
- Creation time;
- Update time;
- Version number.
The content status expresses the lifecycle (normal, hidden, deleted, etc.), while the visibility scope expresses access rules. Keep these two dimensions separate; avoid using a single field to carry multiple meanings.
2. Favorite Relationship
A favorite relationship may include:
- User ID;
- Content ID;
- Favorited time;
- Relationship status;
- Last modified time.
If you adopt a scheme that stores only active favorites, apply a unique constraint on the combination of “user ID + content ID” to prevent the same user from favoriting the same content twice.
If you adopt a scheme that retains un favorite records, you must define a uniqueness rule for the active state and ensure that re-favoriting updates the existing relationship instead of repeatedly producing semantically duplicate data. The specific constraint mechanism should be chosen based on the capabilities of your storage system.
3. Feed Event
When using the event model, you may record:
- Event ID;
- Acting subject;
- Associated object;
- Event type;
- Occurrence time;
- Necessary display information.
Display information should follow the principle of minimization. Do not copy the full body text, private profiles, or access credentials into event records just to save one query. The more redundant data you store, the more copies you must handle during permission changes, deletions, and data cleanup.
4. Favorite Writes: Prioritize Idempotency and Atomicity
1. Avoid Making “Toggle State” the Only Operation
A “toggle favorite” API seems convenient, but it becomes ambiguous under network timeout retries: the first request may have succeeded, and the client sends it again because it never received a response—resulting in the favorite being unintentionally removed.
A more robust design is to submit the target state, for example “set as favorited” or “set as not favorited.” Repeatedly submitting the same target state must not repeatedly change the relationship or increment the counter.
An illustrative flow:
ProcessFavoriteRequest(current_user, content_id, target_state):Validate the current user's identityCheck content access conditions according to the operation typeBegin transactionAtomically adjust the favorite relationship to the target stateDetermine whether the active relationship actually changedIf it actually changed:Record the corresponding changeCommit transactionReturn the current active favorite state
The key here is “atomically adjust.” You cannot first read whether the relationship exists and then insert or delete it without concurrency protection; otherwise, multiple requests may pass the check simultaneously.
2. Counter Updates Must Be Bound to Actual State Changes
Only when the relationship transitions from not favorited to favorited should the active count increase; only when it transitions from favorited to not favorited should the count decrease.
Repeated favorite requests must not increase the count, and repeated unfavorite requests must not decrease it. Otherwise, even if the relationship table contains no duplicates, the counter can still drift due to retries.
When the business allows it, you can maintain the relationship and the counter in the same transaction. As write volume grows, you can maintain statistics asynchronously via change events, but you must accept short delays and provide periodic reconciliation and repair mechanisms. The async pipeline must also guarantee reliable event production and handle duplicate consumption; simply sending a message after the transaction commits is not sufficient.
3. Permission Checks Should Adapt to the Operation’s Purpose
Adding a favorite typically requires that the content is currently accessible. Unfavoriting, however, should not mechanically require the user to still have access to the original content—otherwise, if the content becomes private, users might be unable to clean up their own favorites list.
A sensible boundary is: users can delete their own favorite relationships, but must not be able to use this as a way to read details of content they no longer have permission to access.
5. List Reads: Pagination, Batch Queries, and Stable Sorting
1. Use Deterministic Sorting Rules
Sorting by time alone can produce unstable results, because multiple records may share the same timestamp. You can use a combined sort of “time plus a unique identifier” to establish a deterministic order for records with identical times.
When a feed or favorites list changes continuously, position-offset-based pagination can produce duplicates or omissions. For deep pagination or continuous-loading scenarios, consider cursor-based pagination built on the sort position.
The cursor should express the position of the last read record and include integrity verification. If the cursor contains user, filter conditions, or other context, also verify that it matches the current request. Never treat a client-supplied cursor as trusted authorization data.
2. Avoid Per-Item Queries for Content and Permissions
List reads can be split into two steps:
- Query one page of feed records or favorite relationships;
- Batch-fetch the associated content, author information, and data needed for permission checks.
Per-item lookups can turn a single list request into a large number of internal calls, increasing latency and resource consumption. After a batch fetch, the results must still be reassembled in the original order, because batch queries may not return records in list order.
3. Define Pagination Semantics After Filtering
After a page of relationship records passes permission checks, only a small number of items may remain visible. The system must clearly define whether it will:
- Return fewer than a full page of valid results;
- Continue reading subsequent records to fill the page;
- Display safe placeholder items for invalid entries.
If you choose to fill the page, set a scan limit to prevent a large number of invalid records from causing an unbounded read in a single request. Whether or not you fill the page, the next cursor should advance past the scanned position; otherwise, the same batch of invisible data may be scanned repeatedly.
6. Caching and Consistency: Define the Tolerance First
Caching can reduce repeated reads, but it cannot replace authoritative data, nor does it automatically solve consistency problems.
Different data can have different consistency requirements:
- The current user’s favorite operation results should be reflected promptly;
- Aggregate favorite counts may lag briefly, if the business allows;
- Content permissions and deletion status should use stricter invalidation controls;
- Feed list refresh rates can be set according to business timeliness requirements.
After a successful favorite, the service can directly return the confirmed state so the UI updates immediately, rather than immediately depending on a list cache that may not have refreshed yet.
Caching of personal favorite status must include the user dimension. Public content information and private user relationships must not share cache entries indiscriminately. For permission-controlled content, avoid skipping necessary access checks just because of a cache hit.
When operations such as narrowing visibility or taking sensitive content offline occur, prioritize ensuring that the content is no longer incorrectly displayed, rather than prioritizing cache hit rate.
7. Privacy, Abuse Prevention, and Lifecycle Management
Favorite behavior may reveal user interests and must not be treated as public by default. The system should clearly define whether favorite lists are public, who can view them, and whether users can change their visibility scope.
Feeds also must not automatically make all actions public. Whether edits to private content, private favorites, and restricted interactions generate visible feed items should be determined by explicit business rules.
Security design should at least cover:
- Validate the current identity on every write operation;
- Perform object-level permission checks server-side;
- Users can only manage their own favorite relationships;
- Set reasonable rate limits on high-frequency writes;
- Avoid logging tokens, full sensitive body text, and unnecessary personal information;
- Handle related relationships, caches, and derived data according to established rules when an account is deleted.
Content deletion also requires distinguishing between business-level invisibility and physical data cleanup. If there are explicit data-deletion requirements, event records, search indexes, caches, and other copies must be included in the scope of processing—not just changing the main table’s status.
8. Testing and Monitoring: Verify the Exception Paths
1. Functional and Concurrency Testing
Beyond normal favoriting and unfavoriting, you should also verify:
- The same target state submitted repeatedly;
- Retries after request timeouts;
- Multiple devices modifying favorite state concurrently;
- Content being deleted or having permissions changed during the operation;
- Whether users can unfavorite after the target becomes invalid;
- Whether pagination is stable for records sharing the same timestamp;
- Whether large volumes of invisible records cause abnormal scanning.
In concurrency scenarios, the effective order of conflicting target states must be determined by server-side processing order or an explicit versioning mechanism. Do not promise “the client’s last click always wins” if the system cannot guarantee it.
2. Operational Monitoring and Data Reconciliation
Monitoring should cover not only error rates and response times but also business correctness, for example:
- Favorite write success rate;
- Proportion of duplicate requests;
- Ratio of invalid objects in lists;
- Async change-processing delays;
- Discrepancies between relationship counts and aggregate counts;
- Permission-denial counts and abnormal fluctuations.
Data reconciliation tasks should be able to detect and repair counter drift, but the repair process must also avoid overwriting new changes produced concurrently. Where necessary, ensure safe repair through batching, versioning, or controlled recomputation workflows.
9. Roll Out in Phases; Avoid Premature Complexity
In the early stage, adopt a clear content-record and favorite-relationship model, and implement idempotent writes, stable pagination, and permission checks on top of reliable transactions and uniqueness constraints.
Only after real monitoring shows that read pressure, statistics lag, or feed distribution cost has become a bottleneck should you gradually add caching, message queues, read/write splitting, or dedicated search capabilities. Every component you introduce should have a clearly defined problem it solves and a well-defined recovery path when it fails.
The reliability of feed and favorites features ultimately depends on whether the business boundaries are clear, whether state changes are repeatable, whether permissions are enforced throughout the read pipeline, and whether the system can recover from failures. Get these fundamentals right first, then scale based on real load—this is usually more robust than stacking a complex architecture from day one.
