← Better.com Interview Insights
I jumped straight into the feed fanout problem and probably spent too long debating push vs pull before they nudged me toward actual data modeling.
Start by clarifying requirements and scale (e.g., number of users, tweets per day, read/write ratio), then design a high-level architecture that separates tweet writing from timeline reading, using a fan-out-on-write approach with caching for active users. Discuss trade-offs between push and pull models, and dive into data modeling, storage choices, and handling of edge cases like celebrity users.
Pro tip: Proactively discuss the hybrid approach for celebrities (fan-out-on-write for most, fan-out-on-read for high-follower accounts) to show you understand real-world scalability challenges. Also, mention monitoring and metrics to ensure the system meets latency SLAs.
Ask questions to understand functional and non-functional requirements: number of users, daily active users, tweets per day, read vs. write ratio, latency expectations, and consistency needs. Estimate scale (e.g., 500M tweets/day, 200M DAU) to inform design decisions.
Propose a microservices-based architecture with separate services for tweet posting, timeline generation, and user graph. Use a message queue (e.g., Kafka) to decouple tweet creation from fan-out, and a cache (e.g., Redis) to store precomputed timelines for fast reads.
Design schemas for tweets (tweet_id, user_id, content, timestamp), follows (follower_id, followee_id), and timelines (user_id, tweet_id, timestamp). Choose storage: a distributed SQL database (e.g., Cassandra) for tweets and follows, and Redis sorted sets for timeline caching.
Explain fan-out-on-write: when a user tweets, push the tweet to followers' timeline caches. For celebrities with millions of followers, use a hybrid approach: fan-out-on-read for them, merging their tweets at read time. Discuss trade-offs: write amplification vs. read latency.
Address scaling: sharding by user_id, replication for fault tolerance, and caching strategies. Discuss trade-offs: consistency vs. availability (AP vs. CP), latency vs. cost, and how to handle hotkeys and thundering herd. Mention monitoring and metrics.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.