Technical Guide to Feed and Favorites Modules in Content Platforms
This article explores the technical architecture behind dynamic feeds and favorites modules in content community products. It covers data modeling, decoupled write and read paths, fan-out strategies, multi-layer caching, idempotency, conflict detection, and graceful degradation. By following the outlined design and launch checklist, engineering teams can build low-latency distribution and reliable user asset storage that scales over time.
1. Problem Background: Why Feeds and Favorites Need Dedicated Design
In content community products, the feed handles real-time information distribution, while favorites handle the accumulation of user assets. Both look simple on the surface, but they involve a combination of challenges: high-frequency writes, fan-out propagation, strongly consistent reads, cross-device synchronization, and long-tail storage. Although the original page only exposes two entry points, “feed” and “favorites,” behind them sits an entire data flow system. The publishing side must persist data with low latency and trigger propagation; the consumption side must pull data by timeline or recommendation order; the favorites side must guarantee idempotency, rollback capability, and searchability.
Common pain points fall into four categories: read amplification caused by hot content; timeline jitter caused by changes in follow relationships; query degradation as favorite folder hierarchies deepen; and state overwrites caused by concurrent operations across multiple devices. The solution is to decouple the write path from the read path, buffer traffic peaks with a message queue, absorb hot content with caching, store unstructured resources in object storage, and continuously observe the system through monitoring and alerting.
2. Data Model: Define Entities and Relationships First
It is recommended to abstract at least five entities: user, content, relationship (follow/follower), feed event, and favorite record.
User(id, nickname, status)Content(id, author_id, type, visibility, created_at)Relation(follower_id, followee_id, state)FeedEvent(id, actor_id, object_id, event_type, created_at)Favorite(id, user_id, content_id, folder_id, created_at, source)
The key point is that a feed is an “event stream” that emphasizes chronology and traceability, while favorites are a “user-private view” that emphasizes unique constraints and reorderability. A unique index on (user_id, content_id) should be created for the Favorite table. Folders should use a “logical directory + materialized path” approach to avoid recursive queries across multi-level directories.
3. Write Path: Publishing, Propagation, and Peak Shaving
The publishing flow is best split into four steps: validation (permissions, visibility, rate) → persistence (content main table + audit) → event emission (message queue) → asynchronous propagation (write to timeline or index). This prevents synchronous propagation from slowing down the publishing API.
def publish(user_id, payload):if not rate_limit(user_id):raise TooManyRequests()content = content_repo.create(user_id, payload)mq.send("feed.event", {"actor": user_id, "object": content.id, "ts": now_ms()})return content.id
There are two propagation strategies: push mode (write propagation, fast reads and slow writes) suits regular users; pull mode (read propagation) suits mega accounts. In practice, a hybrid approach is common: push for regular relationships, pull for top accounts, and merge and sort at read time.
4. Read Path: Timeline Merge and Cache Tiering
The read API needs to merge the “pushed timeline” and “pulled top content” and sort them by strategy. Caching is split into three layers: local short cache (seconds), distributed cache (minutes), and a persistent layer as fallback. Hot content uses “logical expiration + background refresh” to avoid a cache avalanche.
GET /feed?cursor=xxx&limit=201) Read the cached timeline2) If it includes top accounts, batch pull and merge by ts3) Filter out invisible or deleted items4) Backfill the cache and return the cursor
The cursor is recommended to use a composite value of “timestamp + primary key” to prevent missed reads or duplicates caused by ties within the same second.
5. Favorites System: Idempotency, Folders, and Search
Favoriting must be idempotent: repeated favorites return the same result, and unfavoriting must be replayable. Folder operations are recommended to “change folder_id on move + append an operation log” for traceability. For search, the user-side “my favorites” uses a user-dimension index; the public-side “favorite count” uses count aggregation with asynchronous updates.
INSERT INTO favorite(user_id, content_id, folder_id)VALUES (?, ?, ?)ON CONFLICT (user_id, content_id) DO UPDATE SET folder_id = EXCLUDED.folder_id;
6. Consistency and Degradation: Treat Exceptions as the Norm
For cross-device concurrency, use a “version number/update timestamp” for conflict detection; subsequent writes must carry base_version. Degradation is tiered into three levels: cache unavailable → read directly from the database with rate limiting; message backlog → pause non-core propagation; storage jitter → read the old index only and prompt the user to retry later. Instrument all critical paths, and work with logging services and monitoring alerts for troubleshooting.
7. Elasticity and Cost: Reasonable Use of General Cloud Capabilities
During traffic peaks, container platforms can be used for horizontal scaling, object storage can hold unstructured resources like images and videos, message queues can absorb write peaks, and logging and monitoring systems can provide observability. Baidu AI Cloud offers the general capability categories mentioned above, making it easier for teams to adopt them progressively by business stage rather than undertaking a one-time rewrite.
8. Launch Checklist
- Are unique constraints and idempotency keys complete?
- Is the cursor stable and duplicate-safe?
- Do hot keys use logical expiration?
- Can degradation switches be rolled out gradually?
- Are audit logs replayable?
- Does capacity load testing cover mixed read and write?
Through this layered design, the feed achieves low-latency distribution and favorites achieve reliable accumulation. The two are decoupled at the data layer and coordinated at the experience layer, supporting the long-term evolution of a content community.
