1. Replicated engine
ReplicatedMergeTree adds replication on top of the normal MergeTree storage.
ENGINE = ReplicatedMergeTree(Typorithm · medium
Step 1 of 8 · intro card
Scale & Ops
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/events', '{replica}') replicates parts across replicas via ClickHouse Keeper (ZooKeeper) for high availability.
ReplicatedMergeTree is a MergeTree that keeps multiple synchronized copies of each part across replica nodes.
ClickHouse Keeper (or ZooKeeper) coordinates the replicas: it tracks which parts exist and which replicas have them.
The Keeper path and {replica} macro identify the table and the node, so a failed replica can rejoin and catch up automatically.
Replicates each part across replica nodes.
Keeper (ZooKeeper) coordinates the replicas.
Gives high availability and failover.
CREATE TABLE events
(
event_date Date,
user_id UInt64,
value Float64
)
ENGINE = ReplicatedMergeTree(
'/clickhouse/tables/{shard}/events',
'{replica}'
)
PARTITION BY toYYYYMM(event_date)
ORDER BY (user_id, event_date);Connect each part of the code to the concept before you type.
ReplicatedMergeTree adds replication on top of the normal MergeTree storage.
ENGINE = ReplicatedMergeTree(This Keeper path identifies the replicated table; {shard} keeps each shard's replicas in their own group.
'/clickhouse/tables/{shard}/events'The replica macro names this node so its copy is distinct from its peers in the same group.
'{replica}'Replication does not change the MergeTree contract — ORDER BY still defines the sort and sparse index.
ORDER BY (user_id, event_date)Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.