Deploy ClickHouse HA

ClickHouse HA: replicated analytics with Keeper, no data loss.

Deploy ClickHouse HA

/var/lib/clickhouse

/var/lib/clickhouse

/var/lib/clickhouse

Just deployed

/var/lib/clickhouse

Just deployed

Deploy and Host ClickHouse HA on Railway

A replicated ClickHouse cluster with 1 shard, 2 replicas, and a 3-node Keeper ensemble. Built for production analytics workloads that need fault-tolerant columnar storage.

About Hosting

ClickHouse HA deploys a replicated cluster on Railway's private network. Two ClickHouse server nodes store identical data using ReplicatedMergeTree tables, coordinated by a 3-node ClickHouse Keeper ensemble (Raft consensus). A Caddy proxy provides a single public HTTPS endpoint that fails over automatically when a replica goes down. The Keeper ensemble ensures metadata consistency and replication coordination. Each server node has its own persistent volume, and the Keeper ensemble has volumes for coordination logs and snapshots. Tables created with ON CLUSTER are automatically replicated across both nodes. ClickHouse stores analytics data in columnar format, enabling fast queries over billions of rows. The proxy routes all traffic to the healthy replica, so a single node failure does not interrupt service.

Common Use Cases

  • Real-time analytics — dashboards and reports over large datasets with sub-second query times
  • Event and log aggregation — high-throughput ingestion of structured events and logs
  • Time-series data — metrics, IoT telemetry, and monitoring data at scale
  • Data warehousing — columnar storage for OLAP queries with compression
  • A/B testing analytics — fast aggregation over experiment results
  • Business intelligence — ad-hoc queries over large datasets for BI tools

Dependencies for

  • ClickHouse 26.8 — official clickhouse/clickhouse-server:26.8-alpine image
  • ClickHouse Keeper 26.8 — official clickhouse/clickhouse-keeper:26.8-alpine image
  • Caddy 2 — caddy:2-alpine for the public proxy
  • Railway volumes — one per service (5 volumes total: 3 Keeper + 2 Server)
  • Railway private networking — IPv6 inter-service communication

Implementation Details

The cluster uses upstream's replication for fault tolerance topology: 1 shard, 2 replicas, coordinated by a 3-node Keeper ensemble. All services build from this repository using subdirectory Dockerfiles (keeper/, server/, proxy/).

Architecture:

                     ┌──────────────┐
  HTTPS ───────────► │    proxy     │  Caddy — one public URL, fails over
                     └──────┬───────┘
                            │  :8123
              ┌─────────────┴─────────────┐
              ▼                           ▼
      ┌───────────────┐           ┌───────────────┐
      │ clickhouse-1  │◄─────────►│ clickhouse-2  │   1 shard / 2 replicas
      └───────┬───────┘           └───────┬───────┘
              └─────────────┬─────────────┘
                            ▼  :9181
        ┌──────────┐  ┌──────────┐  ┌──────────┐
        │ keeper-1 │  │ keeper-2 │  │ keeper-3 │      raft quorum on :9234
        └──────────┘  └──────────┘  └──────────┘

Default credentials: Username is default. Password is auto-generated via ${{secret(32)}} on first boot (stored as SHA-256 hash). You can set CLICKHOUSE_PASSWORD before deploy to control it. Password changes require redeploying with a new value.

Accessing the HTTP interface:

  1. Open the public domain assigned to the proxy service
  2. Use ClickHouse HTTP API: https:///
  3. Authenticate with username default and the generated password
  4. Run queries via HTTP: curl -u default: https:/// -d "SELECT 1"

Connecting via native protocol (TCP):

Use the ClickHouse native protocol on port 9000. Connect directly to a replica or through a TCP proxy:

clickhouse-client --host  --port 9000 --user default --password 

For internal Railway services, connect directly:

clickhouse-client --host clickhouse-1.railway.internal --port 9000 --user default --password 

Creating replicated tables:

Use ON CLUSTER to create tables on all replicas automatically:

CREATE TABLE events ON CLUSTER default_cluster
(
    ts     DateTime,
    user   String,
    action String
)
ENGINE = ReplicatedMergeTree
ORDER BY (ts, user);

A plain MergeTree (without ON CLUSTER) lives on one replica only and is not replicated.

Connecting via code (Python example):

import clickhouse_connect

client = clickhouse_connect.get_client(
    host="proxy.railway.internal",
    port=8123,
    username="default",
    password=""
)
client.command("CREATE TABLE IF NOT EXISTS test (id UInt64, name String) ENGINE = MergeTree ORDER BY id")
client.insert("test", [[1, "hello"], [2, "world"]])
result = client.query("SELECT * FROM test")
print(result.result_rows)

Ports:

PortPurposeExposure
8123HTTP interface (queries, REST API)Via proxy (public)
9000Native TCP protocol (clickhouse-client, drivers)Private (+ TCP proxy)
9009Inter-server communication (replication)Private (cluster only)
9181Keeper client portPrivate (cluster only)
9234Keeper Raft inter-serverPrivate (cluster only)
9182Keeper HTTP readiness (/ready)Private (health check)

Volumes: One volume per service at /var/lib/clickhouse. Railway volumes are 1:1.

Comparison with Alternatives

FeatureClickHouse HA (this template)Single ClickHousePostgreSQLBigQuery
Query speed (analytics)✅ Sub-second on billions of rows✅ Sub-second⚠️ Slower on large scans✅ Fast
Fault tolerance✅ 2 replicas + Keeper quorum❌ Single node⚠️ Needs HA setup✅ Managed
Cost (self-hosted)⚠️ 6 services✅ 1 service✅ 1 service❌ Usage-based (expensive)
Setup complexity⚠️ 6 services✅ 1 service✅ 1 service✅ Managed
Columnar storage✅ Native✅ Native❌ Row-based✅ Native
SQL compatibility✅ ClickHouse SQL✅ ClickHouse SQL✅ Standard SQL✅ Standard SQL
Data compression✅ Excellent (LZ4, ZSTD)✅ Excellent⚠️ Moderate✅ Automatic
Horizontal scaling✅ Add shards/replicas❌⚠️ Limited✅ Automatic
Self-hosted✅✅✅❌

Security Considerations

  • Password: Auto-generated via ${{secret(32)}} and stored as SHA-256 hash. Never stored in plaintext. Set CLICKHOUSE_PASSWORD before deploy to control it.
  • Default user: Uses default username. Set CLICKHOUSE_USER to rename and remove the stock default account.
  • Network access: ClickHouse HTTP (8123) and native (9000) are accessible via the proxy (public) or private networking. Keeper ports (9181, 9234) and inter-server (9009) are private only.
  • Access management: The configured user has access_management=1, allowing user/role management via SQL.
  • Volume encryption: Railway volumes are encrypted at rest.
  • No public ClickHouse ports: Only the Caddy proxy is public. ClickHouse replicas are private.

Why Deploy ClickHouse HA on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying ClickHouse HA on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Six services with automatic replication, Keeper quorum, and a failover proxy — no ZooKeeper to manage, no manual XML configuration. Set the password and deploy.


Template Content

More templates in this category

View Template
RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set
S3-compatible object store, keys and public URL preset, volume kept

SuperSlowSloth
0
View Template
TimescaleDB
Time-series analytics on PostgreSQL: fast, familiar, scalable.

Rakit
2
View Template
Neo4j 2026.10 Community
Neo4j graph database with APOC, Browser, Bolt TCP proxy and a volume

My Projects
0