Notes
All notes

Capstone: Design a System End-to-End (System Design #18)

You have the parts. Now assemble them under pressure, the way an interview or a real launch does. This capstone walks a single prompt — “Design a social feed” — through the full method from Chapter 1: requirements, estimation, high-level design, deep dives, and trade-offs. Every chapter in this course shows up somewhere. Read it as a worked example, then repeat it on a different prompt yourself.

The point is not the specific design. The point is the motion: clarify, estimate, sketch, go deep where the numbers say, and justify every choice against a requirement.

Step 1 — Requirements

Functional: - Users post short text posts. - Users follow other users. - Users see a home timeline of posts from people they follow, newest-ish first. - Users can like and reply (counts matter more than exactness).

Non-functional: - Read-heavy: far more timeline reads than posts. - Timeline reads must be fast (< 200 ms p99) and highly available. - A post becoming visible a few seconds late is acceptable (feed is eventual), but a user’s own post should appear immediately (read-your-writes). - Global users; latency matters across regions. - Losing a post after “posted” is unacceptable; a like count being briefly off is fine.

The last two lines are the CAP/PACELC decisions (Chapters 3–4) made before any box is drawn: feed reads are AP/EL; post durability is CP/EC.

Step 2 — Estimation

Assume 100M daily users, 200M posts/day, and 100 timeline reads per user per day.

DAU = 100e6
posts_per_day = 200e6
reads_per_user = 100

write_qps = posts_per_day / 86_400           # ~2,315 posts/s avg
read_qps  = DAU * reads_per_user / 86_400    # ~115,741 reads/s avg
print(f"write QPS={write_qps:,.0f}  peak={write_qps*3:,.0f}")
print(f"read  QPS={read_qps:,.0f}  peak={read_qps*3:,.0f}")
print(f"read:write = {read_qps/write_qps:.0f}:1")

avg_post_bytes = 300
print(f"post storage/day = {posts_per_day*avg_post_bytes/1e9:.1f} GB/day")
print(f"post storage/3y  = {posts_per_day*avg_post_bytes*365*3/1e12:.1f} TB")

Rough results: ~2.3K writes/s (peak ~7K), ~116K reads/s (peak ~350K), a ~50:1 read-to-write ratio, and a few hundred TB of posts over three years. Two conclusions fall out immediately:

Step 3 — High-level design

\begin{tikzpicture}[font=\rmfamily, >=stealth,
  b/.style={draw, thick, rounded corners=3pt, minimum width=1.65cm, minimum height=0.68cm, align=center, font=\rmfamily\small},
  a/.style={->, thick}]
  \node[b, fill=gray!10] (c) at (-5.0,0) {client};
  \node[b, fill=blue!10] (cdn) at (-3.4,0) {CDN};
  \node[b, fill=orange!16] (lb) at (-1.6,0) {LB};
  \node[b, fill=green!12] (app) at (0.4,0) {app};
  \node[b, fill=cyan!15] (tl) at (2.6,1.2) {timeline cache};
  \node[b, fill=yellow!22] (pg) at (2.6,-0.1) {post store (sharded)};
  \node[b, fill=red!10] (q) at (2.6,-1.4) {queue $\to$ fan-out};
  \draw[a] (c) -- (cdn); \draw[a] (cdn) -- (lb); \draw[a] (lb) -- (app);
  \draw[a] (app) -- (tl); \draw[a] (app) -- (pg); \draw[a] (app) -- (q);
\end{tikzpicture}

Step 4 — Deep dives

Fan-out: write vs read

This is the central design decision.

\begin{tikzpicture}[font=\rmfamily, >=stealth,
  b/.style={draw, thick, rounded corners=3pt, minimum width=2.0cm, minimum height=0.7cm, align=center, font=\rmfamily\small},
  a/.style={->, thick}]
  \node[b, fill=green!12] (post) at (-3.6,0.9) {post by ordinary user};
  \node[b, fill=orange!16] (fan) at (-0.8,0.9) {append to followers' timelines};
  \node[b, fill=red!12] (celeb) at (-3.6,-0.9) {post by celebrity};
  \node[b, fill=blue!10] (pull) at (-0.8,-0.9) {followers pull at read time};
  \draw[a] (post) -- (fan); \draw[a] (celeb) -- (pull);
  \node[font=\rmfamily\small, text=black!60, anchor=north] at (-2.2,-1.6) {hybrid fan-out handles the hot-user tail};
\end{tikzpicture}

Storage and sharding

Caching and read-your-writes

Failure handling

Step 5 — Trade-offs, stated plainly

The repeatable method (use this on any prompt)

  1. Clarify functional and non-functional requirements; state the consistency stance per data type.
  2. Estimate QPS, storage, and the read/write ratio; let the numbers pick the hard problems.
  3. Sketch the five-to-seven box high-level design.
  4. Deep-dive the two or three components the estimate flagged (usually the database and the fan-out/hot path).
  5. State trade-offs and what would change them.

Practice prompts (do these yourself)

For each, run the five steps and produce the same artifacts: requirements table, estimation code, high-level diagram, deep-dive on the bottleneck, and a trade-off list.

Self-assessment rubric

Criterion Passing looks like
Requirements Functional + non-functional, consistency stated per data type
Estimation QPS, storage, read/write ratio, with peak multiplier
High-level 5–7 boxes, correct flow, no unexplained components
Deep dives The actual bottleneck, with mechanism and numbers
Data Store choices justified; sharding key and replication stated
Failure Retries/idempotency, circuit breaker, degradation, HA
Trade-offs Explicit alternatives and what would change the choice
Communication Assumptions stated aloud; diagram matches the words

Pitfalls

QQuestionFinal self-check

What are the five steps of the method, and why is the hybrid fan-out the right answer for a social feed? Which two data types in this design use opposite consistency stances?

ASolution

Clarify requirements, estimate scale, sketch high-level, deep-dive the flagged bottleneck, state trade-offs. Hybrid fan-out pushes posts to ordinary followers’ precomputed timelines (fast reads) while celebrities are pulled at read time, avoiding a fan-out storm at scale. Post durability uses strong consistency (CP/EC) while feed reads and like counts use eventual consistency (AP/EL).

That is the course. Pick a prompt, run the five steps, and design something measured.