DBRaven
Full ReviewModerate Readinessdraft

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

8

Architectural Tradeoffs

2

Recommendations

11
High

Monitor: Thundering Herd (Cache Stampede)

risk_monitoring

When 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)

High

Monitor: Queue Backlog Accumulation

risk_monitoring

Message 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)

High

Implement: Monitor generic risk probe signals

observability

Seed 'Fanout Amplification Risk Probe' identifies 2 metrics relevant to fanout_amplification.

Metrics to instrument: error_rate, p95_latency_ms

Moderate

Monolithic feed built on PostgreSQL timeline queries → Redis pre-materialized feed with Kafka async fan-out workers

migration_planning

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. 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

Moderate

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_planning

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. 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

Moderate

Prepare runbook for: Burst Traffic Cold Cache Stampede

simulation_preparedness

Simulation demonstrates critical degradation of redis, postgresql

Without a runbook, recovery from this failure mode will be ad-hoc

burst-traffic-cold-cache-stampede
Moderate

Prepare runbook for: Connection Pool Exhaustion with Horizontal User Scale

simulation_preparedness

Simulation demonstrates critical degradation of postgresql

Without a runbook, recovery from this failure mode will be ad-hoc

connection-pool-growth-with-user-scale
Moderate

Plan evolution: OLTP Analytics Queries → OLTP + OLAP Separation

evolution_planning

Evolution from Unified OLTP + Analytics on PostgreSQL → Separated OLTP (PostgreSQL) + OLAP (ClickHouse/Snowflake)

Migration complexity: medium. Rollback: always.

oltp-analytics-to-separated
Moderate

Plan evolution: Single Cache Layer → Distributed Cache

evolution_planning

Evolution from Single Redis Node / Sentinel Cluster → Distributed Redis Cluster (Consistent Hash Ring)

Migration complexity: medium. Rollback: complex.

single-cache-to-distributed
Low

Monitor threshold: Tier 1: Fan-Out Worker Queue Backlog

scaling_monitoring

Signal: 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.

Low

Monitor threshold: Tier 2: Redis Feed Memory Ceiling

scaling_monitoring

Signal: 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

8

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

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.

Evidence:kafka-consumer-lag-cascadepartition-hotspot-amplification

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

Evidence:kafka-consumer-lag-cascadepartition-hotspot-amplification

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

Evidence:kafka-consumer-lag-cascadepartition-hotspot-amplification

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

Evidence:kafka-consumer-lag-cascadepartition-hotspot-amplification

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

12

Migration Stages

3
Stage

Monolithic feed built on PostgreSQL timeline queries → Redis pre-materialized feed with Kafka async fan-out workers

info

Migration 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

Stage

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)

info

Migration 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

Stage

Single Redis primary for all feed data → Redis Cluster with feed keys sharded by user_id range

info

Migration 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

9
Risk

Redis feed hydration requires a backfill job to populate fee

warning

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

Risk

During the migration period, double-writes (to both PostgreS

warning

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

Risk

Fan-out-on-read for celebrity accounts requires feed merge l

warning

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

Risk

Threshold for routing (follower count) must be maintained as

warning

Threshold for routing (follower count) must be maintained as a dynamic config; hardcoding it causes operational problems when accounts cross the threshold

Risk

Redis Cluster changes key access patterns: multi-key operati

warning

Redis 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

Risk

Initial cluster setup requires rebalancing all existing feed

warning

Initial cluster setup requires rebalancing all existing feed keys; this operation must be performed with minimal read disruption to the feed API

Risk

Projection lag creates a read-after-write window where users

critical

Projection 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

Risk

Projection rebuild after schema change can take hours or day

critical

Projection 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

Risk

Cross-service workflows that previously used database transa

critical

Cross-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

6

Referenced Intelligence

kafkapostgresqlrabbitmqredisburst-traffic-cold-cache-stampedeconnection-pool-growth-with-user-scalecqrs-projection-lag-expansioncross-region-stale-read-windowdistributed-cache-invalidation-failureevent-replay-storm-recoverykafka-consumer-lag-cascademulti-tenant-noisy-neighborpartition-hotspot-amplificationpostgresql-replication-lag-surgequery-cost-without-indexesrabbitmq-queue-backlog-saturationread-amplification-n-plus-one-queriesredis-cache-collapse-stampederetry-storm-amplificationsplit-brain-during-network-partitionstorage-bloat-without-archivingstorage-cost-compounding-without-retentionwrite-heavy-bulk-import-saturationdirect-db-to-cqrsmodular-monolith-to-event-drivenoltp-analytics-to-separatedpostgresql-to-partitionedrabbitmq-to-kafkasingle-cache-to-distributedsingle-region-to-multi-regionarchitecture-evolutionauditabilitybtree-indexingcache-invalidationcap-theoremconsistency-modelscqrs-operationalevent-sourcingeventual-consistencykafka-consumer-lagmulti-tenancynormalizationoltp-vs-olappartition-hotspotsquery-planningqueue-backlogreplication-lagvector-databaseswrite-amplification
Architecture Review: Social Feed Platform: DBRaven