Designing Activity Feeds and Favorites for a Technical Content Platform

    This article presents a practical architecture for building activity feeds and favorites in a technical content platform. It covers requirement boundaries, data modeling, feed read and write paths, idempotent favorite operations, consistency strategies, pagination, performance, security, observability, and a phased implementation roadmap. The core approach is to keep relationship data strongly consistent while updating timelines, counters, search indexes, and notifications asynchronously with replayable events.

    Designing Activity Feeds and Favorites for a Technical Content Platform

    1. Background and Problem Definition

    A technical content platform typically consists of three areas: content production, content consumption, and user interactions. The Activity Feed aggregates content updates, author activity, and topic activity. Favorites provide users with a persistent way to save content, columns, or authors.

    Although these features appear simple, they involve several system-level challenges:

    • Read-heavy and write-heavy workloads with different characteristics
    • Short-term traffic spikes around popular authors or topics
    • Data consistency and eventual consistency
    • Access control and visibility filtering
    • Stable pagination
    • Duplicate operation prevention
    • Cache penetration and cache invalidation
    • Observability and fault diagnosis

    Activity feeds are generally read-heavy, while popular authors and topics can create short-lived bursts of concurrent reads. Favorites are core user relationship data. Their write volume may be relatively low, but operations must be idempotent, traceable, and safe for eventual counter updates.

    If the design focuses only on basic CRUD operations for a single table, the system may eventually experience duplicated favorites, inaccurate counters, unstable lists, cache penetration, and difficult-to-diagnose failures as the user and content bases grow.

    The activity feed and favorites modules should therefore be treated as two capabilities within a broader content interaction domain:

    • The activity feed aggregates and distributes events.
    • Favorites persist user-to-content relationships and manage their state.
    • Asynchronous events decouple the two capabilities.
    • Shared data models and observability standards improve maintainability.

    2. Requirements and Boundaries

    The functional requirements can be divided into the following areas.

    Activity Publishing and Aggregation

    The system should support publishing content, author activity, and topic updates into an activity pool. It should also support querying activity lists for individual users or defined scopes.

    Activity Consumption

    The feed should support:

    • Cursor-based pagination
    • Batch loading of content metadata
    • Filtering of unavailable content
    • Sorting by time or popularity

    Favorite Operations

    The system should support:

    • Adding and removing favorites
    • Querying a user’s favorites
    • Grouping favorites into folders
    • Batch querying favorite status

    Counters and Notifications

    Favorite counters and activity update notifications should be updated through asynchronous events. Short periods of eventual inconsistency are acceptable.

    Authorization and Moderation

    Private favorites must not be readable by other users. When content is removed or its visibility changes, both the activity feed and favorite lists must filter it correctly.

    Operations and Auditing

    Important operations should be logged for troubleshooting, reconciliation, and event replay.

    Non-functional requirements include low latency, scalability, idempotency, eventual consistency, observability, security, compliance, and recoverability.

    The data boundaries should be explicit:

    • Favorite relationships are core user data and require relatively strong consistency.
    • Activity feeds and favorite counters are derived data and can use asynchronous updates with eventual consistency.
    • Pagination must use stable cursors rather than traditional offsets to prevent duplicates and omissions while data changes.

    3. High-Level Architecture

    A layered architecture is recommended:

    • The access layer handles authentication, rate limiting, and parameter validation.
    • The application layer orchestrates API requests.
    • The domain layer separates activity, favorite, content, and counter services.
    • The storage layer uses a relational database for core relationships, a cache for hot reads, a message queue for event decoupling, a search service for retrieval, and object storage for media.
    • Logging, monitoring, and alerting provide observability.

    The overall flow can be represented as follows:

    1. Client
    2. -> Access Layer (authentication/rate limiting/validation)
    3. -> Application Services (activity APIs/favorite APIs)
    4. -> Domain Services (feed aggregation/favorite relationships/content metadata/counters)
    5. -> Relational Database / Cache / Search Service
    6. -> Message Queue -> Consumers -> Timeline Index, Counters, Notifications, Search Index

    The key principle is to keep core writes inside short transactions and process derived updates asynchronously.

    For example, a favorite request should synchronously write only:

    • The favorite relationship
    • The idempotency record
    • The event record

    It should not synchronously update remote counters or search indexes. This keeps write latency under control while allowing event retries and idempotent consumers to provide eventual consistency.

    Activity feed queries should prefer precomputed timelines or cached data. If required data is missing, the service can load content metadata from the source of truth.

    4. Data Model Design

    Core tables can be separated by domain:

    • The content table stores content identifiers, authors, types, states, publication times, and visibility.
    • The activity event table stores event sources and payloads.
    • The timeline table stores aggregated activity indexes by scope.
    • The favorite relationship table stores relationships between users and target objects.
    • The folder table stores favorite groupings.
    • The counter table stores derived counters.
    • The idempotency table stores operation keys and results.

    Example SQL:

    1. CREATE TABLE favorite_relation (
    2. id BIGINT PRIMARY KEY,
    3. user_id BIGINT NOT NULL,
    4. target_type VARCHAR(32) NOT NULL,
    5. target_id BIGINT NOT NULL,
    6. folder_id BIGINT,
    7. status SMALLINT NOT NULL,
    8. created_at TIMESTAMP NOT NULL,
    9. updated_at TIMESTAMP NOT NULL,
    10. idempotency_key VARCHAR(64),
    11. UNIQUE (user_id, target_type, target_id)
    12. );
    13. CREATE TABLE dynamic_event (
    14. id BIGINT PRIMARY KEY,
    15. actor_id BIGINT NOT NULL,
    16. event_type VARCHAR(32) NOT NULL,
    17. target_type VARCHAR(32) NOT NULL,
    18. target_id BIGINT NOT NULL,
    19. created_at TIMESTAMP NOT NULL,
    20. payload TEXT
    21. );
    22. CREATE TABLE timeline_entry (
    23. scope_id BIGINT NOT NULL,
    24. cursor_value BIGINT NOT NULL,
    25. target_type VARCHAR(32) NOT NULL,
    26. target_id BIGINT NOT NULL,
    27. source_event_id BIGINT NOT NULL,
    28. created_at TIMESTAMP NOT NULL,
    29. PRIMARY KEY (scope_id, cursor_value)
    30. );

    The unique constraint on favorite_relation prevents a user from creating duplicate relationships with the same target.

    The status field represents states such as active, removed, or deleted. An idempotency key ensures that retries return a consistent result.

    The timeline table uses the scope identifier and cursor value as its primary key, making reverse cursor queries efficient. Composite indexes should be created for frequently queried fields. At larger scale, data can be partitioned by user identifier or scope identifier to reduce partition hotspots.

    5. Activity Feed Read and Write Paths

    Common feed strategies include fan-out on write, fan-out on read, and a hybrid push-pull model.

    • Fan-out on write copies an activity into all follower timelines when it is published. Reads are fast, but writes can be heavily amplified.
    • Fan-out on read aggregates activity from followed objects or scopes during a query. Writes are lightweight, but reads are more complex.
    • Hybrid push-pull precomputes timelines for active scopes and reads from the source for long-tail scopes when needed.

    For a technical content platform, the hybrid model is often suitable because content update frequency is relatively controllable while the reader population may be large.

    The recommended flow is:

    1. A content update produces an activity event.
    2. The event is written to a message queue.
    3. A consumer validates event idempotency and updates timeline indexes and caches.
    4. The query API reads timeline entries using a cursor.
    5. Content metadata is loaded in batches.
    6. Removed or invisible content is filtered out.
    7. The API returns the next cursor.

    Example pseudocode:

    1. publish_event(actor, event):
    2. validate(actor, event)
    3. transaction:
    4. insert dynamic_event
    5. insert outbox_event(event_id)
    6. commit
    7. async publish outbox_event
    8. load_feed(scope, cursor, limit):
    9. validate(scope, cursor, limit)
    10. entries = timeline_store.query(scope, before=cursor, limit=limit+1)
    11. contents = batch_load_content(entries.target_ids)
    12. visible = filter(contents, status, visibility)
    13. return visible, encode_cursor(entries.last)

    A cursor should contain at least a timestamp and a unique identifier. Using only an offset can cause duplicate or missing items when the underlying data changes.

    For popular authors or topics, useful techniques include:

    • Caching hot pages
    • Request coalescing
    • Rate limiting
    • Graceful degradation
    • Asynchronous precomputation

    Long-tail activity can be loaded from the source on demand, avoiding the cost of maintaining complete timelines for every scope.

    6. Implementing Favorites

    Favorite APIs should be designed around a relationship state machine.

    • Adding a favorite changes the relationship to active.
    • Removing a favorite changes it to removed.
    • Repeated add operations return success without incrementing the counter again.
    • Repeated remove operations also return success.

    The client may provide an idempotency key. The service uses the unique constraint and idempotency records to make retries safe.

    Within one transaction, the service writes the relationship, the idempotency record, and the event record. Counters and notifications are processed asynchronously.

    Example pseudocode:

    1. add_favorite(user, target, key):
    2. if idempotency_exists(user, key):
    3. return previous_result
    4. transaction:
    5. insert favorite_relation(user, target, status=active)
    6. insert outbox_event(event_id, favorite_added)
    7. insert idempotency_record(user, key, success)
    8. commit
    9. return accepted
    10. remove_favorite(user, target, key):
    11. if idempotency_exists(user, key):
    12. return previous_result
    13. transaction:
    14. update favorite_relation set status=removed
    15. insert outbox_event(event_id, favorite_removed)
    16. insert idempotency_record(user, key, success)
    17. commit
    18. return accepted

    Favorite lists should be queried in reverse order by creation time using cursor pagination. Target metadata should be loaded in batches, and deleted or invisible content should be filtered.

    Folders are an optional dimension of the relationship. Changing a folder affects presentation but does not change the underlying favorite relationship.

    When the counter service consumes favorite events, it should use the event identifier for idempotency. Periodic reconciliation against relationship table snapshots can correct counter drift.

    7. Consistency and Concurrency Control

    Consistency should be layered according to data importance and query characteristics.

    Favorite relationships, idempotency records, and event records should be written in the same database transaction. This guarantees that a successful operation both persists the relationship and creates a retryable event.

    Counters, timelines, search indexes, and notifications are derived data. They can use eventual consistency through message retries, idempotent consumers, and reconciliation jobs.

    Concurrent requests may attempt to add and remove the same favorite at nearly the same time. The unique constraint prevents duplicate relationships. State transitions should also use conditions. For example, the system may allow only a transition from active to removed, or from removed back to active.

    A cache-aside strategy can be used between the cache and database:

    1. Read from the cache first.
    2. On a miss, read from the database.
    3. Populate the cache.
    4. On a write, update the database and invalidate related cache entries.

    Queries with stricter consistency requirements can read directly from the core relationship table.

    8. Performance and Scalability

    Performance optimization should focus first on reducing remote calls and query amplification.

    For activity feeds:

    • Batch-load content metadata.
    • Limit page size.
    • Cache hot pages.
    • Use request coalescing for popular scopes.
    • Apply rate limiting and graceful degradation.

    For favorite lists:

    • Use cursor pagination.
    • Batch-load target metadata.
    • Separate hot and cold data where appropriate.
    • Archive old data when necessary.

    On the write side, short transactions, asynchronous events, and batch consumers can reduce peak pressure.

    Hot scopes may require sharding, request coalescing, rate limiting, and degradation strategies. Long-tail data can use cold storage or archival workflows.

    Capacity planning should monitor:

    • API QPS
    • P99 latency
    • Cache hit rate
    • Message backlog
    • Event failure rate
    • Unique constraint conflict rate
    • Reconciliation differences
    • Page loading time

    When scaling the system, partition primarily by user identifier or scope identifier to avoid large cross-partition transactions. Search indexes should be built asynchronously and may lag temporarily. Notification and counter consumers should scale independently so that one workload does not block another.

    9. Security, Compliance, and Operations

    Favorite data may reveal user preferences and should be protected according to the principle of least privilege.

    Private folders must not be accessible to other users. APIs should enforce authentication, rate limiting, abuse prevention, and crawler protection. Critical operations should be recorded in audit logs.

    Content removal, visibility changes, and deletion requests must propagate to feed and favorite-list filtering. Data retention policies should define deletion, archival, and backup boundaries so that derived data does not indefinitely retain references to content that is no longer visible.

    10. Observability and Failure Testing

    Observability should cover logs, metrics, traces, and alerts.

    Logs should include:

    • Request identifiers
    • User identifiers
    • Target identifiers
    • Idempotency keys
    • Event identifiers

    Metrics should cover:

    • API success rates
    • Request latency
    • Cache hit rates
    • Message backlog
    • Consumer failures
    • Reconciliation differences

    Distributed tracing should connect the write transaction, event publication, and consumer processing stages.

    Failed events should support replay. Counters and timelines should be reconciled periodically. Failure drills should validate recovery from:

    • Message queue backlogs
    • Cache invalidation or cache loss
    • Database primary-replica failover
    • Consumer restarts

    Phase 1: Build the Core Loop

    Start with the minimum complete workflow:

    • Favorite relationship table
    • Unique constraints
    • Idempotency records
    • Cursor pagination
    • Asynchronous counter updates

    The priority is correctness for core operations.

    Phase 2: Improve Feed Performance

    Add:

    • Caching
    • Precomputed timelines
    • Event retry handling

    This phase improves activity feed read performance while preserving asynchronous processing.

    Phase 3: Complete Platform Capabilities

    Add:

    • Search indexes
    • Favorite folders
    • Auditing
    • Reconciliation
    • Capacity governance

    Implementation should follow three principles:

    1. Core relationships use strong consistency.
    2. Derived data uses eventual consistency.
    3. Every asynchronous event must be idempotent and replayable.

    With clear data boundaries and comprehensive observability, activity feeds and favorites can remain stable, maintainable, and scalable as the platform grows.