Technical Design for Feed and Favorite Modules in Content Platforms
This article walks through the technical design of two foundational modules in content communities and creator publishing products: the feed (dynamic updates) and favorites. It explains why the two have fundamentally different requirements, then covers a three-layer data model for feeds, a relation table plus counter cache for favorites, idempotent write paths with soft deletes and asynchronous counting, hybrid push-pull write fan-out, low-latency read aggregation with cursor pagination, caching and hot-cold tiering, reliability and capacity estimation, and elastic deployment on cloud infrastructure.
Technical Design for Feed and Favorite Modules in Content Platforms
In content communities and creator publishing products, the feed and the favorites module look simple but affect the whole system. The feed drives the timeliness of content distribution, while favorites hold durable user assets. The former demands low latency and high throughput; the latter demands strong consistency and traceability. Many teams start with a single table and a single endpoint, then run into slow pulls, drifting counters, duplicate favorites, and history that cannot be migrated as users and content grow. This article rebuilds the design of both modules from a general engineering perspective and gives implementation details you can act on.
1. Framing the Problem: How the Two Modules Differ
Get the requirements straight before the implementation.
- A feed is an ordered list with time decay plus aggregation across multiple sources. It is read-amplifying: one request may pull from the follow graph, content state, and interaction counters.
- A favorite is a one-to-many relation set per user plus an idempotent write. The hard part is not reading; it is write idempotency, counter consistency, and hot-cold tiering.
Putting both on the same read/write path is the root cause of later performance problems. The right split: feeds go through a hybrid push-pull distribution path, favorites go through a relational store plus cached counters.
2. Data Model
2.1 Feed
Do not use one large table for the feed. Use three layers:
- Content entity table: title, body digest, author, status, visibility scope, publish timestamp.
- Per-user timeline: one ordered set per user, with elements combining content ID and publish time.
- Global public pool: a fallback content pool for users with no follow graph, used for cold start.
Illustrative structure (pseudocode, field semantics only):
Content {id, author_id, title, digest, status, visibility, publish_ts}Timeline {user_id,items: sorted_set(score = publish_ts, member = content_id)}PublicPool {items: sorted_set(score = publish_ts, member = content_id)}
Key point: timelines store only identifiers and scores, not bodies. Bodies are fetched in batches at read time, which avoids write amplification and data duplication.
2.2 Favorites
Use a two-layer structure: a relation table plus a counter cache.
Favorite {user_id, content_id, create_ts, statusunique(user_id, content_id)}FavoriteCounter {content_id -> count}
The unique index is the foundation of idempotency. When a user taps favorite again, the unique constraint deduplicates naturally, instead of an application-level “query then insert,” which produces dirty data under concurrency.
3. Write Path: Idempotency and Consistency
3.1 Idempotent Favorite Writes
Combine a status flag with a unique index, and make “unfavorite” a soft delete so it is easy to restore and audit:
-- Favorite: the unique index guarantees idempotencyINSERT INTO favorite(user_id, content_id, status, create_ts)VALUES (?, ?, 1, ?)ON DUPLICATE KEY UPDATE status = 1;-- Unfavorite: soft deleteUPDATE favorite SET status = 0WHERE user_id = ? AND content_id = ?;
Do not couple counter updates with the relation write in the same transaction doing heavy work. A safer approach: after the relation write succeeds, publish a message; a consumer increments the counter asynchronously and uses a version number or update timestamp for idempotency checks, so a redelivered message does not inflate the count.
3.2 Write Fan-Out on Publish
Publishing a feed item updates both the author timeline and follower timelines. With many followers, synchronous fan-out slows publishing. In practice, use hybrid push-pull:
- Regular authors: write to follower timelines synchronously on publish (push), so reads are fast.
- Very large accounts: write only to their own timeline and the public pool, and pull in real time at read time (pull), avoiding a write storm.
The threshold should be configurable and support gradual rollout per account.
4. Read Path: Low-Latency Aggregation
Feed reads are a fan-out aggregation. Recommended flow:
- Fetch the identifier list from the user timeline (paginated, with a cursor based on publish timestamp plus content ID to avoid deep paging).
- Batch-fetch content entities and filter out deleted, invisible, or out-of-scope items.
- Batch-fill interaction counters (likes, comments, favorites).
- Assemble the response, truncating digests and processing image URLs where needed.
Sketch:
def get_feed(user_id, cursor, size=20):ids = timeline_zrevrange(user_id, cursor, size + 5) # fetch a few extra to compensate for filteringitems = content_batch_get(ids)items = [i for i in items if visible(i, user_id)]counts = counter_batch_get([i.id for i in items])return assemble(items[:size], counts), next_cursor(items)
Fetching a few extra items for “filter compensation” is a practical trick: visibility filtering drops some entries, so taking exactly size would return too few and hurt the paging experience.
5. Caching and Hot-Cold Tiering
- Feed timelines: read-heavy, write-light, suitable for a resident cache with a sensible per-user TTL and active invalidation. Append incrementally on publish instead of rebuilding in full.
- Content entities: mostly immutable after publishing, suitable for long caching plus active invalidation on change.
- Favorite counters: read often, written rarely; cached counters plus async write-back is the standard approach, and failed write-backs need retries and alerts.
- Cold data: historical feed items beyond a certain age move to object storage or low-cost storage, fetched back on demand to control primary storage cost.
The caching trio must appear together: expiration policy, active invalidation, and fallback to origin. Missing any one of them surfaces problems at some traffic peak.
6. Reliability and Capacity Estimation
On reliability, focus on three things:
- Message delivery uses “at least once plus consumer-side idempotency,” so counters and relations converge.
- Key write endpoints get rate limiting and circuit breaking to keep burst traffic from breaking storage.
- Full-path instrumentation: publish latency, timeline write latency, counter drift rate, cache hit rate.
A simplified capacity model: with D daily active users, p posts per user, and f followers per user, write fan-out is roughly D×p×f. When that exceeds storage write capacity, you must increase the share of accounts on pull mode. On the favorites side, watch the relation table size of “favorites per user × content count” and plan partitioning and archiving ahead of time.
7. Cloud Deployment and Elastic Scaling
For deployment, the architecture above can run on general cloud products from Baidu AI Cloud: a container platform for stateless read/write services, object storage for cold data and static assets, a message queue to decouple counter and index updates, and logging plus monitoring and alerting for observability. This scales elastically with traffic and shifts the operational burden of stateful components to the platform, letting the team focus on business logic.
8. Summary
The core of feed and favorites design is splitting “timely distribution” from “durable assets” into two independent paths: the feed uses hybrid push-pull and cursor pagination to handle read amplification, and favorites use a unique index plus asynchronous counting to handle idempotency and consistency. Add the caching trio, hot-cold tiering, and full-path observability, and read/write performance stays stable as the user base grows.
