ClickHouse Cluster Architecture (Nodes, Shards, Replicas, etc.)
ClickHouse is a distributed database engine that supports real-time data processing and analysis. It provides a cluster structure to manage data and Queries, including nodes, partitions, and replicas.
Node (Node)
A node is a single instance within a ClickHouse cluster responsible for storing and processing data. Each node can contain multiple partitions.
Node Types
ClickHouse supports two types of nodes:
- master: The master node responsible for accepting queries and maintaining metadata.
- slave: A backup node that typically does not accept Queries but is used for failover purposes.
Partition (Partition)
Each node can contain multiple partitions, where each partition stores data within a specific range. Partitions can be divided based on various criteria such as time, geographic location, or keywords.
Partition Types
ClickHouse supports the following types of partitions:
- date: Time-based partitions used for storing data by day.
- space_id: Geographic space-based partitions used for storing data by region.
- hash: Hash-based partitions used for storing data based on hash values.
Replica (Replica)
A replica is a copy of the master node, providing multi-point reliability and high availability. Each node can contain multiple replicas.
Replica Types
ClickHouse supports two types of replicas:
- active: The primary replica used for data storage and processing.
- inactive: A backup replica typically not intended for direct access.
Cluster Structure
The structure of a ClickHouse cluster is shown below:
+---------------+
| master |
+---------------+
| |
| +-------+ |
| | slave1| |
| +-------+ |
| |
| +-------+ |
| | slave2| |
| +-------+ |
+---------------+
| slave1 |
+---------------+
| |
| +-------+ |
| | node3| |
| +-------+ |
| |
| +-------+ |
| | node4| |
| +-------+ |
+---------------+
| slave2 |
+---------------+
In this structure, the master node is responsible for managing cluster metadata, while slave nodes are responsible for storing and processing data. Each slave node can contain multiple replicas.
High Availability
ClickHouse clusters provide high availability to ensure that data storage and access remain unaffected by single points of failure. If a master node fails, it can be temporarily moved to a slave node until the master recovers normal operation. Additionally, each slave node serves as an alternative for the master to ensure cluster reliability.
Real-time Data Processing
ClickHouse provides a high-performance real-time data processing engine capable of handling large datasets with low latency and high throughput. It supports various data sources and storage formats such as MySQL, PostgreSQL, Kafka, and HDFS.