Distributed Denylist for Request Blocking
A regional updater downloads a truncated snapshot.
Topic tools
Layout updated
Problem statement
Design a system that distributes IP blocking rules to request gateways. Gateways should block matching requests quickly and pick up changes to the rules safely.
Functional requirements
- Import and update IP-address and domain blocking rules.
- Allow or block requests using the installed rules.
- Show each region's rule version and update age.
Non-functional requirements
- Check requests locally in under 1 ms.
- Propagate new rules within about 60 s in healthy conditions.
Back-of-the-envelope estimates
| Illustrative estimate |
|---|
| 1M rules × illustrative 64 bytes ≈ 64 MB raw |
Entities
| Entity / logical owner |
|---|
| Rule(sourceId, ruleId, , action, sourceGeneration) |
| (version, checksum, sourceCutoffs, artifactURI) |
| ActiveVersion(region, version, activatedAt) |
API design
| Operation / input | Response and retry contract |
|---|---|
PUT/sources/{id}/generation {generation, rules, signature} | Reject malformed or regressing generations; stage a complete source replacement. |
GET/snapshots/latest | Signed with checksum and artifact version; notifications only accelerate discovery. |
CHECK {clientIP} | Local allow/deny with matched policy/version; address provenance must be trusted. |
High-level design
How to draw this design
- Collect source rulesTrusted feeds, fetcher, and normalizer
- Build and publishCanonical PostgreSQL, builder, and S3
- Distribute versionsKafka notifications and regional updaters
- Enforce at the edgeGateway and in-memory matcher
Validate the rules, publish a complete , and atomically activate it at each gateway.
- State ownership
- PostgreSQL owns canonical rules. Gateways enforce a validated version.
- Scale
- Compile once and keep request-time matching local.
- Correctness
- Verify the complete before swapping the active version.
- Failure and recovery
- A missed notification triggers polling. An invalid leaves the last valid version active.
- Compute
- State
- Messaging
- Edge
━━ Synchronous┄┄ Asynchronous···· Recovery / control▧ Fault
Each arrow is one interaction. Request, background and recovery branches are not one linear transaction.
Read the 11 flow steps
High-level design component walkthrough
Gov / Trusted Sources
Publish IP / deny rules
Why, tradeoff and connected operations
Treat another system as a separate failure and retry domain with a documented contract.
Tradeoff: Inputs can be malformed/outdated
Connected operations: Pass validated input
Fetcher / Normalizer
Fetch, validate, normalize source entries
Why, tradeoff and connected operations
Isolate this operation so it can scale and fail independently from storage.
Tradeoff: Source outages or format drift
Connected operations: Pass validated input; ingest generation
PostgreSQL / Canonical Rules DB
Source-specific rules + generations
Why, tradeoff and connected operations
PostgreSQL holds canonical rules and version generations. Transactions preserve a consistent rule set while administrators publish changes. is useful for controlled rule edits; the request path uses a derived in-memory matcher instead.
Tradeoff: Generation storage / validation work
Connected operations: ingest generation; latest rules
Snapshot Builder
Compile rules / test full version
Why, tradeoff and connected operations
Isolate this operation so it can scale and fail independently from storage.
Tradeoff: Build time delays urgent changes
Connected operations: latest rules; artifact then ; version ready
S3 Immutable Snapshots
Versioned artifacts + verified
Why, tradeoff and connected operations
Object storage distributes immutable rule snapshots with a checksum and version. Regions can download, verify and retain older snapshots for rollback. Snapshots are bulk artifacts, not a database or a replacement for the canonical rules.
Tradeoff: Download and storage replication cost
Connected operations: artifact then ; download
Kafka / Version Notifications
Tell regions of new
Why, tradeoff and connected operations
Kafka retained partitioned stream. Key events by the domain ordering key; replay and independent consumers motivate this choice. rows remain in the source database; a relay publishes after commit. Buffer independent producers and consumers, with bounded and replay semantics.
Tradeoff: Missed notifications must reconcile
Connected operations: version ready; signal
Regional Updaters
Download, validate, stage next version
Why, tradeoff and connected operations
Make ownership/version changes explicit; downstream resources must reject stale owners.
Tradeoff: Rollout skew across regions
Connected operations: download; signal; ref swap
Redis / In-memory Rule Matcher
v41 → v42 swap; lookup
Why, tradeoff and connected operations
An in-memory matcher makes request checks fast. Loading a validated generation and switching it atomically avoids mixing old and new rules. This derived serving structure avoids a lookup per request; it is not the rule-editing authority.
Tradeoff: Memory footprint; delayed version switch
Connected operations: ref swap; allow / reject; check
Edge / Gateway
Check IP and allow or block
Why, tradeoff and connected operations
Centralize admission and routing while keeping business-state ownership downstream.
Tradeoff: Adds per-request lookup latency
Connected operations: allow / reject; check; Pass validated input
Incoming Requests
High-rate traffic checks
Why, tradeoff and connected operations
Isolate this operation so it can scale and fail independently from storage.
Tradeoff: Burst traffic pressures edge capacity
Connected operations: Pass validated input
Engineering control room
Deep dives — decisions, failures and recovery
Open a deep dive to follow the steps, try an example and see how recovery works.
Tradeoffs and alternatives
| Decision | Tradeoff / alternative and recovery implication |
|---|---|
| Replace the rule set in one step | Keeping the old and new versions briefly uses extra memory, but makes switching and rollback straightforward. |
| Catch gateways that missed an update | Polling adds background requests. Spread the checks over time and alert when a gateway's rules are older than the allowed limit. |
| Keep checking requests when publishing is down | Old rules can block something that is now allowed or miss a new threat. Show rule age and define when to keep serving, reject checks or apply an approved override. |
| What happens if a region fails? | A new rule may take about a minute to reach every region. That delay lets gateways keep checking requests without waiting on a network call. Requiring every region to switch at once would add coordination and could stop checks during a network outage. |
Production scars & failure modes
A regional updater downloads a truncated snapshot.
Look for: Check checksum, record count, generation and freshness age.
Recovery and invariant: Retain the last verified edition, reject incomplete activation and alert on freshness. Define fail-open or fail-closed behavior when the last good edition becomes too old.
| Component / failure | Impact | Recovery mechanism | Alternative / tradeoff |
|---|---|---|---|
| Source format/signature invalid | A new cannot be trusted. | Quarantine the generation, retain last-known-good state and alert the owner. | Availability continues with stale policy rather than silently deleting valid rules. |
| Object download corrupt | A region receives unusable compiled state. | Verify checksum/schema before staging and retry an alternate replica. | Never swap the active pointer before validation. |
| Bad rule blocks a large range | A logically valid deployment can still cause an outage. | Canary regions, compare match-rate deltas and roll back the generation with audit. | Urgent policy changes still need proportional rollout safeguards. |
| Updater/controller unavailable | Matchers continue with existing local data. | Reconcile after recovery and alert on maximum allowed policy age. | At that bound choose the documented risk-specific fail mode. |
90-second interview summary
I would design the distributed blocking system by separating policy management from high-throughput request enforcement.
On the , fetcher services ingest government and security feeds, normalize and validate the rules, and store them in a canonical generation. A Builder compiles these into efficient prefix-based structures for , , and domain matching.
The system validates the and publishes it immutably to object storage, then announces a versioned . Regional updaters retrieve the new , verify its integrity, and atomically switch the local active matcher.
Every gateway evaluates requests using a complete in-memory , avoiding network dependencies in the critical request path.
Because we allow approximately one minute of propagation delay, regions can temporarily serve different validated versions. Notifications provide fast propagation, while periodic polling handles missed updates.
For resilience, I would retain old snapshots for rollback, validate unexpected rule-count changes, use to prevent stale publishers, and continue serving the last known good during control-plane outages.
The central tradeoff is accepting bounded rule staleness in exchange for low-latency, highly available enforcement.
Explain it without looking
Explain replace the rule set in one step
Reveal answer
Build and verify the next rule set before switching the gateway to it.
Changing the live matcher piece by piece can let a request see only half of an update.
Keeping the old and new versions briefly uses extra memory, but makes switching and rollback straightforward.
Explain catch gateways that missed an update
Reveal answer
Use notifications for speed and periodic checks to repair missed announcements.
One lost notification should not leave a gateway using old rules forever.
Polling adds background requests. Spread the checks over time and alert when a gateway's rules are older than the allowed limit.
Explain keep checking requests when publishing is down
Reveal answer
Keep the last verified rules and decide how long they may be used.
An unavailable source does not mean the correct rule set is empty.
Old rules can block something that is now allowed or miss a new threat. Show rule age and define when to keep serving, reject checks or apply an approved override.
Explain what happens if a region fails?
Reveal answer
Let each region keep checking requests using a complete, verified rule set.
Each gateway already has the full rule set in memory. It can keep checking requests even when the services that publish new rules are down. We can also see exactly which version each region is using.
A new rule may take about a minute to reach every region. That delay lets gateways keep checking requests without waiting on a network call. Requiring every region to switch at once would add coordination and could stop checks during a network outage.
Revision checklist
Revision checklist
- Reconstruct replace the rule set in one step: Build and verify the next rule set before switching the gateway to it.
- Reconstruct catch gateways that missed an update: Use notifications for speed and periodic checks to repair missed announcements.
- Reconstruct keep checking requests when publishing is down: Keep the last verified rules and decide how long they may be used.
- Reconstruct what happens if a region fails?: Let each region keep checking requests using a complete, verified rule set.
- Name the authoritative state, boundary, retry identity and failure-domain durability guarantee.
- Explain one alternative and exactly which guarantee you would relax.
- Redraw the request and recovery paths without looking; mark what required a hint.
60-minute interview outline
60-minute interview walkthrough
| Time | Focus | What to cover |
|---|---|---|
| 0–5 min | Introductions | Introduce yourself briefly and confirm the interview format. |
| 5–15 min | Scope and scale | Define which IP or domain rules are in scope. Agree on acceptable propagation delay and stale-rule behavior. |
| 15–30 min | High-level design | Draw the rule intake, canonical store, builder, object storage, regional updaters, and gateway matcher. |
| 30–45 min | Deep dives | Explain validation and activation. Compare local matching with a remote lookup for each request. |
| 45–55 min | Failure and recovery | Walk through a missed update or malformed . Poll for the , keep the last valid version, and explain rollback. |
| 55–60 min | Wrap-up | Summarize the design and its main tradeoff. Leave time for questions. |
On this page
- Problem statement
- Functional requirements
- Non-functional requirements
- Back-of-the-envelope estimates
- Entities
- API design
- High-level design
- High-level design component walkthrough
- Engineering control room
- Deep dives — decisions, failures and recovery
- Tradeoffs and alternatives
- Production scars & failure modes
- 90-second interview summary
- Explain it without looking
- Revision checklist
- 60-minute interview walkthrough