Architecture Review: Social Feed Platform
A social activity feed architecture where user actions (posts, likes, comments, follows) fan out asynchronously to follower timelines. Redis stores hot feed data as pre-materialized lists per user, enabling O(1) timeline reads for the 99th percentile of users. Kafka carries fan-out work to async workers that write to follower Redis keys. PostgreSQL is the durable store for the social graph, posts, and user content. The system uses a hybrid fan-out model: fan-out-on-write for users with fewer than ~10,000 followers (low fan-out cost), fan-out-on-read for high-follower celebrity accounts where pre-materialized fan-out would saturate workers and Redis write bandwidth.
Evidence Confidence
Moderate
strong
Executive Summary
Social Feed Platform: moderate operational readiness (82% evidence confidence). 0 architectural strengths identified, 5 operational risks to manage. Primary concern: Queue Backlog Accumulation. Requires Advanced operational maturity.
Readiness Rationale
Overall moderate readiness across 8 dimensions. Limited: scaling, team maturity. Strong: migration, observability, failure recovery.
Key Concerns
- !Queue Backlog Accumulation
- !Thundering Herd (Cache Stampede)
Key Strengths
- +Architecture is well-defined for the event driven system problem profile
8
Assessments
2
Tradeoffs
6
Sections
11
Recommendations
Readiness Assessments
8Architectural Tradeoffs
2Recommendations
11Monitor: Thundering Herd (Cache Stampede)
risk_monitoringWhen a popular cached key expires or a service recovers from downtime, all requests that were waiting or arrive simultaneously miss the cache and hit the origin database concurrently, producing a request spike that can overwhelm the database within seconds.
Affects 1 node. (Redis)
Monitor: Queue Backlog Accumulation
risk_monitoringMessage queue or event stream consumer processing rate falls below producer write rate, causing consumer lag to grow unboundedly: eventually leading to increased end-to-end latency, producer backpressure, data expiry, or queue resource exhaustion.
Affects 1 node. (Event Streaming)
Implement: Monitor generic risk probe signals
observabilitySeed 'Fanout Amplification Risk Probe' identifies 2 metrics relevant to fanout_amplification.
Metrics to instrument: error_rate, p95_latency_ms
Monolithic feed built on PostgreSQL timeline queries → Redis pre-materialized feed with Kafka async fan-out workers
migration_planningTrigger: PostgreSQL timeline read query p99 > 500ms; query plan for "SELECT posts WHERE user_id IN (following_list) ORDER BY created_at DESC LIMIT 50" showing sequential scan or index merge; feed read traffic accounting for > 40% of database CPU. Migrate from 'Monolithic feed built on PostgreSQL timeline queries' to 'Redis pre-materialized feed with Kafka async fan-out workers'. Introduce the Kafka fan-out worker and Redis feed writer in shadow mode for 2–4 weeks before cutting feed reads from PostgreSQL to Redis. Use a 5% traffic canary to validate feed correctness (compare PostgreSQL and Redis results) before full cutover. The outbox pattern on post writes must be in place before Kafka fan-out workers are added.
Redis feed hydration requires a backfill job to populate feed lists for all existing users from historical post data; backfill must be idempotent and rate-limited to avoid Redis write saturation; During the migration period, double-writes (to both PostgreSQL timeline query path and Redis fan-out path) are required; consistency between the two paths must be validated before cutting over read traffic
Uniform fan-out-on-write for all accounts → Hybrid fan-out model (fan-out-on-write for <10k followers, fan-out-on-read for high-follower accounts)
migration_planningTrigger: Fan-out worker queue lag during celebrity post events > 5 minutes; Redis write throughput spiking to > 80% of capacity during these events; fan-out cost for top 100 accounts measured at > 1000x median fan-out cost. Migrate from 'Uniform fan-out-on-write for all accounts' to 'Hybrid fan-out model (fan-out-on-write for <10k followers, fan-out-on-read for high-follower accounts)'. Implement fan-out-on-read as a supplementary merge layer on top of the existing fan-out-on-write path, not a replacement. Feed reads for users following celebrity accounts fetch the celebrity's recent posts directly from PostgreSQL (via Redis cache) and merge them into the pre-materialized feed list at read time.
Fan-out-on-read for celebrity accounts requires feed merge logic at read time (combine pre-materialized follower feed with recent celebrity posts); this merge adds latency and complexity to the feed read path; Threshold for routing (follower count) must be maintained as a dynamic config; hardcoding it causes operational problems when accounts cross the threshold
Prepare runbook for: Burst Traffic Cold Cache Stampede
simulation_preparednessSimulation demonstrates critical degradation of redis, postgresql
Without a runbook, recovery from this failure mode will be ad-hoc
Prepare runbook for: Connection Pool Exhaustion with Horizontal User Scale
simulation_preparednessSimulation demonstrates critical degradation of postgresql
Without a runbook, recovery from this failure mode will be ad-hoc
Plan evolution: OLTP Analytics Queries → OLTP + OLAP Separation
evolution_planningEvolution from Unified OLTP + Analytics on PostgreSQL → Separated OLTP (PostgreSQL) + OLAP (ClickHouse/Snowflake)
Migration complexity: medium. Rollback: always.
Plan evolution: Single Cache Layer → Distributed Cache
evolution_planningEvolution from Single Redis Node / Sentinel Cluster → Distributed Redis Cluster (Consistent Hash Ring)
Migration complexity: medium. Rollback: complex.
Monitor threshold: Tier 1: Fan-Out Worker Queue Backlog
scaling_monitoringSignal: Kafka consumer group lag for fan-out worker group growing steadily; feed propagation latency (time from post write to follower feed update) exceeding 30s p95; Redis write rate on feed keys elevated but not saturated; post activity rate normal
Bottleneck: Fan-out worker pool undersized for burst post activity or a celebrity post creating a sustained high-fan-out event. Evolution: Add fan-out worker replicas; implement fan-out cost routing: route high-follower-count fan-out events to a dedicated high-cost worker pool with separate Kafka consumer group and Redis write quota; use follower count threshold (e.g., >50k followers) as the routing decision. Monitor fan-out cost per post as a first-class metric.
Monitor threshold: Tier 2: Redis Feed Memory Ceiling
scaling_monitoringSignal: Redis memory utilization > 75%; eviction rate rising; cache miss rate on feed reads increasing; cold feed read fallback queries appearing in PostgreSQL slow query log; feed read p99 > 100ms despite Redis being online
Bottleneck: Redis feed list storage approaching memory limit; feed items being evicted before TTL; or feed list cap set too high for available memory. Evolution: Reduce feed list cap from current value toward 100–150 items; increase Redis cluster capacity or shard feed keys by user_id range across multiple Redis primaries; implement tiered feed storage: hot recent items in Redis, older items fetched from PostgreSQL on demand with explicit product UX affordance
Scaling Pressure Signals
8Kafka consumer group lag for fan-out worker group growing steadily; feed propagation latency (time from post write to follower feed update) exceeding 30s p95; Redis write rate on feed keys elevated but not saturated; post activity rate normal
Threshold
Tier 1: Fan-Out Worker Queue Backlog
Likely Bottleneck
Fan-out worker pool undersized for burst post activity or a celebrity post creating a sustained high-fan-out event
Recommended Evolution
Add fan-out worker replicas; implement fan-out cost routing: route high-follower-count fan-out events to a dedicated high-cost worker pool with separate Kafka consumer group and Redis write quota; use follower count threshold (e.g., >50k followers) as the routing decision. Monitor fan-out cost per post as a first-class metric.
Redis memory utilization > 75%; eviction rate rising; cache miss rate on feed reads increasing; cold feed read fallback queries appearing in PostgreSQL slow query log; feed read p99 > 100ms despite Redis being online
Threshold
Tier 2: Redis Feed Memory Ceiling
Likely Bottleneck
Redis feed list storage approaching memory limit; feed items being evicted before TTL; or feed list cap set too high for available memory
Recommended Evolution
Reduce feed list cap from current value toward 100–150 items; increase Redis cluster capacity or shard feed keys by user_id range across multiple Redis primaries; implement tiered feed storage: hot recent items in Redis, older items fetched from PostgreSQL on demand with explicit product UX affordance
PostgreSQL replica lag > 10s during peak fan-out periods; follower list queries appearing in pg_stat_activity with wait_event = Lock; read replica CPU > 70%; fan-out worker follower fetch latency rising; incorrect fan-out events (missing recent followers) appearing in feed correctness monitoring
Threshold
Tier 3: Social Graph PostgreSQL Read Pressure
Likely Bottleneck
PostgreSQL replicas unable to serve fan-out worker follower list read volume; replica lag causing stale follower list reads
Recommended Evolution
Materialize hot follower lists in Redis (TTL 60s) to absorb fan-out worker read volume; route all fan-out follower reads through Redis cache-aside before touching PostgreSQL replica; add a dedicated read replica for fan-out worker social graph reads, isolated from timeline API read replicas
Kafka partition consumer lag concentrated on 2–3 partitions; fan-out latency for specific high-follower accounts disproportionately high vs. median; Kafka broker CPU uneven across partitions; single partition throughput ceiling (~100MB/s) visibly constraining fan-out for specific actor IDs
Threshold
Tier 4: Kafka Hot Partition Saturation
Likely Bottleneck
Kafka topic partitioned by actor_id causing all celebrity events to land on one partition, hitting single-partition throughput ceiling
Recommended Evolution
Re-partition fan-out topic by a composite key (actor_id + post_id hash bucket) to distribute celebrity writes across multiple partitions; alternatively, use a separate Kafka topic for high-fan-out events with wider partition count; ensure downstream fan-out workers deduplicate or order correctly when a single post may be processed by multiple partitions
Kafka consumer group lag for fan-out worker group growing steadily; feed propagation latency (time from post write to follower feed update) exceeding 30s p95; Redis write rate on feed keys elevated but not saturated; post activity rate normal
Threshold
Escalation trigger: Fan-out worker pool undersized for burst post activity or a celebrity post creating a sustained high-fan-out event
Likely Bottleneck
Tier 1: Fan-Out Worker Queue Backlog
Recommended Evolution
Monitor: error_rate, p95_latency_ms, queue_depth
Redis memory utilization > 75%; eviction rate rising; cache miss rate on feed reads increasing; cold feed read fallback queries appearing in PostgreSQL slow query log; feed read p99 > 100ms despite Redis being online
Threshold
Escalation trigger: Redis feed list storage approaching memory limit; feed items being evicted before TTL; or feed list cap set too high for available memory
Likely Bottleneck
Tier 2: Redis Feed Memory Ceiling
Recommended Evolution
Monitor: error_rate, p95_latency_ms, queue_depth
PostgreSQL replica lag > 10s during peak fan-out periods; follower list queries appearing in pg_stat_activity with wait_event = Lock; read replica CPU > 70%; fan-out worker follower fetch latency rising; incorrect fan-out events (missing recent followers) appearing in feed correctness monitoring
Threshold
Escalation trigger: PostgreSQL replicas unable to serve fan-out worker follower list read volume; replica lag causing stale follower list reads
Likely Bottleneck
Tier 3: Social Graph PostgreSQL Read Pressure
Recommended Evolution
Monitor: error_rate, p95_latency_ms, queue_depth
Kafka partition consumer lag concentrated on 2–3 partitions; fan-out latency for specific high-follower accounts disproportionately high vs. median; Kafka broker CPU uneven across partitions; single partition throughput ceiling (~100MB/s) visibly constraining fan-out for specific actor IDs
Threshold
Escalation trigger: Kafka topic partitioned by actor_id causing all celebrity events to land on one partition, hitting single-partition throughput ceiling
Likely Bottleneck
Tier 4: Kafka Hot Partition Saturation
Recommended Evolution
Monitor: error_rate, p95_latency_ms, queue_depth
Migration Readiness
12Migration Stages
3Monolithic feed built on PostgreSQL timeline queries → Redis pre-materialized feed with Kafka async fan-out workers
infoMigration trigger: PostgreSQL timeline read query p99 > 500ms; query plan for "SELECT posts WHERE user_id IN (following_list) ORDER BY created_at DESC LIMIT 50" showing sequential scan or index merge; feed read traffic accounting for > 40% of database CPU
Uniform fan-out-on-write for all accounts → Hybrid fan-out model (fan-out-on-write for <10k followers, fan-out-on-read for high-follower accounts)
infoMigration trigger: Fan-out worker queue lag during celebrity post events > 5 minutes; Redis write throughput spiking to > 80% of capacity during these events; fan-out cost for top 100 accounts measured at > 1000x median fan-out cost
Single Redis primary for all feed data → Redis Cluster with feed keys sharded by user_id range
infoMigration trigger: Redis memory utilization approaching 80% of a single node; Redis CPU > 60% sustained on feed write operations; single-node Redis becoming a reliability risk for the entire feed system
Risks
9Redis feed hydration requires a backfill job to populate fee
warningRedis feed hydration requires a backfill job to populate feed lists for all existing users from historical post data; backfill must be idempotent and rate-limited to avoid Redis write saturation
During the migration period, double-writes (to both PostgreS
warningDuring the migration period, double-writes (to both PostgreSQL timeline query path and Redis fan-out path) are required; consistency between the two paths must be validated before cutting over read traffic
Fan-out-on-read for celebrity accounts requires feed merge l
warningFan-out-on-read for celebrity accounts requires feed merge logic at read time (combine pre-materialized follower feed with recent celebrity posts); this merge adds latency and complexity to the feed read path
Threshold for routing (follower count) must be maintained as
warningThreshold for routing (follower count) must be maintained as a dynamic config; hardcoding it causes operational problems when accounts cross the threshold
Redis Cluster changes key access patterns: multi-key operati
warningRedis Cluster changes key access patterns: multi-key operations (MGET across users) must use hash tags or become multiple single-key operations; fan-out workers must be updated to handle cluster slot routing
Initial cluster setup requires rebalancing all existing feed
warningInitial cluster setup requires rebalancing all existing feed keys; this operation must be performed with minimal read disruption to the feed API
Projection lag creates a read-after-write window where users
criticalProjection lag creates a read-after-write window where users see stale data after their own writes. Mitigation: Route immediate post-write reads to the write store (session-scoped write token); accept eventual consistency only for non-user-initiated reads
↗ direct-db-to-cqrs
Projection rebuild after schema change can take hours or day
criticalProjection rebuild after schema change can take hours or days on large datasets. Mitigation: Design blue/green projection deployment: build new projection in parallel before switching traffic; test rebuild time in staging
↗ direct-db-to-cqrs
Cross-service workflows that previously used database transa
criticalCross-service workflows that previously used database transactions now require Saga orchestration. Mitigation: Design idempotent event handlers; implement compensating transactions for every multi-step workflow; test failure injection in staging
↗ modular-monolith-to-event-driven
Review Sections
6Referenced Intelligence