Content Community Feed and Favorites System: Architecture Design and Practice
This article presents a platform-agnostic design for the activity feed and favorites features common to content community products. It covers requirement boundaries, a layered architecture split across access, domain services, asynchronous events and multiple storage types, the data models for activity events, timelines and favorite items, the write and read paths including fan-out strategies and cursor pagination, cache and hot-spot governance, eventual consistency with reconciliation jobs, and permission filtering plus observability. It is intended as a practical baseline framework for developers building highly available feed and favorites capabilities.
In content community products, “feed” and “favorites” often look like nothing more than two entries on a page. Behind them, however, sit hard engineering problems: content publishing, relationship-graph aggregation, permission filtering, counter synchronization, cross-client consistency, and pagination over massive datasets. This article is not tied to any specific platform. Instead, it abstracts these features into a general technical topic and lays out an implementable design from the angles of requirement boundaries, architecture modules, data models, read and write paths, cache governance, consistency guarantees, and observability.
1. Requirement Boundaries and Core Challenges
The core goal of an activity feed is to let users efficiently obtain the latest changes from the accounts they follow or the content they are interested in. It typically takes several forms: the following feed, the recommendation feed, per-profile activity, and hot-topic aggregation. On the write side, the system must record events such as content publication, deletion, modification, and visibility changes. On the read side, it must perform candidate recall, permission filtering, deduplication, ranking, and stable pagination. A feed is not a simple “query in reverse chronological order”; it is an aggregated result derived after separating the write model from the read model.
Favorites, in turn, are a persistence-and-marking capability over polymorphic content objects. The object may be an article, a video, a Q&A entry, or a comment; a favorite may belong to a different folder and may be private or public. Favorites must also support counters, un-favoriting, batch queries, cross-client state synchronization, and idempotent handling. The difficulty lies in the fact that favorite records and content summaries may live in different services, counter updates are usually asynchronous, and permissions plus takedown status must be filtered in real time at read time.
Taken together, the main challenges of this class of system include: cache and pagination pressure caused by a read-heavy, write-light workload; traffic spikes caused by hot content and by high-follower accounts publishing; eventual consistency between favorite state and counters; correction of the read model after permission changes; and archiving plus capacity planning under long-term data growth.
2. Overall Architecture and Module Breakdown
A layered architecture of “access layer + domain services + asynchronous events + multiple storage types” is recommended. The access layer handles authentication, rate limiting, parameter validation, and canary routing. The feed service handles event recording, timeline construction, and read aggregation. The favorites service handles favorite records, folders, and state changes. The content service supplies object metadata and permission information. The relationship service supplies follow relationships. The counter service maintains derived metrics such as favorite counts and activity counts.
Storage is split by responsibility: a relational database holds core metadata such as activity events, favorite records, and folders; object storage can hold larger content snapshots or export files; a distributed cache carries hot feeds and favorite state; a message queue decouples publication events, counter updates, and index building; and logging plus monitoring and alerting services provide observability into system health. When deploying on the cloud, you can select from general-purpose offerings such as the object storage, message queue, container platform, logging, and monitoring and alerting products provided by Baidu AI Cloud, though the concrete choice still has to be evaluated against business scale.
The overall data flow should follow the principle of separating the write model from the read model: the write path prioritizes persisting core metadata and reliably delivering events, while the read path serves low-latency queries through asynchronously built timelines, caches, and indexes.
3. Data Model Design
The activity event table can be designed as dynamic_event(id, author_id, object_type, object_id, action, visibility, created_at, version), where action denotes the operation (publish, delete, modify, and so on) and version prevents an older event from overwriting a newer state. The timeline table can be designed as timeline_entry(user_id, cursor, object_id, score, source, deleted), where cursor is composed of a timestamp and the object ID, and source identifies whether the entry comes from the following feed or the recommendation feed.
The favorite record table can be designed as favorite_item(user_id, object_type, object_id, folder_id, state, created_at, updated_at, idempotency_key). Here state indicates active or cancelled, and idempotency_key enables idempotent writes. The folder table stores name, visibility, and ordering; the counter table stores the per-object favorite count together with a version number. To control data growth, deletes should prefer soft deletion or state transitions, with an archiving job migrating cold data.
It is worth emphasizing that the uniqueness constraint on favorite records should be built around “user + object type + object ID” to prevent duplicate favorites, and that a change of folder ownership should record an update timestamp to make incremental synchronization easier.
4. Write Path: Publishing an Activity and Favoriting
When publishing an activity, first validate the content state and visibility, then write the activity event and an outbox event in the same transaction, after which an asynchronous consumer builds the timeline. Timeline construction can use write fan-out, read fan-out, or a hybrid model: for active users, fan out to an inbox; for long-tail users, pull from the outbox at read time and aggregate, balancing write amplification against read latency.
Favorite writes need careful idempotency handling. Pseudocode:
def add_favorite(user, obj, idem_key):existing = find_by_idempotency_key(idem_key)if existing != null:return existing.statusbegin_transaction()item = find_by_user_and_object(user, obj)if item == null:insert_favorite_item(user, obj, state=active, idem_key)else if item.state != active:update_favorite_item(item, state=active)append_outbox_event("favorite_changed", user, obj)commit_transaction()return ok
Un-favoriting should likewise write an event rather than merely deleting the record. After consuming the event, the counter service increments or decrements the count asynchronously, using the version number to avoid out-of-order application. If a counter update fails, retries and a reconciliation job should act as the safety net instead of making the main favorite path wait synchronously.
5. Read Path: Feed and Favorites List
Reading a feed is usually divided into four steps: candidate recall, permission filtering, deduplication and ranking, and cursor pagination. Candidates may come from the inbox, the outbox, a hot pool, or a recommendation pool. Permission filtering must be executed at read time so that deleted, taken-down, or unauthorized content never appears in results. Ranking can use time, popularity, or a composite score, but the cursor must be stable, and large-offset pagination should be avoided.
Reading a favorites list should first filter by folder and state, then batch-fetch content summaries and apply permission filtering. Pseudocode example:
def list_favorites(user, folder, cursor, limit):rows = query_favorites(user, folder, cursor, limit + 1)has_more = len(rows) > limitrows = rows[0:limit]summaries = batch_get_content_summaries(rows)visible = filter_by_permission_and_status(summaries)next_cursor = build_cursor(rows[-1]) if has_more else nullreturn visible, next_cursor
The cursor should encode both the sort field and a unique ID, so that pagination neither duplicates nor skips items sharing the same timestamp. For favorite-state queries, a short-TTL cache can be used, with active invalidation triggered by favorite change events.
6. Caching and Hot-Spot Governance
Both feeds and favorite state are clearly read-heavy and write-light, which makes them suitable for multi-level caching. A local cache can hold extremely hot data, while a distributed cache holds data shared across instances; hot-spot detection identifies scenarios such as a high-follower account publishing or a piece of content being favorited in a concentrated burst. Cache design should include null-value caching, randomized TTLs, active invalidation, and fallback strategies to avoid cache penetration and cache avalanches.
Counter caches must be reconciled against the detail records. A favorite count can be read from cache first and fall back to the counter table on a miss; the counter table is maintained by asynchronous events and periodically calibrated by aggregating the detail records. For hot content, request coalescing, queue-based peak shaving, and read fan-out caching can reduce pressure on the backend.
7. Consistency and Reconciliation
Eventual consistency is the usual choice between favorite details and favorite counts. The event outbox guarantees the atomicity of persisting business data and delivering the event; consumers process idempotently by business primary key and reject stale events via the version number. A reconciliation job can periodically aggregate favorite details per object, compare them with the counter table, and correct and alert on any deviation.
The feed read model needs consistency guarantees as well: events such as content deletion, permission changes, and author bans should trigger timeline correction; if correction is delayed, the read stage must still apply permission filtering as a fallback. Reconciliation should look beyond counters to the proportion of invalidated entries in timelines, the pagination duplication rate, and the cache hit rate.
8. Permissions, Privacy, and Observability
Permission filtering must run through both the read and write paths. Folder privacy, content visibility scope, and takedown status all have to be validated before returning data, so that cached data cannot be used to exceed permissions. Audit logs should record key state changes, and sensitive operations require least-privilege control.
For observability, monitor interface QPS, P99 latency, cache hit rate, message backlog, consumption lag, counter deviation, and pagination duplication rate; use structured log fields; and cover publishing, favoriting, counting, and read aggregation with distributed tracing. Capacity planning should be estimated by read amplification factor, together with an archiving strategy for cold data.
9. Summary
The design principles for a feed and favorites system can be summarized as: separation of read and write, event-driven processing, idempotent writes, cursor pagination, eventual consistency, and observability. First define the functional boundaries, then design the data model and the read and write paths, and finally improve stability through caching, reconciliation, and permission fallbacks. For content community developers, this general design can serve as the baseline framework for building highly available feed and favorites capabilities.
