Profiles, friends, posts, likes, comments and privacy for billions of people, stitched into one platform.
“Design a social media platform like Facebook.”
It is short on purpose. Your first job is to make it specific.
| What they check | Why it matters |
|---|---|
| Scoping an umbrella prompt | “A social network” is ten systems. A strong candidate picks three or four flows, says what is left out, and points to the pieces that are separate designs (feed, chat, notifications, video, search). |
| Modelling the social graph | Friends are the data everything else hangs on. The interviewer wants to see sharding by user, two-sided writes for a friendship, and a plan for accounts with millions of followers. |
| Hot counters and idempotent actions | A like is tiny, but a viral post gets 100,000 a second on one row. You must make likes exact in one place and approximate in another. |
| Privacy as a correctness problem | Who can see what is not a feature, it is an invariant. The check has to survive caches, fan-out, unfriending and blocking, and you must say where it runs. |
| Prioritising and phasing | What would you build first, what is hardest, and where does it fall over at 10 times the load? Interviewers use these to separate people who can lead a design from people who can fill a diagram. |
We build the platform core: profiles, a friend graph, posts with photos, likes and comments, and privacy enforced on every read. The feed, messaging, notifications, video and search are separate designs: the feed is covered in “Design a News Feed”, messaging in “Design a Chat App”.
| Step | Minutes | What to get done |
|---|---|---|
| 1. Clarify | 4 | Scope hard: pick 3 to 4 flows, name what is out, then scale and privacy rules. |
| 2. Estimate | 3 | Posts, likes and post reads per second, graph size, photo storage and egress. |
| 3. API and data | 4 | Post, like, comment, friend request, privacy. Users, graph, posts, likes, comments. |
| 4. High-level design | 7 | Gateway, user, graph, post, media, interaction and counter services, plus a shared permission check. |
| 5. Deep dives | 17 | Graph at scale, likes and comments, privacy on every read, media pipeline, running it at scale. |
| 6. Scale and failures | 7 | Hot posts, lost caches, cross-shard friend writes, regions, abuse. |
| 7. Wrap up | 3 | Recap, trade-offs, the build order, and what comes next. |
| Ask | Why you ask it | Typical answer | How it changes the design |
|---|---|---|---|
| This is a big product. Which flows should I design in 45 minutes? | An umbrella prompt tests whether you can scope. Saying it out loud is the answer. | Profiles and friends, creating a post with photos, likes and comments, and privacy. Treat the feed, chat, notifications and video as separate systems. | We design the platform core, and link the siblings instead of repeating them. |
| Is it a friend (two-sided) graph, a follow (one-sided) graph, or both? | Friendship is two writes that must agree. Follow is one write but can have huge lists. | Friends, with a follow model for public pages and creators. | Symmetric edges written on two shards, and a separate follow list for large accounts. |
| How many users, posts, likes and comments a day? | The ratios show where the load is: likes dominate writes. | 500M daily users, 500M posts, 10B likes and 1B comments a day. | Likes are about 116,000 writes a second, so counters need special care. |
| What can a post contain? | Media decides storage, egress and the upload pipeline. | Text, links and photos. Video is a separate design. | Photos go to object storage and a CDN. Metadata stays small. |
| Who can see a post: only public, or friends and custom lists too? | Privacy models decide how hard the read path is. | Public, friends, friends except some people, a custom list, and only me. | A permission check on every read, with default deny. |
| If I unfriend or block someone, how fast must they lose access? | This is a freshness requirement on privacy, and it rules out stale caches of decisions. | Immediately, within a second. | Never cache the decision. Cache the content, check on read. |
| Do likes and comments need to be exact, or approximate? | Exact is cheap for one user, costly for one viral post. | The user must never like twice. The displayed total can be a little stale. | Exact record, approximate count. |
| Do I need to delete everything when an account is deleted? | Deletion across caches, replicas and search is a design cost. | Yes, within a stated period, including backups on their normal cycle. | A deletion pipeline, not a single DELETE. See Data Privacy and GDPR Basics. |
| Is the product in one region or worldwide? | Regions change where the graph and the permission data live. | Worldwide, but start in one region and plan for more. | Home region per user, and asynchronous replication later. |
| What availability and latency do we need? | This sets the cache and fallback strategy. | 99.99% for reads, p99 under 200 ms for a post read, writes can take 500 ms. | Cache aggressively, degrade counters and comments before posts. |
| Assumption | Value |
|---|---|
| Daily active users | 500 million, out of 1 billion accounts |
| Posts per day, average post record | 500 million, about 1 KB each |
| Likes per day, comments per day | 10 billion and 1 billion |
| Friends per user | 300 on average |
| Posts viewed per user per day (outside the feed work) | 200, mostly from the feed |
| Photo uploads per day, original size | 100 million, 2 MB |
| Original plus resized copies | 2.5 MB per photo |
| Peak compared to average | 3 times |
| Cache hit rate for posts, CDN hit rate for photos | 95% and 95% |
| One counter row can take | 5,000 writes a second (illustrative) |
| What | Maths | Result |
|---|---|---|
| Posts per second (average, peak) | 500M ÷ 86,400 ≈ 5,800, × 3 | about 5,800 and 17,400 a second |
| Likes per second (average, peak) | 10B ÷ 86,400 ≈ 115,700, × 3 | about 116,000 and 350,000 a second |
| Comments per second (average, peak) | 1B ÷ 86,400 ≈ 11,600, × 3 | about 11,600 and 35,000 a second |
| Post reads per second (average, peak) | 500M × 200 = 100B; 100B ÷ 86,400 | about 1.16 million and 3.5 million a second |
| Post reads that reach the store | 1.16M × 5% (after a 95% cache hit) | about 58,000 a second |
| Post metadata per year, 3 copies | 500M × 1 KB × 365 = 182 TB; × 3 | about 550 TB |
| Like records per year, 3 copies | 10B × 24 bytes × 365 = 88 TB; × 3 | about 263 TB |
| Friend graph | 1B users × 300 friends × 16 bytes | 300 billion rows, 4.8 TB, 14.4 TB with 3 copies |
| Graph per shard (64 shards) | 4.8 TB ÷ 64 | about 75 GB per shard, per copy |
| Photo storage per day and per year | 100M × 2.5 MB = 250 TB; × 365 | 250 TB a day, about 91 PB a year |
| Photo upload bandwidth | 100M × 2 MB ÷ 86,400 = 2.3 GB/s | about 18.5 Gbps average, 55 Gbps at peak |
| Photo views and CDN egress | 100B views × 30% photos × 100 KB = 3 PB a day | about 280 Gbps average, about 14 Gbps reaches the origin |
| One viral post: counter rows needed | 100,000 likes/s ÷ 5,000 per row | at least 20 rows, so use 32 (about 3,100 per row) |
| Friend sets cached for permission checks | 100M recently active × 300 × 8 bytes | about 240 GB |
| Method | Path | Request | Response | Notes |
|---|---|---|---|---|
| POST | /v1/posts | { text, mediaIds[], audience } | 201 { postId } | Idempotency key in a header. Photos are uploaded first by a pre-signed URL. audience is public, friends, a list ID, or only me. |
| GET | /v1/posts/{postId} | none | 200 { post, author, counts, viewerState } or 404 | Permission checked for the viewer on every call. A hidden post answers 404, not 403, so its existence does not leak. |
| PUT | /v1/posts/{postId}/like | none | 204 | Idempotent: liking twice is the same as once. DELETE removes the like. Returns fast, counts update asynchronously. |
| POST | /v1/posts/{postId}/comments | { text, parentId? } | 201 { commentId } | Idempotency key. GET with ?cursor= pages comments. Replies are limited to one or two levels. |
| POST | /v1/friends/requests/{userId} | none | 202 | PUT /v1/friends/{userId} accepts. Accepting is idempotent and writes both sides. DELETE unfriends. |
| PATCH | /v1/me/privacy | { defaultAudience, lists, blocks } | 200 | Takes effect at once. Bumps a privacy version so caches of lists are dropped. |
| Store | Key and value | Notes |
|---|---|---|
| Users | user_id → { name, photo, default_audience, home_region } | Sharded by user_id. Cached. Small. |
| Friendships | (user_id, friend_id) → { since, status } | Two rows per friendship, one on each user's shard. 300B rows, 4.8 TB. |
| Follows (large accounts) | (account_id, follower_id) and (follower_id, account_id) | Kept apart from friends. Read in pages. Never loaded whole. |
| Posts | post_id → { author_id, text, media_ids, audience, created_at, status } | Sharded by post_id (time-ordered ID). Plus an index of (author_id, created_at) for the profile page. |
| Likes | (post_id, user_id) → created_at | Unique key. The exact record. 24 bytes a row. Sharded by post_id. |
| Like counters | (post_id, shard 0..N-1) → count | Sharded counters, added on read, cached for 1 to 2 seconds. |
| Comments | (post_id, comment_id) → { author_id, text, parent_id, status } | Sharded by post_id. Cursor paging by comment_id. |
| Audience lists | list_id → members | Custom lists such as Close friends, owned by one user. Small. |
| Photos | media_id → { object keys, sizes, owner, status } | Bytes in object storage. Metadata in the store. Served by a CDN. |
-- on user A's shard (A accepts B's request)
BEGIN;
UPDATE friendships SET status='friends' WHERE user_id=A AND friend_id=B; -- idempotent
INSERT INTO outbox(event, key) VALUES ('FriendAccepted', 'A:B');
COMMIT;
-- a relay publishes FriendAccepted; the worker on B's shard runs the same UPDATE for (B, A).
-- retry-safe: the UPDATE sets a state, it does not add to a counter.| Component | What it does |
|---|---|
| API gateway | Authenticates the caller, rate-limits by user and action, and routes. Friend requests and posts have tight limits to slow spam. |
| Graph service | Owns friendships, follows, blocks and custom lists. Answers: are A and B friends, is B blocked, who is on this list, who are my mutual friends. Sharded by user ID. |
| Permission check | A small library every read path calls. Input: viewer, post audience, author. Output: allow or deny, default deny. Runs on in-memory friend sets, not a network call per post. |
| Post service | Creates, reads, edits and deletes posts and comments. Stores the audience on the post and never decides visibility by itself. |
| Interaction service | Writes likes (exact, unique) and bumps sharded counters. Reads give the cached sum. |
| Media service | Hands out pre-signed upload URLs, runs processing (resize, scan), and gives out signed CDN URLs for private photos. |
| Event bus | Receives events from an outbox (PostCreated, FriendAccepted, LikeAdded) for the feed, search, notifications and counters. All consumers are idempotent. |
| Caches | User and post caches, plus a friend-set cache for the permission check. Content is cached. Decisions are not. |
The problem: 300 billion friendship rows must live on many machines, a friendship is one fact that must appear on two users' lists, and a few accounts have millions of followers. Mutual friends and friends-of-friends must stay cheap.
| Option | How it works | Good | Bad |
|---|---|---|---|
| A graph database | Store people as nodes and friendships as edges in a graph engine, and walk them with graph queries. | Natural for traversals such as friends of friends. Short, readable queries. | Hard to shard at this size. Most of our reads are one user's list, which does not need traversal. Another system to run. |
| Sharded rows, both sides on each user's shard | Row (user, friend) on the user's shard. A friendship is two rows on two shards. | One user's friend list is one shard read. Scales by adding shards. Simple and predictable. | Writing two shards means a cross-shard step. Needs an outbox and idempotent workers. |
| One row per friendship on one shard | Store each friendship once, keyed by the lower user ID. | One write. Never half-written. | Half of the lists need a second lookup. A user's list is scattered across shards. |
| Separate follow model for big accounts | Keep friends (symmetric, capped at a few thousand) apart from follows (one-sided, unlimited), and read the follow lists only in pages. | Friend lists stay small and bounded. The unbounded case is isolated and paged. | Two models in the product and in the code. |
Invariant: if A is a friend of B then B is a friend of A, and no one ever sees a one-sided friendship for long. Two shards cannot commit together without a distributed transaction (see Saga Pattern and Outbox Pattern), so the accepting shard commits its row and an outbox event in one local transaction, and a worker writes the other row. Both writes set a state, they do not add to anything, so a retry is harmless. For the short window the other side lags, the permission check treats the friendship as present only if both rows say so, which fails safe.
Sharding by user ID makes the common questions cheap: list a user's friends, test whether two users are friends, load a user's blocks. Mutual friends is a set intersection of two lists of about 300 IDs, done in memory. Friends-of-friends is bounded: a depth limit of two, and a cap on how many second-level IDs are read. Public pages and creators use the follow model, whose lists are never loaded whole.
| Question | How it is answered | Cost |
|---|---|---|
| List my friends | One shard read by user ID, paged | One lookup, about 300 rows |
| Are A and B friends? | One row lookup on A's shard (cached friend set) | A memory lookup |
| Mutual friends of A and B | Read both lists, intersect in memory | Two lookups and about 600 IDs |
| Friends of friends (depth 2) | Read my list, then sample or cap their lists | Up to 300 lookups, so cap and cache it |
| A page with 5M followers | Paged follow list, never loaded whole | A page of 1,000 per call |
| Remove a friend | Delete row on both shards, drop the cached set | Two writes via outbox |
The problem: A user must never like a post twice, the total must be right enough, and one viral post receives 100,000 likes a second on a single key. Comments need ordering, replies and pagination, and deleted ones must disappear.
| Option | How it works | Good | Bad |
|---|---|---|---|
| UPDATE posts SET likes = likes + 1 | A counter column on the post row, updated on every like. | Simplest thing that works. | A row lock on every like. A viral post serialises 100,000 writes a second on one row. Retries double-count. |
| Exact like table plus a sharded counter | Insert (post, user) with a unique key, and only on success add one to one of N counter rows chosen at random. Read by summing N rows and cache the sum. | Exact per user, spread per post. Retries are harmless. A like can be undone. | A sum of N rows on every read, so cache it. The two writes can drift apart. |
| Buffer in memory and flush | Count likes in an in-memory aggregator per post and flush the total to the store every second. | One write a second per post, however popular. | A crash loses up to a second of counts, unless the stream is replayable. Needs a log. |
| Approximate counts | Show “1.2M”, derive counts from a stream, and rebuild exact totals in a batch job. | Cheap, no hot rows, no one cares about the last digit. | The number can differ between screens, and a user sees their own like missing for a moment unless handled. |
Invariant: one user, one like per post, and a retry never counts twice. The unique key on (post, user) enforces it: the insert either succeeds once or fails as a duplicate, and only a successful insert bumps the counter. The displayed number is a different thing, and it may lag: read the N counter rows, sum them, and cache the sum for a second or two.
For a viral post, split the counter into 32 rows so each takes about 3,100 writes a second against a limit of about 5,000, and for the very hottest posts add a buffering aggregator in front. The client shows the user's own like at once (optimistic), and the “liked by you” flag comes from the exact table, not the counter. Counts that drift are repaired by a periodic recount from the like table.
ok = INSERT INTO likes(post_id, user_id) VALUES (?, ?) ON CONFLICT DO NOTHING -- exact, idempotent
if ok:
shard = hash(user_id) % 32 -- or random
INCR counter(post_id, shard) -- hot row spread over 32 rows
publish LikeAdded(post_id, user_id) -- for notifications and ranking
total(post_id) = cache.get(post_id) ?? SUM(counter(post_id, 0..31)) -- cache 1 to 2 seconds| Comment feature | Design |
|---|---|
| Storage and order | Sharded by post_id, ordered by a time-ordered comment_id |
| Paging | Cursor of comment_id, never an offset |
| Replies | parent_id, with one or two levels shown and the rest loaded on demand |
| Delete or hide | Mark status, filter on read, clean up later |
| Hot post | Cache the first page for a few seconds, and write comments asynchronously if needed |
The problem: Each post has an audience (public, friends, friends except someone, a custom list, only me). Friends change, people are blocked, lists are edited, and posts sit in caches and other systems. A single leak is a serious failure, and one slow check on 1.2 million reads a second is another.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Work out the audience list when the post is written | Compute who may see it at posting time and store that list or use it for fan-out. | Reads are a simple membership test. Fast. | Stale the moment a friendship, block or list changes. A blocked person keeps access. Huge lists for popular authors. |
| Check at read time against current data | On every read evaluate: viewer, author, audience, against the viewer's current friend set, blocks and lists. | Always right. Changes apply at once. The audience is stored as a small rule, not a huge list. | A check on every read, so it must be a cheap in-memory lookup. |
| Cache the allow decision per post | Remember “this post was allowed” and serve it to the next viewer. | Fastest. | Wrong by design. A decision made for one viewer is served to another. This is the classic leak. |
| Cache content, check every read | Cache the post content, keyed by post. Never cache the decision. Run the check on each request, with the friend sets themselves cached. | Fast and correct. Content caches are shared by everyone who may see it. | The friend-set cache must be invalidated quickly on a change. |
Invariant: a viewer sees a post only if the audience rule, evaluated against current relationships, says yes. Everything else is a hint. So the stored thing is a small rule (public, friends, friends except Dana, list 17, only me), not a list of people. The check runs on every read, as a library call that uses the viewer's cached friend set (about 300 IDs), block set and list memberships. That is a few memory lookups, so it fits inside the 200 ms budget.
Invalidation is the hard part. When someone is unfriended, blocked or removed from a list, the graph service bumps a version for that user and drops the cached sets, so the next read sees the change within a second. Blocks win over everything. Default deny: an unknown audience or a failed lookup hides the post. Private photos use short-lived signed URLs, so a link copied out of the page stops working. Counts, search results, notifications and tags are leak paths too, so each of them calls the same check.
| Audience | Rule | Needs |
|---|---|---|
| Public | Anyone, except people the author blocked | Block set |
| Friends | Viewer is in the author's friends | Friend set |
| Friends except Dana | Friends, and not Dana | Friend set and an exclusion |
| Custom list | Viewer is in list 17 | List membership |
| Only me | Viewer is the author | Nothing else |
The problem: 100 million photos a day, 250 TB a day stored, 280 Gbps out. App servers must not carry bytes. Photos need several sizes, scanning, privacy, and cheap storage as they age.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Upload through the app server | The client posts the file to the post service, which stores it. | Simple. | App servers carry 18 Gbps of upload and hold connections open. Retries re-upload everything. |
| Pre-signed direct upload | The service issues a short-lived URL, the client uploads straight to object storage, then confirms. | Bytes skip the app tier. Multipart and resumable. Scales with the store. | A confirm step, and cleanup for uploads never attached to a post. |
| Resize on every request | Keep only the original and make each size when requested. | No wasted storage on unused sizes. | CPU on the read path, and slow first views. |
| Resize once after upload, serve by CDN | An async job makes the standard sizes, scans for malware and policy issues, then marks the photo ready. | Fast reads, a CDN hit rate of 95%, and clean immutability. | A short delay before the photo is ready, and storage for each size. |
The client uploads straight to object storage, so the app tier never carries photo bytes. A queue triggers processing: scan for malware and policy violations, strip location data from metadata (a privacy default), and make a few standard sizes. Names are content-addressed or versioned, so a URL never changes and can be cached for a long time. A photo is only attached to a post when it is marked ready, and orphans are deleted after a day.
Public photos get long-lived URLs. Private photos get signed URLs that expire in minutes, so a copied link stops working, and the permission check is what decides to issue one. Old, rarely viewed photos move to cheaper storage tiers. Moderation is automated screening plus human review, and its rules are product decisions that are out of scope here.
The problem: One viral post turns every layer into a hot key. Users are worldwide. Fake accounts and spam arrive from day one. The design must keep working as each of these grows.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Scale everything uniformly | Add more of everything when load grows. | Nothing to design. | Does not fix hot keys. One row or one cache key cannot be spread by adding machines. |
| Target the hot spots | Sharded counters, replicated hot cache keys, in-process caches and request coalescing for viral posts. | Cheap and effective. Fixes the actual bottleneck. | Needs detection of hot keys and extra code paths. |
| One global deployment | A single copy of the graph and posts, read from everywhere. | Strongly consistent. Simple. | Slow for distant users, and one region failing takes everyone down. |
| Home region per user | Each user lives in a home region. Reads and writes are local, data is replicated to others asynchronously. | Fast and resilient. Matches data-residency rules. | Cross-region friendships and privacy changes need care. Replication lag is visible. |
Hot posts are the first problem: spread the counter, cache the post in each app server for a second or two, replicate the hot cache key, and let one request refill a missing key while others wait (see Cache Stampede and Hot Keys). Everything beyond that is added when a metric asks for it.
For regions, a user's home region owns their writes, so a friend change is local. A friendship across regions writes both homes through the same outbox. Privacy changes are sent first and with priority, because stale access is worse than a stale like count. Abuse is a first-class load: limit friend requests and posts per account, detect bursts of new accounts, and put new accounts on stricter limits.
Gus: was a friend, Ana blocked him.
A teaching model with fixed people, fixed posts and no random numbers. In mode C and D, Ben opens every post first, so the cache holds what Ben was allowed to see. The audience lists in mode A are worked out when the post is written. The 5k writes a second per counter row is an illustrative assumption, not a measurement. The exact like record, one row per (post, user), is a separate table and is not the thing being spread here.
| Bottleneck | Fix |
|---|---|
| Likes on a viral post (100,000 a second on one key) | Sharded counters (32 rows), an in-process aggregator for the hottest posts, and a cached sum. The exact like record stays one row per user. |
| Post reads (1.2M a second, 3.5M at peak) | Cache posts by ID with a 95% hit rate, in-process cache for hot posts, and coalesce misses so one request refills the key. |
| The permission check on every read | Cache each viewer's friend, block and list sets in memory, keep the audience as a small rule, and bump a version on change. |
| Celebrity and page follower lists | A separate follow model read in pages, never loaded whole, and cached top pages. |
| Photo bytes (250 TB a day in, 280 Gbps out) | Pre-signed direct upload, CDN for delivery, cheaper storage tiers for old photos. |
| Cross-shard friend writes | Outbox plus idempotent workers, a reconciliation job for one-sided rows, and alerts on outbox lag. |
| Comment threads under a popular post | Cache the first page for a few seconds, page by cursor, and limit reply depth. |
| Failure | How the design copes |
|---|---|
| The friend-set cache is cold or lost | Rebuild from the graph shard on demand with a per-user lock. Until it is ready, fail safe: show only public posts. |
| The outbox relay stops | Writes still commit locally. Friendships stay one-sided and are treated as not friends. Alert on lag, replay when the relay is back. |
| A counter shard or the counter store is down | Show the last cached count or hide it. Likes still record in the exact table, and a recount repairs the total. |
| Object storage or the CDN has an outage | Posts still load with text and a placeholder for photos. Retries with backoff. Uploads are resumable. |
| A database shard is slow or down | Replicas serve reads. Writes to that shard fail fast with a clear error, and other shards are unaffected. |
| A region goes down | Users fail over to another region with data a few seconds behind. Privacy changes replicate first so no one regains access. |
We built the platform core of a social network. The friend graph is sharded by user, with each friendship written on both users' shards through an outbox. Posts and comments are sharded by post. Likes are an exact unique record plus a sharded counter, so a viral post is not a hot row. Privacy is enforced on every read from in-memory sets, with content cached and decisions never cached, and a denied post looks like a 404. Photos go straight to object storage and come back through a CDN with signed URLs for private ones. The feed, messaging, notifications, video and search are separate designs that plug in through events.
| Decision | What we gain | What it costs |
|---|---|---|
| Friendship written on both users' shards | A friend list is one shard read, and the graph scales by adding shards. | A cross-shard step through an outbox, plus a reconciler for one-sided rows. |
| Privacy check on every read, content cached | Changes apply within a second and caches cannot leak. | A few memory lookups per read and a friend-set cache that must be invalidated fast. |
| Exact like record plus sharded approximate counter | No double likes, and no hot row on viral posts. | Counts lag by a second or two, and a periodic recount is needed. |
| Direct upload and CDN for photos | App servers never carry photo bytes. | A confirm step, orphan cleanup, and a short wait before a photo is ready. |
| Separate follow model for big accounts | Friend lists stay small, and the unbounded case is paged. | Two models to build, explain and keep consistent. |
| One region first, home regions later | A simple start, and a path to local speed and data residency. | A migration later, and cross-region friendships need care. |
Umbrella prompts are scored on judgement first. Say what you would build, and what you would not.
Where the leaks are. Interviewers want a single check, fast invalidation and a plan for deletion.
A change in requirements is a test of whether you understand why your design looks the way it does.
| New requirement | What changes in the design |
|---|---|
| Add a story that disappears after 24 hours | A short-lived post type with a TTL. Same permission check. Cleanup is by expiry, and views are counted with a small approximate counter. |
| Add groups and pages with their own privacy | A new audience type: group members. The check reads group membership. Large groups behave like large follow lists, so they are paged. |
| Private accounts that approve followers | A pending state on follow rows, and the audience of their posts is followers only. The approval write is idempotent and goes through the same outbox. |
| Edit posts and keep a history | Versioned post rows, with the latest pointer. Likes and comments stay attached to the post ID. Caches are invalidated on edit. |
| Tagging people in a photo | A tag widens the audience to the tagged person unless they decline. The check gets one more rule, and tags need their own approval and removal path. |
| Legal hold or a takedown request | A status on the post that the check understands, which hides it without deleting it. Deletion pipelines skip held items. Audit every action. |
| Reactions beyond likes (love, laugh, etc.) | The like key becomes (post, user) with a reaction type, so still one per user. Counters shard by type. The table grows only a little. |
| End-to-end encrypted private posts | The server cannot read content or evaluate the audience, so key management moves to clients, and search, moderation and recount features need rethinking. |
| Area | Weak | Good | Great |
|---|---|---|---|
| Scoping | Tries to design the whole company. | Picks a few flows and states the rest are out. | Names the siblings (feed, chat, notifications), links the boundaries by events, and says what to build first. |
| Estimation | Skips numbers or counts only users. | Posts, likes and reads per second, and storage. | Finds that likes dominate writes, post reads are 200 times the writes, and sizes the graph per shard. |
| Graph design | One table and a join. | Shards by user ID and stores both directions. | Handles the two-shard write with an outbox, idempotent steps and a reconciler, and treats celebrities separately. |
| Counters and consistency | likes = likes + 1. | Mentions sharded counters. | Separates the exact like record from the approximate count, and shows the numbers for a viral post. |
| Privacy | A flag on the post, checked in one place. | Checks on read. | States the invariant, caches content but never decisions, handles invalidation, default deny, 404s and leak paths. |
| Communication | Silent or jumps around. | Follows the seven steps. | Prioritises, names the costs of each choice, and says where it breaks at 10 times the load. |
| Mistake | Do this instead |
|---|---|
| Trying to design every feature of the product | Scope to three or four flows in the first minutes, and link the rest as separate systems. |
| Redesigning the feed and chat inside this answer | Say they are separate designs, give the event they listen to, and move on. |
| Storing a friendship once and joining at read time | Write it on both users' shards through an outbox, so a friend list is one shard read. |
| A single counter row for likes | An exact unique record plus a sharded counter, summed on read and cached briefly. |
| Caching an “allowed” decision per post | Cache content only, and run the permission check on every read. |
| Computing audience lists at write time | Store a small audience rule, and evaluate it against current relationships on read. |
| Sending photos through the app servers | Pre-signed direct upload, async processing, and a CDN with signed URLs for private photos. |
| Forgetting deletion and privacy changes in caches and search | A version bump on relationships, a deletion pipeline per system, and a shared check everywhere. |
The ranked home timeline that consumes this platform's events.
Messaging is a separate system with its own delivery design.
Turns likes, comments and friend requests into pushes and emails.
When multi-hop queries on the live path justify a graph engine.
The graph, posts and likes are all sharded, each by its own key.
A viral post is a hot key in the counter, the cache and the post row.
How a friendship reaches both shards, and events reach the bus.
Deletion and export across stores, caches and backups.