Skip to content

How to design a distributed denylist

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Practice this question

The problem

A distributed denylist is the list of blocked users, IP addresses and email addresses that services consult before they handle a request. The check runs on the request path in each region, so it has to be answered from the serving node's own memory, while a new block still has to reach each node within seconds. The answer turns on two things: a compact copy on the node (a Bloom filter ahead of an exact structure, with address ranges kept as prefixes rather than as addresses) and a change feed with version numbers that keeps those copies current and lets a node tell how far behind it is.

Clarifying questions

AskWhy it mattersA typical answer

What exactly gets checked: a user id, an IP address, an email, or all three? And are address ranges and IPv6 in scope?

User ids and emails are exact values, but addresses come as ranges, and IPv6 ranges can't be expanded into single addresses. That decides whether you need a prefix structure next to the set.

All three, on each request. Address entries can be ranges, and both IPv4 and IPv6 must work.

How large is the list, and how hot is the check?

The list size sets the memory each node needs, and the check rate tells you whether a remote lookup is even thinkable.

Millions of blocked users, emails and IP addresses. No request rate is given, so treat the check as at least as hot as the busiest service that calls it. A single bit for each IPv4 address would take 512 MB, which is a useful bound to carry around.

How fast must a new block take effect everywhere?

Seconds and minutes lead to different designs: pushing changes against polling for them, and whether a stale node is a problem worth engineering around.

Near real time, in each region. A node that sits on an old copy for long is a failure you're expected to handle.

Where do entries come from?

Hand-entered blocks and bulk imports from outside feeds have different shapes: one is a trickle of single writes, the other a periodic batch that may add and remove many entries at once.

Both: an admin API, and lists fetched from external APIs on a schedule.

Do some rules apply in one region only?

A region-scoped rule changes the data model (an entry carries a region) and the distribution (a node holds the rules meant for its own region).

Yes. A rule can say which region it applies to, and government-mandated blocks must take effect where they apply.

When a node can't be sure its copy is current, should it keep serving?

Blocking with an old list lets a newly blocked actor through; refusing to serve blocks everyone. The requirement for high availability points one way, but the interviewer may want you to say it.

Keep serving from the last good copy and raise an alarm on the lag. Say what a government-mandated block in that region would do differently.

Can a block be temporary?

A block that ends on its own needs an expiry time on the entry, not just when it was added, and a way to drop it from each node without an explicit removal.

Not required for the first version, but worth a sentence: the entry model can carry an optional expiry.

The requirements menu

RequirementScopeWhy

Check whether a user, IP address or email is blocked, on every request

Core

The product. It fixes the shape of the design: a check this hot has to be answered on the machine that receives the request.

Add and remove entries, including lists fetched from external APIs

Core

Changes have a different shape from checks: a check is a local lookup, while an addition or removal has to reach each node. A feed import can add and drop many entries in one batch, and removal on the node deserves care, since a plain Bloom filter has no delete.

Apply a rule in one region only when it says so

Core

An entry carries a region, and distribution has to respect it: a Tokyo node keeps global rules and Japan's rules, and doesn't carry another country's.

Handle both IPv4 and IPv6 addresses

Core

IPv6 forces ranges to be stored as prefixes. A bit for each IPv4 address is 512 MB already, and the IPv6 space can't be enumerated at all.

Temporary blocks that end at a set time

Optional

Take it if there's time: it costs one expires_at column on the entry and a sweep on each node, and it's how abusive addresses get unblocked without someone remembering to do it. Leave it if the interviewer wants the propagation story first.

Normalize emails and addresses before storing and before checking

Optional

Worth naming: whether a block on Jane@Example.com should catch jane@example.com is a decision to make on purpose. The domain can be lowercased safely; lowercasing the local part is a policy you choose, since the standard treats it as case-sensitive while many providers don't. Whatever you choose, the same function must run on the entry and on the value being checked.

An allowlist that overrides a block

Optional

Useful when a shared address (an office, a carrier) lands in a feed. It's a second small list checked after a hit, and it reuses the same distribution path, so mention it and move on.

An audit trail of who added or removed each entry and why

Optional

Cheap to add because the change log already records each addition and removal with a version. Say it's the same log with an actor and a reason attached, and leave the UI out.

Separate lists per tenant or per product

Out of scope

It turns one list into many and multiplies the memory on each node. Name it as a later extension (a list id on each entry) and keep one list for the round.

Deciding who to block and the review tooling

Out of scope

That's the abuse team's product. This system stores and serves decisions; it doesn't make them.

Rate limiting

Out of scope

A different mechanism with its own counters and windows. Its output can become an entry here, which is the one sentence worth saying.

Appeals from blocked users

Out of scope

A workflow with people in it. The removal path you design is what an appeal would eventually call.

Non-functional requirements

RequirementWhat it forces

Low latency: the check sits on every request path

The check has to finish without leaving the serving node: a lookup in local memory, no call to a database or a shared cache. That in turn means each node holds the whole list, which drives the memory estimates.

Highly available

No single component may sit between a request and its answer. A node keeps serving from the copy it has when the store, the log or the publisher is down, and the decision about what to do with an old copy has to be made on purpose.

Updates reach every node around the world in near real time

Changes are pushed, not polled on a slow timer, and each change carries a version so a node can tell what it has missed and ask for the rest. It also rules out a full download of the list as the normal way to refresh.

Government-mandated blocks take effect where they apply

An entry can name a region, and nodes in that region apply it while other regions don't. Distribution has to deliver region-tagged entries to the right nodes, and a stale node in that region is a compliance problem, not just a security one.

Estimates

QuantityWorkingResultWhat it sizes

A bit for each IPv4 address, and why the same trick fails for IPv6

2^32 IPv4 addresses × 1 bit = 2^29 bytes = 512 MB. IPv6 addresses are 128 bits wide, so there are 2^128 of them, about 3.4 × 10^38; a bit for each is out of the question.

512 MB for IPv4; an IPv6 bitmap would be 2^128 bits, far beyond anything a node could store

Why the list is stored as entries and prefixes, not as a bit per address, and why IPv6 ranges have to be prefixes.

Memory for an exact set of the whole list on one node

Assume 10 million entries (the brief says millions) at about 100 bytes each: an IPv6 address is 16 bytes, an email is tens of bytes, and a hash table adds pointers and slack. 10 million × 100 bytes = 1 GB.

About 1 GB per serving node

The memory an exact copy costs on each node, which is what the Bloom filter in front is compared against.

Bloom filter for the same entries

About 9.6 bits per element gives a 1% false-positive rate; each tenfold reduction costs about 4.8 bits more, so 0.1% needs about 14.4 bits. 10 million × 9.6 bits ≈ 12 MB; 10 million × 14.4 bits ≈ 18 MB.

12 MB at 1%, 18 MB at 0.1%: between a fiftieth and a hundredth of the exact set

The filter size, chosen from the error rate you're willing to pay for in extra exact lookups.

Extra exact lookups caused by false positives

At a 1% rate, 1 request in 100 that isn't blocked still goes on to the exact structure; at 0.1%, 1 in 1,000. Requests that are blocked go there regardless; the brief gives no share for them, so state your own assumption about it.

One unblocked request in 100, or one in 1,000, pays for the second lookup

The load on the exact structure, which is what lets it live in slower, larger memory while the filter stays in cache.

Bandwidth if each node downloads the full list on a timer

Assume 1,000 serving nodes each refreshing a 1 GB copy once per 5 minutes: 1,000 × 1 GB ÷ 300 seconds ≈ 3.3 GB/s leaving the central store, all the time.

About 3.3 GB/s of steady egress, plus a staleness window as long as the timer

Why a full refresh can't be the normal update path once the fleet is large; it stays useful as the way to bootstrap a node.

Replaying an hour of missed changes against loading a snapshot

Assume 10 changes a second: 36,000 changes in an hour, at about 100 bytes each ≈ 3.6 MB. The snapshot of the whole list is about 1 GB.

An hour's backlog is about 3.6 MB; replaying it is far cheaper than a 1 GB snapshot

When a node that fell behind should replay the log and when it should reload a snapshot: replay until the backlog approaches the size of the list, or the log no longer holds its version.

Addresses covered by one IPv6 /64 prefix entry

A /64 leaves 64 bits for hosts: 2^64 ≈ 1.8 × 10^19 addresses, held as one prefix entry.

One entry instead of about 1.8 × 10^19

Why address ranges have to be stored as prefixes with a longest-prefix lookup, not expanded into the set.

A counting Bloom filter for the same entries

Replace each bit with a counter. With 4-bit counters (an assumption; the counter has to be wide enough not to overflow), the 12 MB filter becomes about 48 MB.

About 48 MB, roughly four times the plain filter

What deletion inside the filter costs in memory, against rebuilding a plain filter on a schedule.

Core entities

EntityWhat it holds

Denylist entry

One blocked thing: a user id, an email, a single address or an address range, with where it applies and when it stops applying.

List version

One step in the change log: what was added and what was removed when the list moved to this version.

Source feed

An external list the importer pulls on a schedule and turns into entries.

Node copy

What a serving node knows about its own copy; kept in the node's memory and reported for monitoring.

The API

EndpointNotes

check(entity, region) → blocked or allowed, a call against the copy on the serving node

A library call inside the serving process, not an HTTP request: it normalizes the value, tests the Bloom filter, and consults the exact structure on a possible hit. The region is the node's own, so region-tagged rules for elsewhere are not even present on the node.

POST /entries { type, value, region? }

Normalizes the value (lowercase domain, the chosen policy for the local part, network bits plus prefix length for an address), writes the row, and appends a new list version with the entry in added. Returns the entry id. An optional expires_at fits here if temporary blocks are in scope.

DELETE /entries/{id}

Marks the row removed with a new version rather than deleting it, so the change log can replay the removal to nodes. The response can say which version carries the removal, which support staff can compare with node lag.

GET /changes?since={version} → entries added and removed since that version

What a node calls when it reconnects or sees a gap. Returns changes in version order up to the current version. If since is older than the log keeps, it answers with a pointer to the latest snapshot and the version that snapshot was taken at, so the node reloads and then replays from there.

The high-level design

copyAdmin APIEntries storeServing nodeRequestExact set

Step 1 of 4

The list lives on the node

Start with where the check runs. An admin API writes entries to a store, and each serving node loads a copy of the list into an exact set in its own memory. A request is checked against that set before anything else happens, with no network call, which is the whole point of the copy. For the list in the brief, a copy costs about 1 GB per node, which is affordable but not free, and the copy is refreshed by downloading the list again on a timer, which the later steps replace.

versionperiodicpushbootstrapcatchupAdmin APIEntries storeFeed importerChange logSnapshotsPublisherRegion relayServing nodeRequestBloom filterExact set
The whole design

What breaks first

The deep dives

The check on the request path. A request arrives at a server in Tokyo. How does that server decide, from its own memory and without adding noticeable time, whether the request's user, address or email is on the list, and what does the list cost in memory with IPv6 ranges included?

A concept that helps here: Bloom filtersA concept that helps here: Tries and prefix search

Spreading updates. An abusive IP address is added through the admin API. How does that one entry reach the copy on a serving node in another region, how does a node know it has missed something, and what does a node do after an hour offline?

A concept that helps here: Dynamic configurationA concept that helps here: Failing open or failing closed

Removing entries. An address was blocked by mistake and an admin deletes it. Structure by structure, how does it leave each node's copy, what does the person at that address see while nodes disagree, and what does your removal path cost compared with the alternative?

A concept that helps here: Bloom filtersA concept that helps here: Consistency modelsA concept that helps here: Cache invalidation and TTLs

Concepts this guide uses

Sources

  1. Wikipedia: Bloom filter
  2. Wikipedia: Email address
  3. Wikipedia: IPv6 address
  4. Cloudflare blog: Introducing Quicksilver: Configuration Distribution at Internet Scale
  5. Cloudflare blog: Quicksilver v2: evolution of a globally distributed key-value store (Part 1)
  6. etcd documentation: etcd3 API (Watch API, revisions and compaction)
  7. Educative: What is the longest prefix matching in routing?
  8. JumpCloud IT index: What is Longest Prefix Match (LPM)?
  9. ShowOffer: Design a Global IP Address Blocking System (Google system design practice question)
Sign in to report a mistake