IPDR Logging at Scale with ClickHouse
Jaze ISP Manager stores every NAT session from more than 3,500 BNGs and CGNAT routers in ClickHouse, so the ISPs we serve can meet their IPDR obligations. That's over 300,000 rows a second and two years of history, with a full copy in each of our two data centres.
- 300,000+Rows a second, in real time
- 3,500+BNGs and CGNAT routers
- 2 yearsOf NAT history kept
- 2 copiesOne in each data centre
Why IPDR compliance needs every NAT record
An ISP has to be able to answer IPDR requests. A lawful request or an abuse complaint usually arrives with a public IP, a port and a timestamp, and the ISP must name the subscriber who was behind that address at that moment, sometimes many months later. Behind CGNAT, many subscribers share each public address, so that answer only exists if every NAT translation was logged. Jaze ISP Manager does that logging, and everything in this post is about answering that one question reliably.
The BNGs and CGNAT routers on our customers' networks send a record, as IPFIX or NetFlow v9, every time they open or close a NAT session or hand out a port block. ClickHouse stores those records. The subscriber details live elsewhere, in a session log table in a separate MySQL database, built from our AAA accounting records. For an IPDR lookup we pull the matching NAT entries from ClickHouse, then match each one against that session log to get the subscriber and their details.
That puts two hard requirements on the log store. It can't lose data when a server or a whole data centre fails, and it has to find a handful of rows among billions in seconds.
We built the NAT log store in Jaze ISP Manager on ClickHouse with one shard and two replicas, one per data centre, coordinated by ClickHouse Keeper. It's the layout from ClickHouse's 1 shard, 2 replicas example, stretched across two sites. We think ClickHouse is about as good a fit for flow data as you'll find. The same exporters, address pools and ports repeat endlessly, which a column store compresses extremely well. Sort the table by public IP, port and time, and "who had this address" becomes a short range scan. Replication is built in through Keeper, so there's no extra software to run for it.
Architecture
The cluster is five nodes. Two ClickHouse servers each hold the full dataset, one per data centre. Three Keeper nodes coordinate replication: one in each data centre and a third on an independent instance with a different hosting provider.
That third Keeper is the most important decision in the design. With only two sites, one of them would have to host two Keepers. Losing that site would leave the surviving Keeper without a majority, so both replicas would go read-only and ingest would stop, even though a complete copy of the data was still running. With the third Keeper elsewhere, either data centre can fail and the other keeps ingesting.
Data centre A
Data centre B
BNG / CGNAT routers
IPFIX · NetFlow v9
BNG / CGNAT routers
IPFIX · NetFlow v9
Ingestor servers
Load balanced · decode
Ingestor servers
Load balanced · decode
Kafka cluster, across both sites
Partitioned topics · records wait here
Consumers
Multi-threaded · batched
Consumers
Multi-threaded · batched
ClickHouse replica 1
Full copy
ClickHouse replica 2
Full copy
Keeper 1
Raft member
Keeper 2
Raft member
Second hosting provider
Keeper 3
Tie-breaker
A single Kafka cluster stretches across both data centres. Ingestor servers in each site publish to it, and consumers write into the ClickHouse replica in their own site. ClickHouse then ships each new data part to the other site over a 2 Gbps point-to-point link. The dashed lines are Keeper's Raft traffic.
Hardware and how storage grew
Each data centre has one ClickHouse server, an HPE Apollo Gen10 with expandable drive bays, 56 cores, 256 GB of RAM and a 2 TB SSD for ingest. Storage is the part that has grown, in three steps.
We started with 24 × 20 TB HDDs in RAID 6 inside the main server. To grow it, we added a second Apollo of the same spec as a storage-only node, connected to the main server over 10G and exporting its array over NFS. A storage node only serves files, so 4 cores and 8 GB of DDR4 is plenty. Two more storage nodes followed the same way, this time HPE Apollo Gen11 machines with 24 × 24 TB drives in RAID 6, because that's what the market had. Both data centres got identical upgrades, so the replicas still mirror each other.
| Server | Hardware | Disks | Usable in RAID 6 |
|---|---|---|---|
| Main server | HPE Apollo Gen10, 56 cores, 256 GB RAM, 2 TB SSD | 24 × 20 TB | 440 TB |
| Storage node 1 | HPE Apollo Gen10, 4 cores, 8 GB RAM, NFS over 10G | 24 × 20 TB | 440 TB |
| Storage node 2 | HPE Apollo Gen11, 4 cores, 8 GB RAM, NFS over 10G | 24 × 24 TB | 528 TB |
| Storage node 3 | HPE Apollo Gen11, 4 cores, 8 GB RAM, NFS over 10G | 24 × 24 TB | 528 TB |
That's about 1.9 PB of usable disk per data centre, before filesystem overhead. RAID 6 costs two drives per array and lets each array survive two failed disks. With drives of 20 TB and up, rebuilds take long enough that we wouldn't run anything less. Because the replicas exchange compressed parts, the 2 Gbps link between sites only carries about a fifth of the raw volume.
How records get in
Records reach ClickHouse in real time, at more than 300,000 rows a second.
- 1
Routers export IPFIX and NetFlow v9 to a pool of ingestor servers in their data centre, with the load balanced across them. The ingestors accept traffic only over encrypted tunnels, so bad bots can't push data into the cluster.
- 2
The ingestors decode each record as it arrives and normalise both formats into one layout, so a NetFlow v9 record and an IPFIX record land in the same columns.
- 3
The ingestors publish to the multi-node Kafka cluster. If ClickHouse slows down or a server restarts, records wait in Kafka until it catches up.
- 4
Several consumer processes, each running multiple threads, read from Kafka and write batches to the local ClickHouse replica.
- 5
ClickHouse registers each new data part in Keeper, and the replica in the other data centre fetches it.
The consumers batch hard. At more than 300,000 rows a second, they send only one or two insert queries a second, and we'd call this the single most important thing to get right when you feed ClickHouse. Every insert becomes a new part on disk that has to be merged in the background. A few large inserts keep merge work under control, and thousands of small ones a second will bury the server. Doing it without lag comes down to how the Kafka topics are partitioned and how those partitions are spread across consumer threads. We have never seen lag in normal operation. The only time it appears is when one of the Kafka servers fails and the cluster resynchronises, and even then Kafka's replication brings it back on its own without losing any data.
Kafka also decouples the network from the database. We can restart or upgrade a ClickHouse server while every router keeps exporting, and the records simply wait in Kafka until it's back.
Storage, retention and compression
The table is partitioned by day, and each daily partition works its way down a chain of disks as it ages. The newest one sits on the SSD, which takes the full insert and merge load. From there, data moves through the HDD tiers in six-month steps:
| Data age | Where it lives |
|---|---|
| Today | SSD in the main server |
| 1 day to 6 months | HDD array in the main server |
| 6 to 12 months | Storage node 1, over NFS |
| 12 to 18 months | Storage node 2, over NFS |
| 18 to 24 months | Storage node 3, over NFS |
| Over 2 years | Dropped |
Each time we added a storage node, we updated the ClickHouse storage policy to make it the next tier. At two years, ClickHouse drops the partition automatically. Dropping a partition just deletes its files, so retention costs almost nothing.
We compress with ZSTD, and data on disk is about 20% of its raw size. That's roughly 5:1, so 1 TB of raw records takes about 200 GB. The sort order does a lot of the work here. Rows for the same public IP sit together, so neighbouring values in each column are nearly identical, and ZSTD does very well on that. With two years of history kept in both data centres, the alternative to 5:1 compression is buying five times the disk.
Answering an IPDR request
A typical IPDR request asks who held a public IP and port at a given time. The table is sorted by public IP, then port, then time, so ClickHouse reads only a thin slice of the data to find the matching NAT entries, even with two years on disk. Port-block allocations go through the same lookup; the port only has to fall inside the allocated range.
That gives us half the answer. Each NAT entry ClickHouse returns is then matched against the session log table in MySQL, which tells us the subscriber and their details. We like keeping the two apart. The session records are generated from AAA accounting, so they belong with the rest of our subscriber data in MySQL, and ClickHouse is left to do what it's best at: scanning an enormous append-only log.
Monitoring
Every 5 minutes we check that each of the 3,500+ routers still has records landing in ClickHouse. If one goes quiet, the ISP that runs it and our admins get a notification immediately. We deliberately check stored rows, because that catches a failure anywhere between the router and the disk: a router that stopped exporting, an ingestor that can't parse its template, or an insert that failed.
For Kafka we use UI for Apache Kafka, the open-source web console from Provectus. It shows brokers, topics and consumer groups, with committed offsets and lag for every partition. We query it on a schedule, and when consumer lag passes a set threshold, we get an email alert. Every server is also on our NMS.
Even at peak ingest, CPU on the ClickHouse nodes barely reaches 50%.
Where this goes next
Once configured, the system has run without a hitch, and ISPs using Jaze ISP Manager get real-time notifications telling them their routers are sending data and that it's being stored. We're still a little amazed at what an open-source column store does on commodity hardware: two years of NAT logs from more than 3,500 routers, with CPU that stays around 50% even at peak.
Every layer can scale out on its own. Ingest is load balanced across multiple ingestor servers, Kafka grows by adding brokers and partitions, and the consumers are multi-threaded and consumer instances can be scaled up on demand. ClickHouse is the layer we expect to need attention first. The highest published Kafka-to-ClickHouse throughput we know of is 500,000 records per second, and as we get closer to that rate, we plan to move from today's two-node replicated pair to a larger, multi-node ClickHouse cluster.