Dashboard/System design/32. Design Twitter

SYSTEM DESIGN · LESSON 32 OF 52 · 17 MIN VIDEO · 5 TOPICS

Design Twitter

Module Progress (0 / 5 Lessons Completed)0%
System design Track (0 / 52 Modules) · Overall 0/80 (0%)0%
⌁

Narrated HD Video Lesson (17 min) · Pro

Lesson Overview + Section #01 + RESHADED Checklist + Quiz #1 are unlocked free below (no login required). Unlock all 80 HD video lessons and deep-dive sections — or watch our two free sample video lessons first.

SYSTEM DESIGN VIDEO LESSON & GUIDE

Design Twitter

Designing Twitter requires building a low-latency global broadcast platform under a 10:1 read-to-write asymmetry (58,000 timeline reads/sec versus 5,800 tweets/sec) and extreme power-law social graph skew, where ordinary accounts have ~200 followers while celebrities exceed 100,000,000. A single 280-character post must be persisted durably once, indexed for real-time search, and delivered across millions of personalized home timelines within seconds. L4–L6 interviewers probe four architectural pillars: coordination-free 64-bit Snowflake ID generation, hot-spot-free storage sharding, hybrid push/pull fan-out, and Finagle-style client-side load balancing across internal microservice meshes.

WHAT YOU WILL MASTER IN THIS LESSON
  • Size read-dominated timeline workloads (5B timeline reads/day = 58K RPS avg / 174K RPS peak), media blob storage (25 TB/day), and CDN egress bandwidth (93 Gbps).
  • Generate k-sorted, globally unique 64-bit Snowflake IDs (41-bit timestamp, 10-bit worker, 12-bit sequence) to support coordination-free sharding and drift-free cursor pagination.
  • Resolve the 100M-follower celebrity fan-out bottleneck by combining asynchronous Redis fan-out-on-write for regular users with read-time merge (fan-out-on-read) for high-follower accounts.
  • Eliminate internal L7 proxy bottlenecks and full-mesh TCP explosion using Finagle client-side load balancing (Power of Two Choices + EWMA latency) with Deterministic Ring Aperture.
SYSTEMATIC INTERVIEW CHECKLIST · RESHADED + 45-MIN CLOCK

8-Step RESHADED Execution Checklist

Follow this exact sequence from the Intro narration on every system design prompt so you never miss requirements, math, contracts, or the 13-minute deep dive.

0 / 8 Checked
INTERVIEWER SCORECARD · WHAT MAKES A STRONG HIRE?

5 Signals Bar Raisers Grade (L4 vs. L5 Senior vs. L6 Staff)

Senior (L5 / E5 / Senior SDE) Bar — Autonomous Pacing, Depth & Proactive Trade-Offs: Owns the 45-minute clock without prompting, derives every component quantitatively, surfaces failure modes (hot shards, stampedes, dual writes) BEFORE being asked, and defends consistency vs. latency trade-offs.
1. Scoping
✓ STRONG HIRE SIGNAL

Clarifies users, read/write skew, p99 latency, consistency bounds, and explicit non-goals in minutes 2–8.

✗ NO-HIRE RED FLAG

Jumps straight into drawing load balancers and microservices at minute 2 without asking a single question.

2. Right-Sized Design
✓ STRONG HIRE SIGNAL

Starts with the simplest working architecture justified by the math (e.g., 1 NVMe SQL primary + replicas + Redis for 40 writes/s & 3 TB).

✗ NO-HIRE RED FLAG

Recites a memorized Kafka + multi-DC Cassandra diagram that contradicts their own traffic calculations.

3. Technical Depth
✓ STRONG HIRE SIGNAL

Drives deep into 1–2 hard bottlenecks (partition keys, hot-key mitigation, transactional outbox, KV-cache batching) at minute 27.

✗ NO-HIRE RED FLAG

Skims across 12 boxes at identical buzzword depth and runs out of time before the deep dive.

4. Explicit Trade-Offs
✓ STRONG HIRE SIGNAL

Uses 3-part reasoning: 'A queue here because SMTP spikes to 3 s; checkout stays <60 ms, and we accept eventual email delay + retry dedup.'

✗ NO-HIRE RED FLAG

Name-drops tools ('We put Kafka and ZooKeeper here') without stating the alternative or operational cost.

5. Communication
✓ STRONG HIRE SIGNAL

Thinks aloud every 30–45s, checks alignment at phase transitions, and treats 'What if X fails?' as a cue for where points are awarded.

✗ NO-HIRE RED FLAG

Goes silent for 5 minutes while drawing or defends a flawed assumption defensively when nudged.

ARCHITECTURE & DATA-FLOW SLIDES · SLIDE 1 OF 1Section 01: System Design: Twitter
ARCHITECTURE / DATA FLOW DIAGRAM
100M followersAuthorwrites a tweetseconds, not minutesTwitterlikeFollowerhome timelineretweetFollowerhome timelinereplyFollowerhome timeline
SECTION 01 OF 5

1. System Design: Twitter

★ FREE PREVIEW
Key Takeaway: Twitter is an asymmetric fan-out system where a single directional write must rapidly materialize across millions of home timelines despite extreme follower-count skew.
ARCHITECTURE / DATA FLOW DIAGRAM
100M followersAuthorwrites a tweetseconds, not minutesTwitterlikeFollowerhome timelineretweetFollowerhome timelinereplyFollowerhome timeline

Directional Social Graph & Real-Time Broadcast

On Twitter, users publish short messages up to 280 characters (optionally referencing photos or video) and follow other accounts via a directed (one-way) graph—unlike mutual friend networks that enforce symmetric edges and cap connections at 5,000. Because following requires no reciprocation, a single news outlet or public figure can accumulate 100,000,000+ followers. Every time a user opens the app, their home timeline aggregates recent tweets from hundreds of followed accounts into a time-ordered or ranked stream alongside lightweight engagement counters (likes, retweets, replies).

  • Read-Heavy Consumption: Users refresh and scroll their home timeline roughly 10x more frequently than tweets are authored across the platform.
  • Power-Law Fan-Out Skew: One write from an ordinary account updates ~200 timelines; one write from a top-tier celebrity reaches 100,000,000 followers.
  • Real-Time Freshness SLA: Breaking news and live-event commentary lose value rapidly if delivery lags beyond 2–5 s.

Core Architectural Tensions

Every design decision in Twitter balances write amplification against read amplification. Computing home timelines purely at read time (SELECT ... WHERE author_id IN (...)) collapses under 58,000 reads/sec, whereas precomputing timelines purely at write time collapses whenever an account with 100M followers posts. Solving both simultaneously requires decoupling write persistence from timeline materialization and adapting the delivery strategy per author.

System PropertyWorkload RealityNaive Design Failure ModeProduction Engineering Pattern
Read-to-Write Ratio10:1 (58K timeline reads/s vs. 5.8K writes/s)On-demand SQL joins across 500 followees per read saturate DB IOPSPrecompute 8-byte tweet ID lists in RAM (Timeline Cache) + Tweet Cache
Follower Skew200 average followers vs. 100,000,000 maxUnconditional push triggers 100M cache writes (~100 s lag) on 1 celebrity tweetHybrid fan-out: push ordinary authors on write, merge celebrity authors on read
Media Payload Size300 B tweet text vs. 200 KB photo / 3 MB videoServing binary blobs through core API servers exhausts origin NICsStore immutable blobs in object storage (S3) fronted by global edge CDN
East-West RPC VolumeMillions of internal calls/sec hydrating tweets and profilesCentralized internal L7 proxies add extra network hops and failure domainsClient-side RPC load balancing (Finagle) with Power of Two Choices + Deterministic Aperture
SECTION 02 OF 5

2. Requirements of Twitter's Design

🔒 PRO SECTION
Key Takeaway: Optimize for high availability (AP), sub-200 ms server-side timeline latency, and zero tweet loss while accepting multi-second eventual consistency, backing the 58K RPS read workload with multi-tier RAM caches and a 93 Gbps CDN tier.

Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.

SECTION 03 OF 5

3. High-level Design of Twitter

🔒 PRO SECTION
Key Takeaway: Persist each tweet once in a sharded store, push only 8-byte tweet IDs into per-user timeline caches asynchronously via a queue, and serve timeline reads through a two-level memory cache backed by edge CDNs.

Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.

SECTION 04 OF 5

4. Detailed Design of Twitter

🔒 PRO SECTION
Key Takeaway: Combine specialized storage engines, coordination-free 64-bit Snowflake IDs sharded by hash(tweet_id), hybrid push/pull celebrity fan-out, and Kafka-driven inverted search indexing.

Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.

SECTION 05 OF 5

5. Client-side Load Balancer for Twitter

🔒 PRO SECTION
Key Takeaway: Embedding Finagle load balancing inside each RPC caller eliminates middlebox hops, while pairing Power of Two Choices (P2C) with Deterministic Ring Aperture bounds TCP connections and prevents random-subset server clumping.

Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.

ACTIVE RECALL & TRADE-OFF PROBES

System Design Checkpoint Quizzes (1)

CHECKPOINT QUIZ #1

In "System Design: Twitter" (Core Architectural Tensions), how does a production-grade design handle "Follower Skew" (Production Engineering Pattern)?