Design a photo-sharing social media platform where users can upload photos, follow other users, and view a chronological feed of posts from people they follow. Users expect fast uploads, instantly visible posts, and a smooth, duplicate-free infinite scroll experience.
The primary challenge is designing for two hard things at once: handling very large media uploads reliably and serving a low-latency, high-scale feed. Interviewers want to see clear API contracts, pragmatic caching strategies, a hybrid feed approach for celebrities, and robust pagination. You should abstract the follow graph (assume it exists) and focus on client-visible performance rather than infrastructure details like sharding or load balancing.
Based on real interview experiences, these are the areas interviewers probe most deeply:
Interviewers want to understand your approach to building personalized feeds at scale, particularly the tradeoffs between fan-out-on-write and fan-out-on-read.
Hints to consider:
Large photo and video uploads require special handling to ensure reliability and performance. Interviewers expect you to keep media off the application server hot path.
Hints to consider:
Interviewers probe how you handle the common pitfall of users seeing duplicates or missing posts as they scroll through a continuously updating feed.
Hints to consider:
When a user with many followers creates a post, the system must update potentially millions of precomputed feeds. Interviewers assess whether you understand the cost and mitigation strategies.
Hints to consider:
Confirm the scope with the interviewer. Ask about supported media types (photos only or videos too?), maximum file sizes, expected user scale, and follower distribution. Clarify whether the feed is purely chronological or includes ranking/recommendations. Establish latency targets for feed serving and acceptable delay for new post visibility. Ask about additional features like likes, comments, and stories to understand scope boundaries.
Sketch the major components: API Gateway for mobile and web clients, Post Service for creating and storing posts, Feed Service for generating and serving personalized feeds, Media Service for upload orchestration and processing, and a Notification Service for alerting followers. Show how uploads flow directly to object storage via pre-signed URLs, how post creation events fan out through a message queue to update follower feeds, and how feed reads hit a fast cache layer. Include a CDN for media delivery and Redis for precomputed feed storage.
Walk through the lifecycle of a new post. When a user creates a post, the Post Service writes metadata to the database and publishes an event to Kafka. Fan-out workers consume the event, look up the poster's follower list, and append the post ID to each follower's precomputed feed in Redis (ZADD with timestamp score). For celebrity accounts (followers > threshold), skip fan-out and merge their posts at read time. When a user requests their feed, the Feed Service reads from the precomputed Redis feed, merges in any celebrity posts via fan-out-on-read, hydrates post metadata from a cache or database, and returns a paginated response with a cursor token.
Describe the upload flow: client requests a pre-signed URL from the Media Service, uploads directly to S3, and the Media Service receives a completion callback. This triggers async workers for thumbnail generation, video transcoding, and CDN pre-warming. For scalability, partition the feed fan-out by user ID ranges, use Redis Cluster for feed storage, and implement read replicas for post metadata. Discuss monitoring feed lag (time from post creation to feed visibility), cache hit rates, and upload success rates. Cover graceful degradation: if the feed cache is unavailable, fall back to on-demand feed computation from the follow graph.