← Building blocks

Catch spam and abuse

Security & abusesenior

Malicious links, squatting on short aliases, fake accounts.

Say it like this

Abuse looks like normal usage one request at a time, so I score content and accounts asynchronously with rules and models, quarantine the risky minority before it is public, and keep a fast block list at the edge for what is already known bad.

Basic solution

Score content and accounts asynchronously with rules and models, quarantine before publish when risk is high, and block lists at the edge.

Safe Browsing APIreputation scoresCAPTCHAallow / deny lists

Accept fast, score async, block at the edge

Creates pass cheap in-memory checks and are accepted; a scoring pipeline decides allow, hold or block off the request path; confirmed abuse feeds the edge block list and the model.

How it works

  1. Every create (a new link, an upload, a sign-up) is accepted quickly and then emitted as an event carrying the content, the actor, and context signals: account age, IP reputation, how fast this actor has been creating things, and a device fingerprint.
  2. A scoring pipeline consumes the event in stages. Cheap rules run first (deny lists, known-bad domains, alias patterns, rate anomalies), then external checks such as malware and phishing lists, and finally models trained on past abuse. Each stage adds to a risk score.
  3. The score maps to an action: allow, allow but monitor, hold for review, or block. High-risk items are quarantined before they become public; low-risk items are published immediately and re-checked later.
  4. Confirmed abuse feeds back into the system. The domain, content hash or account is added to the edge block list, so the next attempt is refused in microseconds without reaching the pipeline, and the confirmed example is added to the training data.
  5. Users get an appeal path. Reviewers see which signals fired and why, and each reviewer decision is stored as a labelled example that improves the model.

Why asynchronous

  • Scoring takes tens to hundreds of milliseconds and calls external services, so it must not sit on the create path where it would slow every request. Accept first, score next, then act.

Worked example

URL shortener

  • 40 creates/s, 3.5M/day. Historical abuse rate ~0.5%: 17,000 bad links a day, mostly phishing and malware, plus alias squatting on brand names.
  • Synchronous checks on create (under 2 ms): alias not on the reserved list (brand names, common words, profanity), destination host not on the local deny list (an in-memory Bloom filter of 2M domains, 4 MB, 0.1% false positives which fall through to an exact check).
  • Asynchronous scoring: the create event goes to a stream; a consumer calls Safe Browsing for unknown destinations (p50 80 ms) and runs a small model on account age, creation velocity and destination features. Throughput needed: 40/s average, 400/s at peak, 10 consumers.
  • Actions: a new account creating 200 links/hour to a domain registered yesterday is held; the link resolves to an interstitial warning until reviewed. Expected hold rate 1%, so about 35,000 holds/day, of which reviewers see the 10% the model is least sure about; the rest auto-resolve on a second check after an hour.
  • Feedback: confirmed-bad domains are pushed to the edge list within a minute; redirects for already-created links to that domain are cut off by the same list because the redirect service checks it too.
  • Precision target: at 0.5% abuse, a 1% false-positive rate on good links would wrongly hold 35,000 good links a day against 17,000 bad ones. The interstitial-instead-of-block design is what makes that tolerable.

Video platform (copyright)

  • Fingerprint each upload (perceptual hash per segment) and match against a reference index of claimed content; a match above threshold blocks publishing or routes revenue, depending on the rights holder's policy.

Variants and when each wins

Rules and lists

  • Deterministic checks against known patterns and repeat offenders. They win on explainability and speed; they miss anything new and need constant maintenance.

Reputation scores

  • Each actor, domain, IP and device accumulates a score from its history. It wins because it is cheap to check and hard to game at scale; it is slow to trust newcomers.

Machine-learned classifiers

  • Models trained on labelled abuse catch novel patterns. They win on recall for things rules never saw; they need a labelling pipeline, offline evaluation, and monitoring for drift as abusers adapt.

Friction (CAPTCHA, verification, limits for new accounts)

  • Raises the cost of abuse rather than detecting it. It wins against bulk automation cheaply; applied too broadly it annoys real users.

Recommendation: layer all four: rules and lists synchronously, reputation and models asynchronously, friction applied only when the score is uncertain.

Failure modes

Blocking good users

  • Legitimate links are held and real accounts are suspended. It happens because thresholds were tuned for recall only, catching more abuse at the cost of more false positives. Measure precision on a labelled sample every week, prefer soft actions (an interstitial warning, a review) over hard blocks, and keep an appeal path with a response-time target.

Scoring on the request path

  • Create latency spikes whenever an external reputation service slows down. It happens because the create handler calls that service synchronously. Accept the create, then score asynchronously; only in-memory checks run inside the request.

Attackers adapt faster than lists update

  • A blocked domain reappears under new names within minutes. It happens because the defence is a static deny list of names. Score features that are expensive to change, such as domain age, registrar and hosting, and share signals across the graph of accounts, IPs and devices.

No feedback loop

  • The model never improves, and reviewers make the same decisions again and again. It happens because reviewer decisions are not stored as labels. Record every reviewer action as a labelled example, retrain on a schedule, and track precision and recall per rule.

Quarantine leaks

  • A held link still redirects. It happens because the hold flag is checked at creation but not at redirect time. Make every serving path check the item's status and the live block list before serving it.

Interviewer follow-ups

Answer out loud before you open each one.

How do you stop users squatting on short brand aliases?

A reserved list of brand names, trademarks and common words that only verified owners can claim, checked synchronously at create. Add a minimum alias length for custom aliases, and release unused reserved names through a claim process rather than first-come-first-served.

Why quarantine instead of block, and what does the user see?

False positives are inevitable, and a wrongly blocked user is worse than a briefly delayed one. A quarantined link serves an interstitial warning or a pending state until review or a re-check clears it. Blocking is reserved for confirmed matches against known-bad lists.

How does copyright fingerprinting work at upload time?

Each uploaded video is split into segments and a perceptual hash is computed per segment, robust to re-encoding and cropping. Hashes are matched against an index of reference content supplied by rights holders. A match above a threshold applies the policy the rights holder chose: block, track, or monetise. It runs as a side task of the transcoding pipeline.

What metrics tell you the abuse system is working?

Precision and recall on a labelled sample, time from first abusive item to block, appeal rate and appeal overturn rate, and the share of items needing human review. A falling overturn rate with stable recall means the automated decisions are getting better; a rising review share means the model is losing confidence.

Connections

Built on
Bloom filter · Count-Min sketch
Pairs with
Limit requests per client · Validate at the edge · Move slow work off the request · Keep events as a replayable log · Process uploads in parallel · Count big things with small memory
Used in
URL Shortener (TinyURL / bit.ly) · Video Streaming Platform (YouTube / Netflix)

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon EC2 Auto ScalingCreate API, Scoring workersCompute Engine managed instance groupsVirtual Machine Scale SetsKubernetes Deployment with a HorizontalPodAutoscaler, Nomad
Amazon Kinesis Data StreamsCreate eventsPub/SubEvent HubsApache Kafka, Redpanda, Apache Pulsar
Amazon SQSReview queuePub/Sub, Cloud TasksService Bus queues, Queue StorageRabbitMQ, ActiveMQ
Amazon DynamoDBLink statusFirestore, BigtableCosmos DBScyllaDB, Apache Cassandra
Amazon ElastiCacheEdge block listMemorystoreAzure Managed RedisRedis, Valkey, Memcached