Skip to the matchbox tray

Noction Flow Analyzer Adds ClickHouse Sharding and Replication for Growing Deployments

Administrator 642 views

NFA can spread flow and BGP data across ClickHouse shards and replicate each shard, while keeping a single server as the default starting point.

Noction Flow Analyzer Adds ClickHouse Sharding and Replication for Growing Deployments

Noction Flow Analyzer (NFA) can now use multiple ClickHouse shards and replicas to handle growing traffic datasets and reduce reliance on a single database server. For administrators, the distinction matters: shards divide data and database work among servers, while replicas maintain additional copies of each shard’s data. The architecture supports both flow records and BGP routing information.

NFA Sharding

The design keeps a one server configuration as the default. An NFA installation can begin with one shard and one replica, then add database nodes when storage capacity or data availability needs change. That gives operators a way to expand ClickHouse without installing the full NFA application on every database server.

Scaling the database addresses only database limits. The flow collector still has to receive and process exports from NetFlow, sFlow, IPFIX, J-Flow, and NetStream devices. If collection is the bottleneck, adding ClickHouse shards won’t by itself solve it.

One cluster from the start

NFA uses MySQL for application information and ClickHouse for traffic data, BGP information, and the aggregated datasets behind reporting and analysis. In a typical installation, ClickHouse runs on the same server as NFA. That layout keeps administration relatively simple and can be sufficient when the server has the resources required for incoming records, retention, and queries.

With the sharding-enabled architecture, a new installation creates a ClickHouse cluster named nfa, initially with one shard and one replica. ClickHouse Keeper, the cluster definition, and the identifiers used by replicated tables are also configured. Although this may seem like extra setup for a one server deployment, it means the database already uses a structure that can accommodate additional nodes.

Keeper coordinates replication and some distributed database operations. In the default setup, it runs locally alongside ClickHouse Server, and the database service starts after Keeper. Keeper holds coordination information; it does not store the flow or BGP dataset.

There’s an important limit to what the default configuration provides. A replicated table engine can be present with only one replica, but that does not create a second physical copy. One shard with one replica still has a single database copy. Operators need to add a replica to gain another copy of that shard’s data.

How NFA distributes flow and BGP records

NFA uses ClickHouse Distributed tables to route inserts to shards and to present data across the cluster as a logical dataset. Flow and BGP records have different structures, so NFA uses a separate sharding key for each. ClickHouse hashes the selected record attributes and maps the result to a shard in the configured cluster.

Flow placement uses exporter and address fields

For flow data, the sharding expression is:

cityHash64(
exporter_address,
exporter_id,
src_address,
dst_address
)

The key combines the exporter’s address and identifier with the source and destination IP addresses. NFA has local storage tables such as flows_data1 and corresponding Distributed tables such as flows_data1_dist. The Distributed table references the nfa cluster and the local table that stores the records.

Including source and destination addresses gives the hash more ways to spread records from a busy exporter across shards. An exporter-only key could concentrate records from a high-volume router on one server, even if many other exporters produce less data. With address pairs in the key, records from the same exporter can map to different shards.

This does not guarantee a perfectly even split. Actual traffic patterns determine how many records and how much processing each shard receives. The key also isn’t a conventional five-tuple: it omits transport ports and IP protocol. Records with the same exporter context and source-destination address pair therefore produce the same hash even if they represent different TCP or UDP conversations.

Shard assignment also depends on the cluster configuration. Changing the number or weighting of shards can change where future inserts go, but it does not automatically relocate records already stored.

BGP placement uses session and prefix

NFA’s optional BGP Data capability obtains routing information through BGP sessions with network devices. This data supports analysis of prefix announcements and withdrawals, routing changes, and correlations between traffic and attributes such as AS_PATH.

The BGP sharding key is:

cityHash64(session, prefix)

Here, session is the address of the BGP session that supplied the routing information, and prefix identifies the network. The Distributed table is defined as:

ENGINE = Distributed(
nfa,
currentDatabase(),
bgp,
cityHash64(session, prefix)
);

Records for the same session and prefix have the same key. For example, an announcement for 203.0.113.0/24 and a later withdrawal for that prefix map to the same shard while the sharding configuration remains unchanged.

Different prefixes from one session can land on different shards, while the same prefix received through separate sessions can also be split across shards. As with flow records, hashing creates opportunities to distribute data; it doesn’t promise equal BGP update counts on every server.

The local BGP table uses ClickHouse’s ReplicatedMergeTree engine. When a shard has multiple replicas, that engine synchronizes the BGP data between them using the same replication mechanism as the flow tables.

Queries span the cluster

When data is spread across multiple shards, a report may need records stored on several ClickHouse servers. NFA’s Distributed tables give queries a cluster-wide view. ClickHouse runs work on the relevant shards and combines the results, so an operator can query traffic by destination address across the cluster without manually collecting separate reports from each server.

The same applies to BGP data. Information about a prefix may sit on different shards if multiple sessions supplied it. A query through the Distributed table can retrieve data from across the configured cluster.

Some NFA queries use IN or JOIN subqueries involving distributed tables. For the documented multi-shard configuration, ClickHouse uses:

distributed_product_mode = global

This setting allows the relevant distributed operations to use global query execution semantics. It needs to be applied consistently across the ClickHouse nodes. It’s part of the database configuration rather than a setting operators normally change through NFA’s reporting interface.

More nodes don’t automatically make every query faster. Performance depends on the data involved, server resources, and network communication between nodes. A distributed query may help with large analytical workloads, but it still has to coordinate work across the cluster.

Replication keeps copies within a shard

Sharding and replication solve different problems. Sharding places different portions of the dataset on separate servers. Replication maintains copies of the data within a shard.

NFA tableClickHouse storage engine
bgpReplicatedMergeTree
flows_data1ReplicatedAggregatingMergeTree
flows_data2ReplicatedAggregatingMergeTree
flows_data3ReplicatedAggregatingMergeTree
flows_data_1s_compactReplicatedAggregatingMergeTree

The AggregatingMergeTree family supports aggregation-oriented storage. Its replicated variant maintains the corresponding data on replicas of the same shard.

NFA’s cluster configuration sets internal_replication=true. When an insert reaches a Distributed table, ClickHouse selects the destination shard and sends the block to one of its replicas. The replicated table engine then coordinates synchronization with the other replicas. NFA doesn’t have to insert every record separately on every copy.

Synchronization may take time if a replica is unavailable or has queued work to process. The replicas can temporarily differ in physical data parts while ClickHouse performs background merges, even when they represent the same logical dataset.

Keeper paths distinguish replicas of one shard from tables on another shard. For example, the flows_data1 table on Shard 01 uses:

/clickhouse/tables/01/nfa/flows_data1

The BGP table on that shard uses:

/clickhouse/tables/01/nfa/bgp

Another replica of Shard 01 shares those table paths but registers with its own replica identifier. Shard 02 uses separate paths, including:

/clickhouse/tables/02/nfa/flows_data1
/clickhouse/tables/02/nfa/bgp

NFA stores shard and replica identifiers as ClickHouse macros, with values set for each node. The ClickHouse documentation on replication describes the database mechanism.

Choose shards, replicas, or both

The right topology depends on whether the constraint is storage and query capacity, the need for another data copy, or both.

One shard, one replica

This is the default starting point. One local ClickHouse instance stores the data, with no inter-node database traffic. It can be a sensible choice when the server has enough capacity for exporters, retention, and reporting. There’s no additional database copy, however, so a failure of the only ClickHouse server can make its data inaccessible until service is restored.

Two shards, one replica each

Adding a second shard can increase available storage and processing capacity. Distributed inserts can send new flow and BGP records to either shard according to their respective keys. Each server stores a different portion of the datasets, so neither holds a complete replica of the other.

Adding a shard does not automatically divide historical data between the servers. Existing records remain on the original shard unless a separate redistribution procedure is performed. Disk usage may therefore remain uneven after the expansion. And because each shard has only one replica, loss of a server can make that shard’s portion of the data inaccessible.

One shard, two replicas

A second replica is the relevant option when data availability is the priority rather than additional storage for unique records. The new server joins the existing shard and synchronizes that shard’s data. Once synchronization is complete, both replicas maintain the same logical flow and BGP datasets.

This can help preserve access to data during certain server failures or maintenance, provided the remaining replica and supporting services are working. Replication doesn’t increase the amount of unique historical information the shard can hold.

Two shards, two replicas per shard

A larger deployment can combine both approaches: Shard 01 has two replicas and Shard 02 has two replicas, for four ClickHouse instances. The shards hold different portions of the data, while replicas within each shard maintain copies of that portion.

This arrangement combines distributed capacity with database redundancy, but it also adds infrastructure to operate. The environment needs adequate network, storage, and processing resources for replication and distributed queries. Losing both replicas of a shard can still make that shard’s data unavailable, and shared dependencies remain relevant.

Upgrading an existing installation

For an existing NFA deployment, moving to the cluster-aware structure means migrating ClickHouse tables while retaining historical data. The upgrade prepares the database services, then changes the storage engines and creates the Distributed tables needed for sharding.

ClickHouse Keeper is started and checked before ClickHouse Server is prepared and verified. If database preparation fails, the schema upgrade should not proceed. The package upgrade also stops NFA services that could write to the affected tables, preventing new inserts during the migration.

The BGP table changes from MergeTree to ReplicatedMergeTree. The main aggregated flow tables change from AggregatingMergeTree to ReplicatedAggregatingMergeTree.

The migration creates temporary replicated tables with the intended Keeper paths, then attaches partitions from the existing tables before replacing the original table objects. When the old and new tables use the same ClickHouse storage, attaching partitions can reuse existing data parts instead of inserting every row into a new table. That approach matters when an installation holds substantial history.

The upgrade leaves the installation on one server: the existing node becomes Shard 01, Replica 01 of the nfa cluster. Historical data stays there, and operators can keep using the single-node deployment until they need more capacity or redundancy.

Adding and checking database nodes

An additional database server needs a compatible ClickHouse version and the correct cluster configuration, but it doesn’t need its own full NFA application installation. Nodes must resolve one another’s configured hostnames, establish database connections, and communicate with Keeper. Each also needs shard and replica identifiers set to match its role.

To add a shard, assign a new shard identifier, update the cluster configuration, and initialize the required NFA schema. New Distributed inserts can then be assigned to it. Schema initialization is coordinated from the original NFA node using the nfaadm administration utility. Existing records do not move merely because the new shard has been added.

To add a replica, use the existing shard identifier and assign a different replica identifier. Once the replicated tables are initialized, ClickHouse can synchronize the shard’s data to the new server. The catch-up time depends on the amount of data and available network and storage performance. A replica with a large backlog should not be treated as fully synchronized simply because it appears in the cluster configuration. NFA’s documented setup includes checks for active replicas and replication queues returning to normal.

Multi-node deployments also need monitoring beyond the NFA frontend and collector. ClickHouse’s system.clusters table shows the configured topology, including shard and replica hosts. system.replicas reports replica status, active replica counts, queues, delay, and read-only state.

Check that expected replicas are active and that synchronization backlogs clear as pending work is processed. Physical part counts can differ temporarily because ClickHouse merges data in the background. Replica health and logical consistency are more useful signals than expecting matching physical part layouts at every moment.

Keeper remains a dependency

The documented NFA configuration runs ClickHouse Keeper on the NFA node, and additional ClickHouse servers connect to that Keeper instance. That dependency matters when evaluating availability: replicas rely on coordination services for replication-related operations. Loss of Keeper connectivity can leave replicated tables read-only or affect other operations that require coordination.

Database replicas alone therefore don’t make the whole NFA installation highly available. Operators planning for greater fault tolerance need to include Keeper availability in their design and monitoring.

What the architecture changes for operators

Sharding gives NFA a way to spread ClickHouse storage and analytical work across additional servers. Replication provides copies of each shard’s flow and BGP data. Together, those mechanisms can address growing database capacity needs and help maintain access to stored data during some individual node failures.

They don’t replace flow collection capacity, independent backups, or operational monitoring. Database replication can propagate unwanted changes, so it isn’t a substitute for separate recovery copies. Administrators also take on inter-node connectivity, authentication, storage use, replica synchronization, and Keeper as parts of the monitoring system.

The practical choice is to add only the capacity or copies the deployment needs. A single server remains the supported starting point; additional shards and replicas can be introduced as retention, query workloads, or availability requirements grow. Before expanding, identify whether the pressure is in collection or storage, decide whether historical data must be redistributed, and verify that Keeper and replica health are included in ongoing checks.

Source: Administrator · www.noction.com

From the Same Series