Design a content moderation system - decide for 500 million posts a day whether each one may be shown. A comment is checked inside 150 ms before it is published, images and video are checked after, and 1 item in 100 goes to a human reviewer. The staff-level signal is splitting the work by how long each check takes, keeping every decision as a new version that names its policy and its model, and making every writer say which version it read, so that a late answer never overrides a reviewer.
Written by a Staff+ Engineer and an Engineering Manager
12+ years of experience in distributed systems and real-time messaging. Tech lead for large-scale chat applications serving billions of users. Over 12 years of industry experience with 6 years in engineering leadership, building and scaling tech infrastructure teams that deliver end-to-end large-scale distributed systems.
Finished this lesson?
Sign in to save your progress across devices.
Tip: use ← and → to move between lessons.
Was this lesson helpful?
Rehearse this exact question with the author
45-minute mock with a Staff+ engineer who interviews at your target company. Premium members save $20.
What to Design?
Could you answer these today? Tick what you already know.
The first drawing is quick: a service takes an item, asks a model, and stores yes or no. The interview is decided by four questions about what happens when the model is slow, when people join the loop, and when two answers arrive at once. Each one is a deep dive later on this page, with three designs side by side.
Swipe to see all columns
| The four questions, and the answer that sounds right | |||
|---|---|---|---|
| # | The interviewer asks | The answer that sounds right | What it misses |
| DD1 | The text model is slow tonight. What does the 150 ms gate answer? | Wait, to be safe | A slow model then stops all posting. Allow for now, flag it, and check it in the background |
| DD2 | 5 million items a day need a human. Which one is next? | The one with the highest risk | One violent event fills the top of the queue. Every other category waits, and a reviewer sees nothing else all day |
The same three habits answer all four:
Do not spend your questions on how the model works. Spend them on who answers, how fast, and what happens when two answers disagree.
Swipe to see all columns
| Scope Decisions | ||
|---|---|---|
| Question | Agreed answer | Why it matters |
| Which content? | Text, images and uploaded video. No live streams | Three very different check times: milliseconds, seconds, minutes |
| Checked before or after publishing? | Text before, inside 150 ms. Images and video after | A fast gate for text and a background pipeline for media (Phase 1, Phase 2) |
| What if the gate cannot answer in time? | Posting must not stop. Allow for now and check later | |
Out of scope (say this out loud): live streams, user names and profile photos, encrypted chats that the platform cannot read, reports to the police, ads, and how the models are trained. The models are black boxes with a version number here. If the interviewer opens the box, see the ML section near the end.
FR1 — Decide. Take a text, an image or a video, and answer ALLOWED, BLOCKED or IN_REVIEW.
FR2 — Fast for text, later for media. A comment is checked before it is published. Images and video are published first and checked in the background.
FR3 — Human review. Unclear and high-risk items go to reviewers, in an order that is fair to every kind of content. A reviewer can overrule any earlier decision.
FR4 — Appeals. A user can appeal a decision. The appeal goes to another reviewer and produces a new decision.
FR5 — Check again, and explain. When a policy or a model changes, old content is checked again. Every decision records which policy, which model and who.
The key principle behind all five
Swipe to see all columns
| Four facts and the conclusions they do not supportRead each row as: the fact on the left does not, by itself, imply the claim in the middle. | ||
|---|---|---|
| Fact | Does not imply | Why the gap exists |
| The gate answered ALLOWED | The item is fine | The gate had 150 ms. A slower model or a person may say something else an hour later |
NFR1 — A fast gate. The text check answers within 150 ms for 99 requests in 100 (p99), so that posting a comment stays under 300 ms.
NFR2 — Posting never stops. When moderation is slow or down, posting still works. The gate may give a weaker answer. It never gives no answer.
NFR3 — Media in the background. An image is decided within about 5 seconds, a video within minutes.
NFR4 — One truth, and humans win. An item has exactly one current decision. Every earlier decision is kept, with its policy, its model and its author. A reviewer's decision is never overwritten by a late automated one.
NFR5 — Old work never slows new work. Checking old content again must not delay the check of a new upload.
| Capacity Thought Experiment | |
|---|---|
| Parameter | Value |
| New items | 500 million a day from 200 million users: about 6,000 a second, 30,000 at peak |
| Text | 70%: 350 million a day, 21,000 a second at peak |
| Images | 25%: 125 million a day, 7,500 a second at peak |
| Video | 5%: 25 million a day, 1,500 a second at peak |
| The gate | 150 ms of a 300 ms publish budget. Normally it needs about 45 ms |
The number that identifies the real system is the gap between three clocks:
the gate 150 ms 21,000 comments a second at peak
a video check ~3 minutes 1,200 times too slow for the gate
a person ~25 seconds 5 million items a day need 5,000 reviewers
One item gets several answers, minutes or days apart. The design is about keeping those answers in order. Every number above is an illustrative assumption.
Interviewer signal: candidates who draw one service that calls one model have missed the number. Candidates who say "I have three clocks: 150 ms at the gate, minutes for video, hours for people, so one item gets several decisions and I must keep them in order" have found the system.
Three ideas shape everything:
A comment has 150 ms. A video check takes minutes. A person can take hours when the queue is long. No single request can wait for all three. So the gate answers what it can in time, and everything slower runs in the background and reports back later.
The same video can be PENDING, then IN_REVIEW, then BLOCKED, then ALLOWED after an appeal. Each answer is a new row with a version number, the policy, the model and the author. Nothing is overwritten. The highest version is what users see.
A worker that started three minutes ago can finish after a reviewer has decided. So every writer says which version it read. If the item has moved on since then, the write is refused.
The core recognition
This is two pipelines around one ledger. A fast gate and a slow background pipeline both write to the same list of decisions. A ledger is a list that is only ever added to.
| Design Decisions | |
|---|---|
| Design choice | Reason |
| A gate with a hard 150 ms deadline for text | Posting a comment waits for it, so it must always answer in time |
| The gate waits at most 100 ms for the model | A slow model costs accuracy for a while. It never costs posting (DD1) |
Two tables carry the design:
itemsanddecisions. The field to explain isversion: it puts the answers in order, and it decides who may write.
One row per comment, image or video. It holds what users see right now.
Swipe to see all columns
| items | ||
|---|---|---|
| Field | Type | Comment |
item_id | STRING | Key. For example c-101 for a comment, v-205 for a video |
account_id | STRING | Who posted it |
type | ||
One row per answer. Rows are added, never changed.
Swipe to see all columns
| decisions | ||
|---|---|---|
| Field | Type | Comment |
item_id, version | STRING, INT | Key. Version 1 is the first answer for this item |
decision | ENUM | |
Swipe to see all columns
| Supporting records | ||
|---|---|---|
| Record | What it holds | Why it exists |
| Review queue row | item_id, category, priority, leased_by, lease_until | One item that waits for a person. Written to PostgreSQL first, then copied into Redis |
| Policy and model versions | ||
A score is not a decision. Every model returns a score from 0 to 1: how likely the item breaks a rule. Two thresholds turn the score into an answer. Below 0.30 the item is ALLOWED. At 0.90 or more it is BLOCKED. In between it is IN_REVIEW: a person decides.
Swipe to see all columns
| Storage | ||
|---|---|---|
| Store | Data | Consistency |
| PostgreSQL | items, decisions, review_queue | The source of truth. Split over machines by item_id, so all rows of one item change in one transaction |
| Kafka | The topics jobs, backfill and decisions | At least once. Events are kept, so they can be read again |
| Redis | The fast copy of the review queue (DD2) | |
The publish service is the caller that matters. It needs three things: to ask, to be told, and to look it up. Being told is a webhook: moderation calls the publish service when a decision changes.
Swipe to see all columns
| The calls | ||
|---|---|---|
| Call | Who calls | What it does |
POST /v1/items/{id}/moderate | Publish service | Checks a new item. For text the answer is the decision. For media it is PENDING, version 0. Safe to repeat |
GET /v1/items/{id}/decision | Publish service | The current state and version, from the ledger. The truth when a webhook was missed |
The one write that every decision uses. Gate, worker and reviewer all write a decision the same way:
BEGIN;
UPDATE items SET state = 'BLOCKED', version = 2
WHERE item_id = 'v-205' AND version = 1; -- 1 is the version this writer read
-- 0 rows updated: somebody else decided first. Stop, write nothing.
INSERT INTO decisions (item_id, version, decision, actor, reviewer_id, policy)
VALUES ('v-205', 2, 'BLOCKED', 'reviewer', 'rita', 'P7');
COMMIT;
This is a compare-and-swap: the change happens only if the value is still the one the writer saw. On this page it is called "write if the version is still N".
Present the design as four short stories, each in its own colour on one whiteboard: Phase 1 the text gate (black), Phase 2 media later (blue), Phase 3 a human decides (green), Phase 4 a new model (purple). The number on an arrow is the same number in the animation and in the step table.
Swipe to see all columns
| The four phases | |||
|---|---|---|---|
| Phase | Colour | Story | What it leaves behind |
| Phase 1: The text gate (FR1, FR2) | Black | Alice posts a comment. The gateway checks it and answers before it is published | An item row and decision version 1 |
| Phase 2: Media later (FR2) | Blue | Bob uploads a video. It goes live at once and a worker checks it a few minutes later | Decision version 1: IN_REVIEW |
How to read the picture
c-101, Bob's video v-205 and Carol's video v-310.Each phase below is an interactive walkthrough of the same picture. It plays on its own. You can pause it, step with the arrow keys, and click any component to read its role.
Goal: answer for a comment before it is published, well inside 150 ms.
/v1/items/c-101/moderatePublish service → Moderation gatewayAlice's request waits for the answerNothing is written in this step.
Swipe to see all columns
| Phase 1 step by step (black arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | Alice posts the comment "Love this recipe!". Before showing it, the publish service asks the gateway: POST /v1/items/c-101/moderate. Alice's request waits for the answer. | Nothing |
| 2 | The gateway sends the text to the text model, with a limit of 100 ms. At the same time it checks the rules of policy P7, which it keeps in memory. No rule is hit. That takes 2 ms. | Nothing |
Why it is built this way
The other two answers. A score of 0.90 or more gives BLOCKED: the comment is refused and the author is told. A score in between gives IN_REVIEW: the comment is held back, and a row goes into the human queue (Phase 3).
A larger model is more accurate and needs half a second or more. Nobody accepts a comment that takes that long to appear. The fast model settles what is clear, which is almost everything. What is unclear lands in the middle band and goes to a person.
Goal: let a video go live at once, and check it without making anyone wait.
/v1/items/v-205/moderatePublish service → Moderation gateway200 at oncev-205new rowSwipe to see all columns
| Phase 2 step by step (blue arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | Bob uploads v-205.mp4, 60 seconds, 40 MB, to S3. The publish service asks the gateway and gets the answer at once: PENDING, version 0. The video goes live. | items row v-205: PENDING, version 0 |
| 2 | ||
Why it is built this way
decisions is copied to the topic decisions by the database's change stream, and the notifier reads that topic. A stored decision is always announced.Images. An image gets one quick check at the gate: its fingerprint is looked up in a list of known-bad images. A hit is BLOCKED at once. Otherwise the image is PENDING and takes the same road as a video, with an answer in about 5 seconds.
No. The notifier repeats a webhook until the publish service confirms it. And for an item that stays PENDING longer than expected, the publish service asks GET /v1/items/v-205/decision.
Goal: give the item to the right reviewer, and record a decision that nothing automated can undo.
ZADD rq:us:dangerous-acts 1.86 v-205Decision ledger → Review queuev-205new rowSwipe to see all columns
| Phase 3 step by step (green arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | The queue row of v-205 is copied into Redis, into the queue of its category, where items are ordered by priority. Its priority is the score 0.62, times 3 for the feed, times 1.0 for a new item: 1.86. | One entry in rq:us:dangerous-acts |
| 2 | Rita asks for her next item. It is the turn of the category dangerous-acts. The review tool takes the entry with the highest priority: v-205. | The entry leaves the set |
Why it is built this way
review_queue.Appeals (FR4). Bob appeals with POST /v1/items/v-205/appeal. That adds a new queue row with double priority, for a different reviewer. Sam watches the video and decides ALLOWED: version 3. The video is back. One appeal is allowed per decision.
Her lease ran out after 5 minutes, so another reviewer may have the item now. Rita's write still names version 1. If nobody has decided yet, it succeeds, and the other reviewer's later write is refused. If somebody has, Rita's write is refused and her tool shows the new decision. The lease says who is working. The version check keeps the result correct.
Goal: apply a new model to last month's videos, without slowing down the check of new ones.
/v1/admin/reprocessPolicy team → Backfill controllerSELECT item_id FROM items, page by pageBackfill controller → Decision ledger750 million idsreprocess V4, P8new rowSwipe to see all columns
| Phase 4 step by step (purple arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | The policy team starts a backfill: model V4, policy P8, all videos of the last 30 days. The backfill controller reads their ids from the ledger, page by page. There are 750 million. | The job, and how far it has come |
| 2 | For every video the controller leaves one event on the topic backfill, not on jobs. It sends at most 500 a second. | Events on backfill |
Why it is built this way
The newest and the most watched. A video collects most of its views in its first days, so that is where a wrong "allowed" does the most harm. A video from four weeks ago that nobody opens any more can wait until the end.
The deep dives are the four questions from the top of the page. Each one compares three designs for the same scenario: a Bad one, which is usually the answer that sounds right; a Good one, which still leaves a gap; and a Great one, which holds. The answers start covered. Read the scenario, decide what you would build, then click each card.
Swipe to see all columns
| Deep Dive Map | |||
|---|---|---|---|
| Deep Dive | Topic | Scenario | NFR |
Scenario: A big story breaks at 8 pm. 21,000 comments a second come in. The text model is overloaded: its answer time goes from 30 ms to 900 ms, for 20 minutes. The gate has 150 ms. Eve posts comment c-140, an insult aimed at another user. The model would give it 0.97. What does the gate answer?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. The gate calls the text model and waits for the score. No comment is published without a check.
Where it breaks. Tonight the model needs 900 ms. Posting a comment may take 300 ms, so every post times out: 21,000 a second, for 20 minutes. Nothing harmful got through, because nothing got through at all. A slow model has become a full outage of commenting.
The idea. The model call gets a limit of 100 ms. If no score arrives in time, the gate answers ALLOWED.
What it fixes. Posting. Every comment gets its answer inside 150 ms again.
What it still misses. The check. In those 20 minutes about 25 million comments went live without a score, and no row says which ones. Eve's insult stays up, and nobody can find the unchecked comments later.
The key idea. A missing score is not an allow. It is a debt. Write it down, and pay it when the model is back.
How it works
ALLOWED, version 1, with degraded set.jobs.c-140 gets 0.97: , version 2, and the webhook removes it.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
/v1/items/c-140/moderatePublish service → Moderation gatewayEve's request waits for the answerNothing is written in this step.
Swipe to see all columns
| DD1 side by side | |||
|---|---|---|---|
| Bad: wait | Good: allow and forget | Great: allow, flag, check later | |
| Posting during the 20 minutes | Fails for everyone | Works | Works |
| Eve's insult | Is never posted, like everything else | Stays up for good | Is up for about 4 minutes |
Check it against the scenario
| The model needs 900 ms | |
|---|---|
| Situation | Outcome with the Great option |
| A comment contains a banned phrase | The rules catch it without the model: BLOCKED, also in degraded mode |
| The later check says a comment is fine | It writes version 2: ALLOWED, now with a score. The debt is paid |
| The model answers in 30 ms again | New comments get the full check, and the jobs that piled up are worked off in minutes |
| The model stays slow for an hour | More than 5% of the answers are degraded for 5 minutes: the on-call engineer is paged. Degraded mode is for minutes, not for the night |
The trade-off to name. In degraded mode some harmful comments are visible for a few minutes. That is the price of never stopping posting, and it is acceptable only because every such comment is marked and checked. For the worst kinds of content the trade is made differently: a rule hit and a known-bad image are blocked without any model.
It is the Bad option with a faster error. Every comment would be refused for 20 minutes, which is the same outage. "Safe" has two sides here: showing harm, and silencing 200 million users. Allowing with a later check keeps the first down to minutes and avoids the second.
"The gate has 150 milliseconds, so the model call gets a hard limit of about 100. If the model does not answer, I do not block publishing and I do not silently allow. I write a tentative allow that is flagged as degraded, put the item on a queue, and answer in time. When the model recovers, a worker scores those items, and a block is a new decision version plus a webhook. The rules still run, a circuit breaker protects the slow model, and the share of degraded answers has an alert."
Follow-up: "What if the ledger is slow, not the model?" — Same idea. The gate answers a tentative allow and puts the item on the topic. A worker writes the first decision once the ledger is back.
Scenario: 1,700 reviewers are online. Together they decide 68 items a second, and normally 58 a second arrive. Then a violent event makes it 290 a second for one hour. About 800,000 items pile up, nearly all in the category violence. Spam, fraud and Bob's v-205 keep arriving too. Which item does Rita get next?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. The waiting items are rows in a table. For the next item, the tool asks for the row with the highest priority and locks it, skipping rows that others have locked.
Where it breaks. Priority is not fixed: an item becomes more urgent the longer it waits. So a job rewrites the priority of every waiting row once a minute. With 800,000 rows that is 13,000 row updates a second, on the same index that 1,700 reviewers read from. Taking an item goes from 5 ms to seconds. Reviewers wait for work while the pile grows.
The idea. A sorted set in Redis keeps its members ordered by a score. Each waiting item is a member, and its priority is the score. The row in PostgreSQL is still written, and written first.
What it fixes. Speed. Taking the top item is one command and takes under a millisecond. Changing a priority is one command in memory. If Redis loses everything, the set is rebuilt from the table.
What it still misses. Fairness. The 800,000 violence items have the highest scores, so they fill the top of the set. Spam and fraud wait behind them for hours. Rita gets violence for her whole shift. And reviewers who are not trained for violence get items they may not decide.
The key idea. Priority orders the items inside one category. It must not decide between categories. Categories take turns, and no reviewer gets too much of one.
How it works
rq:us:violence, rq:us:spam, rq:us:dangerous-acts.violence. One item costs one token. Without tokens, that category is skipped until the hour turns.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
SELECT ... FROM review_queue ORDER BY priority DESC LIMIT 1 FOR UPDATE SKIP LOCKEDReview tool → Decision ledgerthe top row that nobody else holdsNothing is written in this step.
Swipe to see all columns
| DD2 side by side | |||
|---|---|---|---|
| Bad: a polled table | Good: one sorted set | Great: sets per category, tokens, cap | |
| Taking the next item | A sorted query with row locks | One command, under a millisecond | One command, on the category whose turn it is |
| A new priority | Rewrites a row and its index entry | One command in memory | One command in memory |
Check it against the scenario
| 800,000 violence items in an hour | |
|---|---|
| Situation | Outcome with the Great option |
| Rita has used her 60 violence tokens | She gets spam and dangerous-acts until the hour turns |
| A spam item arrives during the surge | It waits behind other spam only. Its turn comes at the usual pace |
| A violence item has waited 4 hours | The timer writes BLOCKED, actor timer. The author can appeal, and an appeal always gets a person |
The trade-off to name. The wait cap decides for people. In a surge like this one, a large part of the pile is blocked by the timer, and some of those items were fine. The other levers cost money or accuracy: call in more reviewers, raise the token limit for a day, or move the thresholds so that fewer items need a person (see the ML section).
It is fair to the time of arrival and unfair to harm. A threat of violence in the feed and a spam comment would wait the same hours. So priority is needed. And priority alone starves the calmer categories, which is the Good option. Turns between categories, with priority inside each one, give both.
"About one percent of items go to people, five million a day, so the human queue is a system of its own. Each queued item is a durable row in PostgreSQL first, then an entry in a Redis sorted set, scored by risk, surface and waiting time. The review tool pops from Redis and writes a lease to the table, so a Redis loss or a crashed session loses nothing. One global set would let a surge in one category starve the others. So I keep one set per region and category, rotate between the categories a reviewer is trained for, limit how much of a hard category one person gets per hour, and cap the waiting time."
Follow-up: "Why Redis and not Kafka for this queue?" — Kafka hands out items in the order they arrived. Reviewers need the most urgent item they are allowed to see, and that order changes while items wait.
Scenario: Dave's video v-420 is live and PENDING, version 0. A video worker started its scan at 12:00 and needs 3 minutes. At 12:01 viewers report the video. At 12:02 Rita looks at it and blocks it. At 12:03 the worker finishes: score 0.12, allow. What do viewers see at 12:04?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. Each item has one row with a state column. Whoever has an answer writes it into that column.
Where it breaks. Rita writes BLOCKED at 12:02. The worker writes ALLOWED at 12:03, and the video is back. The last write won, and it carried the oldest opinion: the worker decided from what it read at 12:00. And no row says that Rita ever blocked the video. Nobody can explain what happened, and nobody can repair it.
The idea. Decisions are rows that are only added: who, what, when. The current state of an item is its newest row.
What it fixes. The history. Both answers are on record: Rita's block at 12:02, the worker's allow at 12:03. The mistake can be found and explained.
What it still misses. The mistake itself. The newest row is the worker's, so the video is back, until somebody complains. The newest row is not the newest knowledge.
The key idea. Do not ask who wrote last. Ask whether the writer had seen the current answer. If not, its write is refused.
How it works
The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
UPDATE items SET state = BLOCKED WHERE item_id = v-420Review tool → Decision ledgerthe video is downv-420updateSwipe to see all columns
| DD3 side by side | |||
|---|---|---|---|
| Bad: update in place | Good: newest row wins | Great: the version check | |
| What is stored | One state per item | Every decision, with its time | Every decision, with its version |
| Rita at 12:02, the worker at 12:03 | The worker overwrites Rita | The worker's row is the newest | The worker's write is refused |
Check it against the scenario
| Rita at 12:02, the worker at 12:03 | |
|---|---|
| Situation | Outcome with the Great option |
| The worker finishes before Rita decides | The worker writes version 1. Rita's write names 0 and is refused. Her tool shows the worker's answer, she confirms, and her second write makes version 2 |
| Rita and Sam decide the same item in the same second | One write finds the version unchanged. The other is refused, and its tool shows the first decision |
| The webhook for version 1 arrives after the one for version 2 | The publish service holds version 2 and ignores it |
The trade-off to name. A writer that loses has worked for nothing: a 3-minute video scan is thrown away. That is cheap next to a blocked video that comes back. Note where each rule lives: "nobody writes blind" is enforced by the database, and "a reviewer beats a model" is a rule in the writers.
It fixes this case and breaks the next ones. Two reviewers disagree in the same second: who wins? A reviewer allowed a video a year ago under an old policy: must it stay allowed for ever? A rank says who should win. It does not say whether a writer had seen the latest answer. The version check does.
"I keep decisions in an append-only table keyed by item and version, and the item row holds the current version. Every writer reads the version first and writes with a condition: update the item only if the version is still the one I read, and insert the decision in the same transaction. If the condition fails, somebody decided in between, and the writer has to look again. An automated writer that finds a human decision drops its result. So a worker that started three minutes ago cannot bring back a video that a reviewer just blocked."
Follow-up: "Why a version number and not a timestamp?" — Clocks on two machines differ by milliseconds, and two writes can carry the same time. A counter per item has no ties: exactly one writer turns 1 into 2.
Scenario: A dangerous challenge spreads. The policy team adds a rule, policy P8, and a new video model V4 can spot such videos. The 750 million videos of the last 30 days were judged by V3. The video workers can check 2,000 videos a second. Live uploads need up to 1,500. How does V4 take over?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. Replace V3 with V4 on all video workers. From now on every upload is scored by the new model.
Where it breaks. The 750 million old videos keep their V3 answers, so last month's challenge videos stay up. The decision rows do not say which model made them, so nobody can tell which answers are old. And V4 decides everything from the first minute. If it blocks too much, every upload is hit before anyone notices.
The idea. Every decision records its policy and its model. A script puts all 750 million old videos on the topic jobs, and the workers check them again with V4.
What it fixes. The old videos. Each one gets a new decision where the answer changed, and every row says V4, P8.
What it still misses. The live checks. New uploads sit in the same topic, behind the old videos. At 2,000 a second the pile takes over 4 days, so a new video is now checked days after it went live, not minutes. And V4 still took over in one step.
The key idea. A new model earns trust before it decides. And old content never stands in the same line as new content.
How it works
V4 scores live videos next to V3. It writes scores, no decisions. The two are compared.V4 decides for 5% of live uploads. Block rate, reviewer overrules and appeal results are watched. Then 100%.backfill, newest first, at most 500 a second.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
deploy model V4all video workersNothing is written in this step.
Swipe to see all columns
| DD4 side by side | |||
|---|---|---|---|
| Bad: swap in place | Good: replay on the live topic | Great: prove it, then a separate lane | |
| The 750 million old videos | Never checked again | Checked again, in over 4 days | Checked again, in about 17 days |
| A new upload meanwhile | Checked in minutes | Waits for days | Checked in minutes |
Check it against the scenario
| V4 takes over from V3 | |
|---|---|
| Situation | Outcome with the Great option |
| In shadow, V4 would block 1.3% of videos. V3 blocks 1.0% | Reviewers look at a sample of the videos where the two disagree. V4 moves on only if they side with it |
| The canary's appeal results get worse | V4 is switched off for the 5%. Its decisions carry the model name, so they can be found and checked again |
| V4 says block, and a reviewer had allowed it | The decision stays. The item goes back to the review queue with the new score |
The trade-off to name. Time. The careful road takes days of shadow and canary and then 17 days of backfill, and last month's challenge videos stay up in the meantime. So the backfill goes newest and most watched first, and its speed limit is raised at night, when live traffic is low.
A task queue deletes a message once it is done. Here the events are worth keeping. When the next model comes, the same months of items can be read again, at any speed, by a second group of consumers, and the live group does not notice. Checking again becomes a normal operation, not a special script.
"A model change has two parts: the new traffic and the old content. For new traffic I never swap in place. The new model runs in shadow first, scoring the same items and writing only scores, so I can compare it with the live one. Then a small canary, watching block rate, reviewer overrules and appeal results, then everything. For old content, a controller scans the ledger and feeds a separate topic at a capped rate, and the same workers read it as a second consumer group, so live checks keep their capacity. Backfill writes use the same conditional write, add a version only where the answer changes, and never overwrite a human decision: a disagreement goes back to review."
Follow-up: "How do you roll back?" — Every decision names its model. Point the workers back at V3, list the decisions that V4 made, and run those items through the backfill lane once more.
So far the models were black boxes with a version number. Some interviewers open the box: "how would you build the classifier?" You do not need a research answer. You need the eight rows below, and the three traps that are special to moderation.
| The ML side in one table | |
|---|---|
| Question | Short answer |
| What does the model predict? | For one item and one rule category, a score from 0 to 1. One score per category, not one "bad" bit: violence and spam are different problems |
| Where do the labels come from? | Reviewer decisions, appeal results and confirmed user reports. Plus a small random sample of allowed items that is sent to review |
| Which features matter? | The text itself. Frames and sound for video. The account's age and earlier violations. Where it is posted. How fast reports come in |
| Which model, simple first? | Rules and fingerprints of known-bad media. Then a small text classifier that answers in 30 ms at the gate. Then a larger model for images and video that runs later |
Trap 1: the thresholds are a staffing decision. Two thresholds cut a day's 500 million items into three bands. Say 1 item in 100 breaks a rule: 5 million a day. All numbers here are illustrative:
Swipe to see all columns
| One day in three bands | ||
|---|---|---|
| Band | Items a day | What is inside |
| Score 0.90 or more: blocked | 2.5 million | 98% rightly blocked. 50,000 wrongly blocked, and those people appeal |
| Between 0.30 and 0.90: to reviewers | 5 million | 2 million break a rule, 3 million are fine |
| Below 0.30: allowed | 492.5 million | 550,000 break a rule and are missed |
The middle band is 5 million items a day: exactly what 5,000 reviewer shifts can decide. Now lower the allow threshold from 0.30 to 0.20. Fewer bad items slip through, but say the middle band doubles to 10 million a day. That needs 10,000 shifts, or the queue grows by 5 million a day. So thresholds are set per category, by the cost of a miss: low for the worst kinds of harm, higher for spam.
Trap 2: accuracy says nothing. 99 items in 100 are fine. A model that allows everything is 99% accurate and useless. Ask two questions instead. Precision: of the items the model blocked, how many deserved it? In the table: 2.45 of 2.5 million, 98%. Recall: of the items that deserved it, how many did the model find? The automatic block finds 2.45 of 5 million, 49%. With the review band it is 4.45 of 5 million, 89%.
Trap 3: the labels are biased. Reviewers only see what the model sent them. What the model wrongly allowed never gets a label, so the next model learns the same blind spot. The fix is the random sample of allowed items. Appeals fix the opposite error: wrong blocks.
The offline score was measured on yesterday's content. Content changes, and people who want to get past the model adapt to it. Shadow and canary show what the model does on today's traffic, before it decides anything. DD4 is as much an ML answer as a systems answer.
| If the interviewer keeps going | |
|---|---|
| Question | Short answer |
| The webhook is lost, or arrives twice | The notifier repeats it until it is confirmed. The publish service keeps the highest version it has seen and ignores the rest. For anything unclear it reads GET /v1/items/{id}/decision |
| The ledger is slow or down | The gate answers a tentative allow and puts the item on the topic jobs. A worker writes the first decision when the ledger is back |
| One account breaks the rules again and again | Keep a strike count per account, fed by decisions that a reviewer confirmed. Warn, then suspend, then ban. The limits belong to the policy version, so a stricter policy does not change what counted before |
A video check takes minutes and the request has milliseconds. Answer PENDING, leave a job, and report back by webhook.
A slow model then stops all posting. Give the call a hard limit that is well inside the gate's budget.
The unchecked items look like checked ones, and nobody can find them. Flag every such answer and check it later.
The history is gone, so no decision can be explained. Add a new decision row for every answer.
A worker that started minutes ago writes last and knows least. Every write must name the version it read.
One busy category fills the top, the others starve, and a reviewer sees nothing else all day. Use a queue per category and take turns.
New uploads then wait behind 750 million old videos. Old content gets its own topic and its own speed limit.
A model that blocks too much hits every upload at once. Let it watch first, then decide for 5%, then for all.
The shape of a strong answer: start with one service and one model, and show the three clocks. Then add a gate with a hard deadline for text, a queue and a webhook for media, a version for every decision, a queue per category for people, and a lane of its own for old content.
Answer in the time you have, finish the check later
150 ms at the gate, minutes for video, hours for people. The gate answers what it can and flags the rest. The slower checks follow as new versions.
Never overwrite a decision
Every answer is a new row with a version, a policy, a model and an author. The highest version is what users see, and every earlier one can still be explained.
A writer names the version it read
One conditional write decides between a reviewer and a late worker, between two reviewers, and between a backfill and the live pipeline.
| What the interviewer expects at each level | |
|---|---|
| Level | A strong answer shows |
| Junior | The three answers: allow, block, review. Why text is checked before publishing and media after. Two pipelines, a store for decisions and a queue for reviewers |
| Mid-level | Treats the gate and the background pipeline as two problems with two time budgets. Names the states and how a reviewer overrules a model. Knows that the human queue needs priority, and that decisions need a policy and a model version |
| Senior | Goes to the hard parts unasked: what the gate answers when the model is slow, how a reviewer wins against a late worker, and how old content is checked again without slowing live checks. Explains why the versioned ledger carries all three |
These aren't toy problems — they reflect real infrastructure challenges at companies that run trust and safety at scale. If you want to walk through this design in a mock interview or get feedback on your own approach, book a session with us. We're here to help you sharpen your thinking, build your confidence, and land your next offer.
Pick an answer for each question, and you see at once whether it is right. Show explanation opens the answer, why it is right, and why each of the other options fails.
Question 1 of 10
The text model needs 900 ms tonight. The gate has 150 ms. What does the gate do with a comment that hits no rule?
Question 2 of 10
Bob uploads a 40 MB video. What does the gateway answer to the publish service?
Question 3 of 10
500 million items a day, 1% of them go to human review, and a reviewer decides about 1,000 items in a shift. How many reviewer shifts a day?
Question 4 of 10
An item that waits for a reviewer is written to PostgreSQL first and to Redis second. Why this order?
Question 5 of 10
What do a reviewer's tokens do?
Question 6 of 10
During a surge an item has waited 4 hours for a reviewer. What happens?
Question 7 of 10
A video worker read version 0 at 12:00. Rita blocks the video at 12:02: version 1. At 12:03 the worker tries to write ALLOWED. What happens?
Question 8 of 10
The publish service holds version 2 for a video: BLOCKED. A late webhook arrives: version 1, IN_REVIEW. What does it do?
Question 9 of 10
A new model must check 750 million old videos again. How is that done without slowing down the check of new uploads?
Question 10 of 10
Items with a score below 0.30 are allowed. Items between 0.30 and 0.90 go to reviewers: 5 million a day. The allow threshold is lowered to 0.20. What happens?
| DD3 | A reviewer blocks a video while a worker is still scanning it. Who wins? | The latest write | The worker's late "allow" is the latest write. Every writer must name the version it read |
| DD4 | A new model ships. What about the 750 million videos of last month? | Swap the model and run them all again | On the live pipeline that makes new uploads wait for days. And a new model must prove itself before it decides |
| A weaker answer with a re-check, never no answer (DD1) |
| Are human reviewers part of it? | Yes. About 1 item in 100, and their decision overrules any model | A queue for people, and a rule for who wins (DD2, DD3) |
| Can users appeal? | Yes. An appeal goes to a second reviewer | The answer for one item changes over time. Keep every version |
| Do rules and models change? | Every week. Old content is then checked again | Every decision names its policy and model, and old content gets its own lane (DD4) |
| The model returned a score | A decision exists | A score is a number. Two thresholds turn it into allow, review or block |
| This write is the newest | This answer is the newest | A worker that started three minutes ago writes last and knows least |
| The new model is better in tests | It may decide tonight | It was tested on yesterday's content. It runs next to the old one first |
| A video check |
| About 3 minutes from upload to decision |
| Human review | 1% of items: 5 million a day, 58 a second |
| One reviewer | About 25 seconds an item, about 1,000 items a shift. So 5,000 reviewer shifts a day |
| Appeals | 0.1% of decisions: 500,000 a day |
| Decision rows | A bit over 500 million a day, about 100 GB a day |
Media is answered PENDING and checked from a Kafka topic |
| A video check takes minutes. No request can wait that long |
A decisions table that is only added to, with a version per item | Every answer stays, with its policy, model and author, so each one can be explained |
| Every write says: only if the version is still N | A late worker cannot overwrite a reviewer (DD3) |
| A Redis queue per category, with a table behind it | Fast to take from, fair between categories, and it can be rebuilt (DD2) |
| A second Kafka topic for old content | A backfill of 750 million videos never delays a new upload (DD4) |
ENUM |
| text, image or video |
surface | ENUM | Where it is shown: feed, comments or dm |
state | ENUM | PENDING, ALLOWED, BLOCKED or IN_REVIEW |
version | INT | The number of the current decision. 0 means: no decision yet |
ALLOWED, BLOCKED or IN_REVIEW |
actor | ENUM | Who answered: gate, worker, reviewer, backfill or timer |
policy | STRING | The set of rules in force, for example P7 |
model, score | STRING, FLOAT | The model that scored the item, for example V3, and its score from 0 to 1. Empty when a person decided |
reason | STRING | The rule category, for example dangerous-acts |
reviewer_id | STRING | Set when a person decided |
degraded | BOOL | True when the gate answered without the model (DD1) |
| P7, P8, T4, V3, V4: never changed once published |
| A decision points at them, so the rules behind it can be shown years later |
Disposable. It is rebuilt from review_queue |
| S3 | The image and video files | Written once by the upload. Read by workers and reviewers |
Webhook: item, state, version| Notifier |
| Sent to the publish service for every new decision, at least once. A version that is not higher than the one it holds is ignored |
POST /v1/items/{id}/appeal | Publish service | Puts the item back into the review queue, for a different reviewer |
POST /v1/review/next | Review tool | Gives a reviewer the next item, leased for 5 minutes |
POST /v1/review/items/{id}/decision | Review tool | Records the reviewer's answer, with the version the reviewer saw |
POST /v1/admin/reprocess | Policy team | Checks old content again with a given policy and model |
| Phase 3: A human decides (FR3) | Green | Rita, a reviewer, gets Bob's video, watches it and blocks it | Decision version 2, written by a person |
| Phase 4: A new model (FR5) | Purple | A new video model checks last month's videos again and blocks one of Carol's | A new version only where the answer changed |
| The text model T4 answers after 30 ms: score 0.03. That is below 0.30, so the comment is allowed. |
| Nothing |
| 4 | The gateway writes the item and its first decision in one transaction. | items row c-101: ALLOWED, version 1. decisions row c-101, version 1: gate, P7, T4, 0.03 |
| 5 | The gateway answers ALLOWED, version 1, about 45 ms after the request. The comment is shown. | Nothing |
jobs| One event: item v-205, video |
| 3 | A video worker reads the event. | Nothing |
| 4 | The worker reads the file straight from S3. Model V3 looks at one frame a second and listens to the sound. Score: 0.62. | Nothing |
| 5 | 0.62 lies between 0.30 and 0.90: a person must decide. The worker writes IN_REVIEW, if the version is still 0. In the same transaction it adds a row to the human queue. | items row v-205: IN_REVIEW, version 1. decisions row version 1: worker, V3, 0.62. A review_queue row |
| 6 | The notifier calls the publish service: item v-205, IN_REVIEW, version 1. The publish service hides the video until a person has decided. | Nothing |
| The tool leases the item to Rita for 5 minutes. |
review_queue row v-205: leased by rita, for 5 minutes |
| 4 | The tool gives Rita a signed link to v-205.mp4. The link works only in her session. | The access is logged |
| 5 | Rita decides: BLOCKED, reason dangerous-acts. Her tool sends the version she saw, 1. The write succeeds because the version is still 1. | items row v-205: BLOCKED, version 2. decisions row version 2: reviewer rita. The queue row is closed |
| 6 | The notifier calls the publish service: item v-205, BLOCKED, version 2. The video stays down and Bob is told. | Nothing |
| 3 | The same video workers read backfill as a second group, with its own speed limit. The live jobs are not slowed down. | Nothing |
| 4 | A worker reads v-310.mp4 from S3. Model V4 gives it a score of 0.96. | Nothing |
| 5 | The video is ALLOWED, version 1: V3 had scored it 0.22. The new answer is BLOCKED. The worker writes it, if the version is still 1. A video that gets the same answer as before gets no new row. | items row v-310: BLOCKED, version 2. decisions row version 2: backfill, P8, V4, 0.96 |
| 6 | The notifier calls the publish service: item v-310, BLOCKED, version 2. The video comes down. | Nothing |
| DD1 |
| The text model is slow tonight |
| The model needs 900 ms, the gate has 150 |
| NFR1, NFR2 — Fast gate, posting never stops |
| DD2 | Which item does a reviewer get next? | 800,000 items of one category pile up in an hour | FR3 — Human review, in a fair order |
| DD3 | A reviewer and a late worker write at the same time | Rita blocks at 12:02, a worker allows at 12:03 | NFR4 — One truth, humans win |
| DD4 | A new model, and 750 million old videos | Workers do 2,000 a second, live needs 1,500 | NFR5 — Old work never slows new work |
BLOCKED| The 25 million comments without a score |
| There are none: nothing was posted |
| Unmarked. Nobody can find them |
| All flagged, all checked afterwards |
BLOCKED, and the author can appeal.| During the surge |
| Taking an item needs seconds |
| Fast, but violence fills the top |
| Violence is slower, the rest moves as usual |
| One reviewer's day | Whatever is on top | One category all shift | At most 25 minutes of violence an hour |
| What viewers see at 12:04 |
| The video |
| The video |
| Nothing: it is blocked |
| Can it be explained later? | No | Yes, after somebody complains | Yes, and there is nothing to repair |
backfill as a second consumer group: readers with their own place in the topic and their own limit. The live jobs keep their 1,500 a second.V4 disagrees with it, the item goes back to the review queue.| V4 blocks too much |
| Every upload is hit |
| Every upload is hit |
| Seen in shadow, before it decides anything |
| Why was this video blocked? | Nobody knows | V4, policy P8 | V4, policy P8 |
| Offline metric |
| Precision and recall per category, at the two thresholds. Never accuracy |
| Online metric | The share of views that land on violating content, measured on a random sample. Also how often reviewers overrule the model and how often appeals succeed |
| How is it served? | The fast model in the gate with a 100 ms limit. The slow models behind the topic jobs. Every score is stored with its model version |
| How is it rolled out? | Shadow, then 5%, then everything (DD4). Rolling back means pointing at the old version |
| A policy version holds rules per region and per surface: the feed is stricter than a private message. The same item can be allowed in one region and blocked in another. Media and its reviewers stay inside their region |
| Reviewers see the worst content all day | Tokens limit the time on one category, with fixed breaks. Links to media work only inside the tool and only for that session. Every look at an item is logged |
| 500 million decision rows a day | Split the tables by item_id: every write touches one item, so one machine. Move old versions to cheap storage |
| One category's queue grows without end | Give each set a size limit. What does not fit waits in an overflow set that is worked when there is room |