IP Filtering System Design
Problem Statement
Design the Low-Level Design (LLD) for an IP Filtering System that decides whether to allow or block incoming network requests based on configurable IP filtering rules.
The system should efficiently manage and apply whitelists, blacklists, and CIDR-based range filters, and support dynamic rule updates without downtime.
🎯 Core Requirements
1. IP Rule Management
2. Filtering Logic
3. Dynamic Updates
4. Persistence & Caching
5. Audit Logging
⚙️ Functional APIs
APIDescription
addRule(ruleId, ruleType, value)
Adds a new whitelist or blacklist rule.
removeRule(ruleId)
Deletes an existing rule.
checkAccess(ipAddress)
Returns ALLOW or DENY for a given IP.
loadRules()
Loads rules from a persistent store on startup.
listRules()
Returns all active filtering rules.
🧱 Class Design (Suggested)
ClassResponsibility
IPRule
Represents a single filtering rule (id, type, IP/CIDR pattern).
IPFilterManager
Maintains collections of whitelist and blacklist rules.
IPMatcher
Performs IP or CIDR matching logic.
CacheManager
Stores cached results for previously checked IPs.
AuditLogger
Logs filtering decisions.
IPFilterService
Main entry point for checking access and managing rules.
🧩 Example Scenario
Rules configured:
1
2Whitelist:
3 - 10.0.0.5
4 - 192.168.0.0/16
5Blacklist:
6 - 203.0.113.45
7 - 172.16.0.0/12Requests:
IP AddressDecisionReason
10.0.0.5
ALLOW
Whitelisted exact IP
192.168.2.10
ALLOW
Matches CIDR range
203.0.113.45
DENY
Explicitly blacklisted
8.8.8.8
DENY
Default deny (not matched)
🧠 Design Considerations
Performance:
Thread Safety:
Extensibility:
Scalability:
🔄 Sample Flow
System Initialization
Incoming Request
1
2checkAccess("192.168.2.10")
3→ IPMatcher checks whitelist and blacklist
4→ Decision: ALLOW
5→ AuditLogger logs eventDynamic Update
1
2addRule("R102", "BLACKLIST", "10.0.0.0/8")
3→ Rule added in memory
4→ Future requests from 10.x.x.x will be blocked🧱 Sample Class Diagram
1
2+-------------------+
3| IPRule |
4+-------------------+
5| ruleId |
6| type (ALLOW/DENY) |
7| cidrRange/IP |
8+-------------------+
9
10+-------------------+
11| IPMatcher |
12+-------------------+
13| +matches(ip, rule)|
14+-------------------+
15
16+-------------------+
17| IPFilterManager |
18+-------------------+
19| whitelist: List<IPRule> |
20| blacklist: List<IPRule> |
21| +addRule() |
22| +removeRule() |
23| +getDecision(ip) |
24+-------------------+
25
26+-------------------+
27| CacheManager |
28+-------------------+
29| cache: Map<ip, result> |
30| +getResult(ip) |
31| +putResult(ip, result) |
32+-------------------+
33
34+-------------------+
35| IPFilterService |
36+-------------------+
37| +checkAccess(ip) |
38| +addRule() |
39| +removeRule() |
40+-------------------+
41
42+-------------------+
43| AuditLogger |
44+-------------------+
45| +log(ip, rule, result) |
46+-------------------+🚀 Possible Extensions
✅ Goal:
Design an extensible, efficient IP Filtering System that can manage dynamic allow/deny rules, support CIDR-based IP ranges, provide fast lookups, and maintain audit logs for all access decisions.