---
title: "Deploy Kafka HA"
description: "Kafka HA: 3-node KRaft cluster with failover and replication."
category: "Queues"
url: https://railway.com/deploy/kafka-ha
---

# Deploy Kafka HA

Kafka HA: 3-node KRaft cluster with failover and replication.

**[Deploy Kafka HA on Railway](https://railway.com/template/kafka-ha)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/kafka-ha/manifest.json

- **Creator:** Rakit
- **Category:** Queues
- **Total deploys:** 1

## Template content

### kafka-3 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/kafka.svg

- **Source:** codestorm-official/kafka-ha

### kafka-1 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/kafka.svg

- **Source:** codestorm-official/kafka-ha

### kafka-2 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/kafka.svg

- **Source:** codestorm-official/kafka-ha

## Documentation

# Deploy and Host Kafka HA on Railway

A 3-node Apache Kafka cluster in KRaft mode with replication and automatic failover. Built for production event streaming workloads that need fault-tolerant message brokering.

## About Hosting

Kafka HA deploys three combined broker/controller nodes on Railway's private network using KRaft mode — no ZooKeeper required. Each node holds both broker and controller roles, forming a 3-node controller quorum. Topics are replicated across all 3 nodes (replication factor 3, min in-sync replicas 2), so a single node failure does not lose data or interrupt service. Each node has its own persistent volume for partition logs, offsets, and KRaft metadata. The cluster uses a fixed cluster ID for consistency across redeploys. A public TCP proxy with SASL/SCRAM authentication provides secure external access. The private network listener is plaintext for internal Railway services. Health checks run on port 8080 via a built-in HTTP endpoint.

## Common Use Cases

- **Event streaming** — real-time data pipelines between microservices
- **Log aggregation** — centralized logging with replay capability
- **Change data capture (CDC)** — database change events streamed to downstream systems
- **Event sourcing** — immutable event log for audit trails and state reconstruction
- **Message queuing** — durable message queues with consumer groups
- **Stream processing** — feeding Kafka Streams, Flink, or Spark for real-time analytics

## Dependencies for

- **Apache Kafka 4.4.0** — official `apache/kafka:4.4.0` image (240 MB)
- **Railway volumes** — one persistent volume per node at `/var/lib/kafka` (3 volumes total)
- **Railway private networking** — IPv6 inter-service communication
- **Railway TCP proxy** — for external client access with SASL authentication

### Implementation Details

Each node runs as a combined broker/controller in KRaft mode. The start script renders a `railway-server.properties` config file with the cluster ID, controller quorum voters, listeners, and replication settings. Storage is formatted with the shared cluster ID on first boot. Node 1 creates the SASL user after the broker is ready. All nodes share the same cluster ID and controller quorum configuration.

**Default credentials:** SASL username is `kafka`. Password is auto-generated via `${{secret(32)}}` on `kafka-1`. Set `KAFKA_SASL_PASSWORD` before deploy to control it. Authentication uses SCRAM-SHA-256 and SCRAM-SHA-512.

**KRaft cluster ID:** Fixed at `MkU3OEVBNTcwNTJENDM2Qk`. Never change this on a formatted volume — the broker compares it against `meta.properties` and refuses to start on mismatch.

**Connecting to the cluster:**

From another Railway service (private, plaintext):

```properties
bootstrap.servers=kafka-1.railway.internal:9092,kafka-2.railway.internal:9092,kafka-3.railway.internal:9092
```

From external clients (TCP proxy, SASL):

```properties
bootstrap.servers=:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=SCRAM-SHA-512
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="kafka" password="";
```

**Connecting via code (Python example):**

```python
from kafka import KafkaProducer, KafkaConsumer

# Producer
producer = KafkaProducer(
    bootstrap_servers=["kafka-1.railway.internal:9092", "kafka-2.railway.internal:9092", "kafka-3.railway.internal:9092"],
    value_serializer=lambda v: v.encode("utf-8")
)
producer.send("test-topic", "Hello from Railway")
producer.flush()

# Consumer
consumer = KafkaConsumer(
    "test-topic",
    bootstrap_servers=["kafka-1.railway.internal:9092", "kafka-2.railway.internal:9092", "kafka-3.railway.internal:9092"],
    auto_offset_reset="earliest",
    value_deserializer=lambda v: v.decode("utf-8")
)
for msg in consumer:
    print(msg.value)
```

**Creating topics:**

```bash
# From any node's shell
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic events --partitions 3 --replication-factor 3
```

**Verifying cluster health:**

```bash
# Check broker API versions
kafka-broker-api-versions.sh --bootstrap-server kafka-1.railway.internal:9092

# List topics
kafka-topics.sh --bootstrap-server kafka-1.railway.internal:9092 --list

# Describe cluster
kafka-metadata.sh --bootstrap-server kafka-1.railway.internal:9092 --describe
```

**Testing failover:**

1. Produce messages to a topic with replication factor 3
2. Stop `kafka-1` (Railway dashboard → remove or scale to 0)
3. Produce and consume messages — should still work (quorum maintained)
4. Restart `kafka-1` — it rejoins and syncs automatically

**Ports:**

| Port | Purpose | Exposure |
| --- | --- | --- |
| 9092 | Internal listener (plaintext) | Private (inter-broker + clients) |
| 9093 | Controller (KRaft) | Private (cluster only) |
| 9094 | External listener (SASL) | Via TCP proxy |
| 8080 | Health check endpoint | Private (Railway) |

**Volume:** One volume per node at `/var/lib/kafka`. KRaft metadata and partition logs persist here.

**Health check:** HTTP endpoint on port 8080 returns 200 when broker is ready.

## Comparison with Alternatives

| Feature | Kafka HA (this template) | Single Kafka | RabbitMQ HA | NATS |
| --- | --- | --- | --- | --- |
| Event streaming | ✅ Native | ✅ Native | ⚠️ Plugin-based | ⚠️ JetStream |
| Fault tolerance | ✅ 3 nodes, RF=3 | ❌ | ✅ 3 nodes | ✅ Cluster mode |
| Setup complexity | ⚠️ 3 services | ✅ 1 service | ⚠️ 3 services | ✅ 1 binary |
| Message replay | ✅ Offset-based | ✅ Offset-based | ⚠️ Limited | ✅ Stream-based |
| Throughput | ✅ Very high | ✅ High | ⚠️ Moderate | ✅ Very high |
| Consumer groups | ✅ Native | ✅ Native | ⚠️ Manual | ✅ Native |
| Cost (self-hosted) | ⚠️ 3 services | ✅ 1 service | ⚠️ 3 services | ✅ Low |
| Memory footprint | ⚠️ 3 JVMs | ⚠️ 1 JVM | ⚠️ 3 Erlang VMs | ✅ Very low |

## Security Considerations

- **SASL password**: Auto-generated via `${{secret(32)}}` on `kafka-1`. Shared across all nodes. Set `KAFKA_SASL_PASSWORD` before deploy to control it.
- **SCRAM authentication**: Uses SCRAM-SHA-256 and SCRAM-SHA-512. Password is never sent in clear text.
- **Private listener**: Plaintext on port 9092 — only accessible within Railway's private network.
- **External listener**: SASL-encrypted on port 9094 — requires TCP proxy for external access.
- **Controller ports**: 9093 is private only — never expose externally.
- **Volume encryption**: Railway volumes are encrypted at rest.
- **No public broker ports**: Only the TCP proxy (if configured) provides external access.

## Why Deploy Kafka 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 Kafka 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.

Three nodes in KRaft mode with replication factor 3, automatic failover, and SASL authentication — no ZooKeeper to manage, no manual cluster configuration. Set the password and deploy.

## Similar templates

- [Celery | Web, Worker and Scheduler as Three Services](https://railway.com/deploy/celery-or-web-work-1) — Web, worker and scheduler wired up: Celery on Redis, outcomes in Postgres.
- [smoothmq](https://railway.com/deploy/AJv-64) — A drop-in replacement for AWS SQS
- [Kafka UI](https://railway.com/deploy/kafka-ui) — Kafbat UI — Open-source web UI to monitor and manage Apache Kafka clusters

Open this page in a browser: https://railway.com/deploy/kafka-ha
