---
title: "Deploy Patroni (PostgreSQL High Availability)"
description: "Patroni PostgreSQL High Availability Cluster"
category: "Storage"
url: https://railway.com/deploy/patroni-1
---

# Deploy Patroni (PostgreSQL High Availability)

Patroni PostgreSQL High Availability Cluster

**[Deploy Patroni (PostgreSQL High Availability) on Railway](https://railway.com/template/patroni-1)**

- **Creator:** utsav-pal's Projects
- **Category:** Storage
- **Total deploys:** 3

## Template content

### etcd2 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/webp/etcd.webp

- **Image:** quay.io/coreos/etcd:v3.5.12

### patroni2 https://devicons.railway.com/i/postgresql.svg

- **Source:** utsav-pal/Patroni-PostgreSQL-High-Availability

### etcd3 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/webp/etcd.webp

- **Image:** quay.io/coreos/etcd:v3.5.12

### haproxy https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/webp/haproxy.webp

- **Source:** utsav-pal/Patroni-PostgreSQL-High-Availability

### etcd1 https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/webp/etcd.webp

- **Image:** quay.io/coreos/etcd:v3.5.12

### patroni1 https://devicons.railway.com/i/postgresql.svg

- **Source:** utsav-pal/Patroni-PostgreSQL-High-Availability

## Documentation

# Deploy and Host Patroni on Railway

Patroni is an open-source tool for managing highly available PostgreSQL clusters. It handles automatic failover, leader election, and streaming replication using a distributed configuration store (etcd), ensuring your database stays online even when nodes fail.

## About Hosting Patroni

Hosting Patroni requires orchestrating multiple components: a distributed configuration store (etcd cluster) for leader election and cluster state, multiple PostgreSQL instances managed by Patroni agents, and a load balancer to route traffic to the correct primary/replica nodes. This template automates the entire setup with 3 etcd nodes for consensus, 2 PostgreSQL/Patroni nodes for data redundancy, and HAProxy for intelligent connection routing. All services communicate securely via Railway's private network.

## Common Use Cases

- **Production databases requiring zero downtime** - automatic failover within 30 seconds
- **Read-heavy applications** - load balance reads across replicas while writes go to primary
- **Multi-region deployments** - maintain database availability during node or zone failures

## Dependencies for Patroni Hosting

- **etcd** - Distributed key-value store for cluster consensus and leader election
- **HAProxy** - Load balancer for routing PostgreSQL connections

### Deployment Dependencies

- [Patroni Documentation](https://patroni.readthedocs.io/)
- [etcd Documentation](https://etcd.io/docs/)
- [PostgreSQL 16](https://www.postgresql.org/docs/16/)
- [HAProxy](https://www.haproxy.org/)

### Implementation Details

Connection endpoints after deployment:

**Primary (read-write)**
`postgresql://postgres:PASSWORD@haproxy.railway.internal:5432/postgres`

**Replica (read-only, load balanced)**
`postgresql://postgres:PASSWORD@haproxy.railway.internal:5433/postgres`

Check cluster status via HAProxy stats dashboard on port 8404.

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

## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [Postgres Backup to Cloudflare R2 (S3-Compatible)](https://railway.com/deploy/postgres-to-r2-backup) — Automated PostgreSQL backups to S3-compatible storage with encryption

Open this page in a browser: https://railway.com/deploy/patroni-1
