Design a System to Capture and Surface the State of Networking Devices

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-05-31

Problem Statement

Design a scalable and reliable system that can collect, store, and surface the current and historical state of networking devices (e.g., routers, switches, firewalls, load balancers, etc.) across a large distributed infrastructure.


The system should periodically capture configuration, performance metrics, and health data from devices, detect changes or anomalies, and make this information available to network engineers and monitoring tools via APIs, dashboards, and alerting mechanisms.


🎯 Core Requirements


1. Data Collection


•Continuously poll or subscribe to network devices to collect:
•Configuration data (e.g., interface configs, routing tables, VLAN info).
•Operational metrics (e.g., CPU/memory usage, packet loss, link status).
•Health indicators (e.g., up/down status, errors, temperature).
•Support multiple protocols (SNMP, NetFlow, gNMI, REST APIs, CLI scrapers).


2. Data Storage & Processing


•Store both current snapshot and historical data for time-series analysis.
•Detect changes in state or configuration drift.
•Support versioning of device state.
•Compress and efficiently store large volumes of telemetry data.


3. Visualization & APIs


•Provide APIs or a dashboard to:
•Query current state of any device.
•View historical trends (e.g., CPU utilization over time).
•Compare configuration versions.
•Search or filter by device, region, vendor, or status.
•Support alerting when devices go offline or exceed defined thresholds.


4. Scalability & Reliability


•Handle hundreds of thousands of devices.
•Support real-time ingestion from millions of telemetry messages per minute.
•Ensure fault tolerance in case of network partitions or device unreachability.
•Minimize data loss with at-least-once delivery guarantees.


5. Non-Functional Requirements


•Availability: 99.9%
•Latency: Near real-time (< 1 minute from device update to dashboard visibility)
•Scalability: Horizontal scaling for ingestion and storage layers
•Durability: Long-term historical data retention (30–90 days)
•Security: Device credentials and telemetry data must be securely stored and encrypted in transit


⚙️ Core Functional Components


ComponentDescription


Device Discovery Service


Periodically scans the network to detect and register devices.


Telemetry Collector


Polls or subscribes to device metrics via SNMP, gNMI, or APIs.


Ingestion Pipeline


Streams incoming data to processing and storage layers.


State Processor


Compares new state vs previous snapshot to detect changes.


Storage Layer


Persists both real-time and historical device state data.


Alerting Engine


Generates alerts for threshold breaches or offline devices.


API Gateway / Dashboard


Exposes data to end-users, UIs, and external systems.


Config Change Tracker


Tracks configuration diffs and versioning for each device.


🧱 High-Level Data Model


Device

1 2Device { 3 device_id: UUID 4 hostname: string 5 ip_address: string 6 location: string 7 vendor: string 8 type: string 9 status: enum { UP, DOWN, DEGRADED } 10 last_seen: timestamp 11}


DeviceState

1 2DeviceState { 3 device_id: UUID 4 timestamp: datetime 5 cpu_usage: float 6 memory_usage: float 7 interface_status: map<string, string> 8 errors: int 9 config_version: string 10}


ConfigVersion

1 2ConfigVersion { 3 device_id: UUID 4 version_id: UUID 5 config_snapshot: text 6 captured_at: datetime 7 diff_with_previous: text 8}


Alert

1 2Alert { 3 alert_id: UUID 4 device_id: UUID 5 alert_type: enum { DOWN, HIGH_CPU, CONFIG_CHANGE } 6 severity: enum { LOW, MEDIUM, HIGH, CRITICAL } 7 message: string 8 timestamp: datetime 9 resolved: boolean 10}


🧩 High-Level Architecture

1 2 +----------------------+ 3 | API Gateway | 4 +----------+------------+ 5 | 6 +-----------------------------------+ 7 | Control Plane | 8 +-----------------------------------+ 9 | Device Discovery | Config Tracker| 10 +-----------------------------------+ 11 | 12 +-----------------------------------+ 13 | Data Plane (Ingestion) | 14 +-----------------------------------+ 15 | Telemetry Collector | SNMP Poller | 16 | Streaming Ingestor | gNMI Agent | 17 +-----------------------------------+ 18 | 19 +------------------------------+ 20 | Message Queue (Kafka) | 21 +------------------------------+ 22 | 23 +-----------------------------------+ 24 | Processing Layer | 25 +-----------------------------------+ 26 | State Processor | Alert Engine | 27 | Change Detector | Dedup Service | 28 +-----------------------------------+ 29 | 30 +-----------------------------------------------+ 31 | Storage Layer | 32 +-----------------------------------------------+ 33 | Time-Series DB (InfluxDB/Prometheus TSDB) | 34 | Metadata DB (PostgreSQL/Cassandra) | 35 | Config Store (S3 / Blob) | 36 +-----------------------------------------------+ 37 | 38 +-----------------------------------+ 39 | Visualization Layer | 40 +-----------------------------------+ 41 | Dashboard / APIs / Grafana | 42 +-----------------------------------+


🧠 Key Design Considerations


1. Data Ingestion


•Use Kafka or AWS Kinesis to handle telemetry streams.
•Devices push telemetry data or are polled by collectors.
•Data is normalized into a common schema before processing.


2. State Computation


•Maintain a latest state snapshot per device.
•Each incoming update is compared to the previous one — if a change is detected, store the diff and publish an event (DEVICE_STATE_CHANGED).


3. Storage Design


Use:

•Time-series DB for metrics (CPU, memory, etc.).
•Relational DB for metadata (device info, alerts).
•Blob storage for configuration snapshots.


4. Alerting


•Thresholds defined per device or globally (e.g., CPU > 80%).
•Alert Engine consumes DEVICE_STATE_CHANGED events and triggers alerts if thresholds are breached.
•Integrate with PagerDuty / Slack / Email for notifications.


5. Scaling Strategy


•Partition ingestion by device region/vendor.
•Use sharded collectors (e.g., SNMP collectors per data center).
•Horizontally scale Kafka consumers and processors.


6. Reliability


•Use checkpointing in consumers for at-least-once processing.
•Retry failed device polls with exponential backoff.
•Keep backup snapshots of all devices periodically (daily/hourly).


📈 Example Flow


1. Device Polling

1 2Telemetry Collector → polls router → receives metrics (CPU=85%, mem=70%)


2. Ingestion

1 2Collector → pushes metrics to Kafka topic: device_telemetry


3. Processing

1 2State Processor → compares with previous state → detects CPU threshold breach 3→ publishes event DEVICE_ALERT to Kafka


4. Alert

1 2Alert Engine → consumes DEVICE_ALERT → creates alert → sends notification


5. Visualization

1 2User queries dashboard → sees device state, config diff, alert history


🧱 Storage Choices


Data TypeSuggested StorageReason


Device metadata


PostgreSQL / MySQL


Strong consistency


Telemetry metrics


Time-series DB (Prometheus, InfluxDB)


Optimized for time queries


Config snapshots


S3 / Blob storage


Large, infrequent objects


Alerts


Cassandra / DynamoDB


Fast writes, high availability


Caching


Redis


Reduce DB load


Queue


Kafka / Kinesis


Decoupled event pipeline


⚙️ Key APIs


APIDescription


GET /devices


List all devices with current status


GET /devices/{id}/state


Fetch latest state snapshot


GET /devices/{id}/history


Fetch time-series data for metrics


GET /devices/{id}/config/{version}


Retrieve specific config version


GET /alerts


List active or historical alerts


POST /alerts/acknowledge


Acknowledge and resolve alerts


🚀 Scalability Enhancements


•Use edge collectors to offload central systems.
•Implement sampling and data aggregation for high-frequency telemetry.
•Use stream processing frameworks (Flink / Spark Streaming) for real-time analysis.
•Archive older data into cheaper storage (e.g., S3 Glacier).


✅ Goal:


Design a real-time, scalable, and resilient network state tracking system that captures device telemetry and configuration, stores historical data, detects anomalies, and surfaces insights to network operators through APIs and dashboards.

Solution

Comments