Design a social media feed

    A social feed (Twitter/Instagram) must assemble a personalized timeline from the posts of everyone you follow, fast, at read time. The central tension is fan-out-on-write (precompute timelines) vs fan-out-on-read (assemble on demand) — and the celebrity problem that breaks naive fan-out.

    Web Apps, 11 components, about 45 min

    The full guide covers requirements, estimates, the API, the data model, deep dives, trade-offs, failure modes and the follow-up questions interviewers ask.

    Read the full guide on Substack

    Key points

    • Fan-out on write: when user posts, copy to follower timelines (Redis lists).
    • Celebrity exception: > 1M followers → store once, merged at read time (pull).
    • Timelines capped at ~800 entries per user; older posts paged from DB.
    • Media uploads go directly to S3 via signed URLs (bypass app servers).
    • Search index (Elasticsearch) is async-updated from a Kafka post-stream.

    Sign in to track this guide in your curriculum progress.