FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplatesGuides
Release Notes
Source514
  1. MooseStack
  2. Table Engines
  3. Replicated Engines

Replicated Engines

Replicated engines provide high availability and data replication across multiple ClickHouse nodes. MooseStack supports all standard replicated MergeTree variants:

  • ReplicatedMergeTree - Replicated version of MergeTree
  • ReplicatedReplacingMergeTree - Replicated with deduplication
  • ReplicatedAggregatingMergeTree - Replicated with aggregation
  • ReplicatedSummingMergeTree - Replicated with summation
  • ReplicatedCollapsingMergeTree - Replicated with state collapsing
  • ReplicatedVersionedCollapsingMergeTree - Replicated with versioned collapsing
ReplicatedEngines.py
from moose_lib import OlapTable, OlapConfigfrom moose_lib.blocks import (    ReplicatedMergeTreeEngine,    ReplicatedReplacingMergeTreeEngine,    ReplicatedAggregatingMergeTreeEngine,    ReplicatedSummingMergeTreeEngine) class Record(BaseModel):    id: Key[str]    updated_at: datetime    deleted: int = 0 # Basic replicated table with explicit pathsreplicated_table = OlapTable[Record]("records", OlapConfig(    order_by_fields=["id"],    engine=ReplicatedMergeTreeEngine(        keeper_path="/clickhouse/tables/{database}/{shard}/records",        replica_name="{replica}"    ))) # Replicated with deduplicationreplicated_dedup = OlapTable[Record]("dedup_records", OlapConfig(    order_by_fields=["id"],    engine=ReplicatedReplacingMergeTreeEngine(        keeper_path="/clickhouse/tables/{database}/{shard}/dedup_records",        replica_name="{replica}",        ver="updated_at",        is_deleted="deleted"    ))) # For ClickHouse Cloud or Boreal (no parameters needed)cloud_replicated = OlapTable[Record]("cloud_records", OlapConfig(    order_by_fields=["id"],    engine=ReplicatedMergeTreeEngine()))
Configuring Replication

Replicated engines support three configuration approaches. Choose the one that fits your deployment:

Default

Omit all replication parameters. Moose uses smart defaults that work in both ClickHouse Cloud and self-managed environments:

DefaultReplication.py
table = OlapTable[Record]("my_table", OlapConfig(    engine=ReplicatedMergeTreeEngine(),  # No parameters    order_by_fields=["id"]))

Moose auto-injects: /clickhouse/tables/{database}/{shard}/{table_name} and {replica} in local development. ClickHouse Cloud uses its own patterns automatically.

Cluster

For multi-node deployments, specify a cluster name to use ON CLUSTER DDL operations:

ClusterReplication.py
table = OlapTable[Record]("my_table", OlapConfig(    engine=ReplicatedMergeTreeEngine(),    order_by_fields=["id"],    cluster="default"  # References cluster from moose.config.toml))

Configuration in moose.config.toml:

[[clickhouse_config.clusters]]name = "default"

Use when:

  • Running multi-node self-managed ClickHouse with cluster configuration
  • Need ON CLUSTER DDL for distributed operations
Replication Paths

For custom replication topology, specify both keeper_path and replica_name:

ExplicitReplication.py
table = OlapTable[Record]("my_table", OlapConfig(    engine=ReplicatedMergeTreeEngine(        keeper_path="/clickhouse/tables/{database}/{shard}/my_table",        replica_name="{replica}"    ),    order_by_fields=["id"]))

Use when:

  • Need custom replication paths for advanced configurations
  • Both parameters must be provided together
Warning:

Cannot mix approaches: Specifying both cluster and explicit keeper_path/replica_name will cause an error. Choose one approach.

Cluster is a deployment directive: Changing cluster won't recreate your table -— it only affects future DDL operations.

For more details, see the ClickHouse documentation on data replication.

  • Overview
Build a New App
  • 5 Minute Quickstart
  • Browse Templates
  • Existing ClickHouse
Add to Existing App
  • Next.js
  • Fastify
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
Moose Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs & Web Apps
Deployment & Lifecycle
  • Moose Migrate
  • Moose Deploy
Reference
  • API Reference
  • Data Types
  • Table Engines
    • MergeTree
    • ReplacingMergeTree
    • AggregatingMergeTree
    • SummingMergeTree
    • Replicated Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Release Notes
Contribution
  • Documentation
  • Framework