The timeline piece is where things got interesting and also where I spent most of my time.
Start by clarifying requirements and scale, then design the core data models and APIs for tweeting and following. Focus on the home timeline generation strategy (fan-out on write vs. read) and discuss trade-offs for search and notifications. Finally, address scalability, storage, and caching.
Pro tip: Demonstrate awareness of the 'celebrity problem' and propose a hybrid fan-out approach (push for normal users, pull for celebrities) to show depth. Also, mention how you'd handle consistency vs. availability trade-offs in timeline generation.
Ask about functional and non-functional requirements: expected DAU, tweets per day, read/write ratio, latency requirements, and consistency needs. This sets the stage for design decisions.
Define schemas for users, tweets, follows, and notifications. Outline key APIs: postTweet, follow, getHomeTimeline, searchTweets, and getNotifications.
Compare fan-out on write vs. fan-out on read. Discuss hybrid approach for celebrities, and how to handle timeline caching and pagination.
For search, propose an inverted index (e.g., Elasticsearch) and discuss indexing pipeline. For notifications, design a push-based system with queues and workers.
Discuss sharding, replication, caching, and CDN for media. Highlight trade-offs: consistency vs. latency, storage cost vs. speed, and failure handling.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.