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
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Estimates
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- The check on the request path
- Spreading updates
- Removing entries
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
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
| Ask | Why it matters | A 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. |
Non-functional requirements
| Requirement | What 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
| Quantity | Working | Result | What 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 | A | 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
| Entity | What 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
| Endpoint | Notes |
|---|---|
| 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. |
| 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 |
| 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. |
| What a node calls when it reconnects or sees a gap. Returns changes in version order up to the current version. If |
The high-level design
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.
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: Longest-prefix match for address ranges
A concept that helps here: Tries and prefix searchSpreading 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: Snapshots and log compaction
A concept that helps here: Failing open or failing closedRemoving 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?
Concepts this guide uses
- Bloom filters
- Longest-prefix match for address ranges
- Tries and prefix search
- Dynamic configuration
- Snapshots and log compaction
- Failing open or failing closed
- Consistency models
- Cache invalidation and TTLs
Sources
- Wikipedia: Bloom filter
- Wikipedia: Email address
- Wikipedia: IPv6 address
- Cloudflare blog: Introducing Quicksilver: Configuration Distribution at Internet Scale
- Cloudflare blog: Quicksilver v2: evolution of a globally distributed key-value store (Part 1)
- etcd documentation: etcd3 API (Watch API, revisions and compaction)
- Educative: What is the longest prefix matching in routing?
- JumpCloud IT index: What is Longest Prefix Match (LPM)?
- ShowOffer: Design a Global IP Address Blocking System (Google system design practice question)