Global Edge Abuse-IP Filtering with Fast Rollback
System DesignModel answerLast updated
Design a worldwide edge service that scores client IPs per request, shares abuse signals between regions within seconds, and can undo bad blocklist changes in under ten seconds.
Problem
You operate a large internet-facing platform with edge locations spread around the world. Attackers running credential stuffing, scraping, and DDoS campaigns cycle through source IPs quickly. Design a service that inspects every inbound HTTP/HTTPS request at the edge, decides whether the source IP is abusive, and learns from abuse observed in any region.
What the system must do
- Per-request decision: At the edge gateway, look up the client's IP reputation and return one of
ALLOW,CHALLENGE(for example a CAPTCHA), orBLOCK. - Cross-region learning: Behavioral signals (repeated 401 responses, odd request patterns) seen in one region should lead to updated verdicts in all other regions within a few seconds.
- Safe corrections: Operators must be able to apply manual overrides, allowlist by CIDR or ASN, and roll back a bad rule or list update everywhere within 10 seconds.
- Audit trail: Every block decision and every administrative change must be recorded in a tamper-evident log that supports post-incident review.
Non-functional targets
- Latency added by the check: at most 2 ms at p95 and 5 ms at p99.
- Partition tolerance: If regions cannot talk to each other, each edge keeps enforcing from local state with no loss of service.
- Collateral damage: Legitimate users who share an address through NAT or carrier-grade NAT must not be swept up in broad blocks.
Scale assumptions
- 1,000,000 requests per second in total, across 6 regions.
- 20 million malicious IPv4 addresses and 2 million malicious IPv6
/64prefixes active at any time. - About 5,000 reputation changes per second worldwide (adds, updates, expirations).
What to cover in your answer
- Architecture: the path of a request, how the edge makes its decision, and how regional signals flow into global aggregation.
- Edge data structures: how millions of IPs and CIDR ranges are held in memory and queried in well under a millisecond.
- Cross-region replication: the topology and consistency model that propagates updates without synchronous cross-region waits.
- Rollback and safety: the emergency override path, plus protections such as staged rollouts and blast-radius limits.
Hints
Hint 1
Do the arithmetic first: 22 million entries at roughly 16 bytes each, and an update stream of only a few hundred KB/s. What does that imply about where lookups can happen and whether any network call belongs on the request path?
Hint 2
Not all state needs the same consistency. Reputation verdicts can merge conflict-free (precedence plus expiry), while overrides, rollbacks, and policy versions are rare and may justify consensus. Consider giving them separate channels.
Hint 3
Think about what could go wrong with your own system: a buggy detector blocking a whole ISP, or shared NAT addresses. How would you cap impact before publishing, ramp up gradually, and revert automatically?
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Sizing and the key insight
| Item | Estimate |
|---|---|
| Traffic | 1M QPS over 6 regions, about 170K QPS per region average; design for ~3x peak (~500K per region) |
| IPv4 table | 20M entries x ~16 B (action, score, expiry, rule id, version) is about 320 MB, under 1 GB with hash overhead |
| IPv6 /64 table | 2M x ~16 B is about 32 MB |
| Update stream | 5K/s x ~64 B is about 320 KB/s globally |
| Latency budget | 2 ms p95 rules out any network hop on the request path |
The whole dataset fits in RAM on every edge host and the update rate is tiny. So replicate everything everywhere and evaluate in-process, with no RPC per request.
Questions worth asking up front: is the verdict per request or per connection, do we control L4, which ASNs or customers are protected, and what is the default TTL for a block?
2. Interfaces
- Data plane (in-process):
evaluate(ip, asn, fingerprint, path) -> {verdict, rule_id, list_version}. - Control plane (authenticated, audited): create rule (scope ip/cidr/asn, action, ttl, reason, ticket), create allow override, rollback by rule, batch, or pinned version, and query audit history.
3. Architecture
Request path
- Anycast routes the client to the nearest PoP.
- An L4 layer (XDP/eBPF) drops traffic from the hard-block set at line rate, absorbing volumetric floods before TLS.
- The L7 proxy (for example Envoy) runs a reputation module that reads a lock-free, memory-mapped snapshot. A lookup costs a few microseconds.
- The verdict is forwarded to the origin as a header for downstream risk logic.
Signal path (asynchronous)
- Edges and origins publish events (401s, rates, verdicts) to a regional Kafka.
- A regional stream job (Flink) keeps sliding windows keyed by IP, /24, IPv6 /64 and /48, ASN, and username.
- When a threshold or model fires, it emits verdict deltas to local edges directly (sub-second) and to a regional verdict topic.
Global aggregation
- Regional verdict topics are mirrored to every other region (multi-master).
- A global scorer combines weak evidence, such as an IP that is mildly suspicious in four regions, into a confirmed block, and publishes the result as another delta stream.
4. Edge data structures
Consulted in strict precedence, so overrides always win:
- Allow/override set: a small longest-prefix-match trie for CIDRs plus an ASN bitmap.
- Exact-match tables: an open-addressing hash keyed by
uint32for IPv4, and by the/64prefix (uint64) for IPv6. Entries are packed to 16 bytes. A lookup is one or two cache misses, around 100 ns. - Prefix block table: a compressed radix trie (ART, Poptrie, or DIR-24-8 for IPv4). A separate LPM trie maps IP to ASN.
Updates: a sidecar applies deltas to a writer copy and swaps a pointer atomically (RCU-style), or uses per-entry atomic writes, so readers never lock. Full compressed snapshots (around 1 GB) are published every few minutes for cold start and resync. Deltas carry monotonic offsets so gaps are detectable.
NAT and CGNAT: mark an IP as shared when many distinct cookies or device fingerprints appear (HyperLogLog per IP) and seed with known CGNAT space such as 100.64.0.0/10. Automated rules on shared IPs may only issue CHALLENGE, and rate limits key on (IP, device/session). A CAPTCHA costs a real user seconds; a block costs a customer.
5. Cross-region replication
- Verdicts need no consensus. Each entry is
(key, action, score, expiry, origin_region, hlc_timestamp). Merge by highest-precedence unexpired action, with hybrid logical clocks as tiebreaker. TTL-based expiry avoids tombstone coordination. This is conflict-free and eventually consistent, and no region waits on another. - Control state uses consensus. Overrides, rollbacks, and policy versions live in a small Raft-backed store replicated globally. These writes are rare and human-driven, so 100-300 ms is fine.
- Separate channels. Control messages use a dedicated high-priority topic, and edges also poll the control store every 1-2 s, so a rollback never queues behind bulk deltas.
- Partition behavior. Each region continues with its last state plus its own detections. Only global correlation of weak signals degrades.
6. Rollback and safety
Versioning and rollback. Every delta has a rule_id and batch_id. Edges retain recent snapshots and a per-rule delta index. Rollback publishes "disable rule/batch" or "pin list version V", which edges apply as a mask or pointer swap in under a second. End to end it takes roughly 2-5 s, within the 10 s target. A global kill switch demotes all automated rules to CHALLENGE or shadow mode.
Blast-radius validator (before publish). Using a 15-minute per-prefix and per-ASN traffic sketch, reject and page if an update would:
- affect more than 0.1% of global traffic or 1% of any region;
- touch a protected ASN or customer list;
- be an automated rule broader than /24 (IPv4) or /48 (IPv6) without human approval.
Also rate-limit new blocks per detector per minute so one faulty detector cannot flood the list.
Staged rollout. Shadow mode first (log only), then CHALLENGE on about 1% of edges, then one region, then global BLOCK.
Automatic guards. Watch login success, 2xx ratio, and CAPTCHA solve rate per ASN, and auto-revert the latest batch on regression. A high CAPTCHA solve rate is a strong false-positive signal.
Audit. Write block decisions (sampled or aggregated for volume, full detail for admin actions) and all rule changes to an append-only log with hash chaining, periodically anchoring the head hash in separate write-once storage. Record who, what, why, ticket, and list version.
7. Trade-offs and common mistakes
- Central lookup service per request: adds network latency and a single failure point. Local replication is better at this data size.
- Strong consistency for all updates: unnecessary for verdicts and would couple regions. Reserve consensus for control data.
- Blocking on IP alone: causes NAT collateral damage. Prefer graduated responses and device-aware keys.
- No expiry: stale entries accumulate and hit reassigned IPs. Always use TTLs.
- Rollback sharing the bulk channel: it can be delayed by backlog. Isolate it.
- Forgetting cold start: new hosts need snapshots plus delta catch-up before serving enforcement.
Useful metrics: lookup latency percentiles, delta propagation lag per region, rollback end-to-end time, challenge solve rate, and share of traffic affected per rule.