Template Request: Patroni (PostgreSQL High Availability)
chandrika
EMPLOYEEOP

13 days ago

Patroni is an open-source template for creating highly available PostgreSQL clusters. It manages automatic failover, leader election, and streaming replication using a distributed configuration store (DCS).

This bounty will be paid out when:

  • A high-quality Patroni Railway template is presented

  • All potential template feedback has been incorporated

  • All requirements are met and tested

Template Requirements

  • Multi-service deployment including Multiple PostgreSQL/Patroni nodes (2-3 nodes), a distributed configuration store (etcd cluster recommended), and a connection pooler/load balancer (HAProxy or PgPool)

  • Volume-backed storage for PostgreSQL data directories to preserve data across redeploys

  • Volume-backed storage for the DCS (etcd) data directory to maintain cluster state

  • Service dependencies should be correctly configured with proper startup order and health checks between the DCS, Patroni/PostgreSQL nodes, and load balancer

  • Environment variables properly configured for Railway domains; internal services should use the private network (.railway.internal) to communicate

  • Load balancer should be configured to route write traffic to the primary node and optionally load-balance read traffic across replicas

  • Template should expose the load balancer endpoint for users to connect their applications to the PostgreSQL cluster

Some Additional Context

This one's a complex deployment, some challenges to think about:

  1. Private Networking: Railway now supports IPv4 private networking which should help simplify etcd configuration (compared to IPv6-only networking)

  2. etcd Cluster Bootstrap: etcd requires all members to successfully start for initial bootstrap. Consider using etcd's discovery service or DNS-based discovery rather than hardcoded IPs, since container addresses can change on redeploy

  3. Startup Ordering: The DCS (etcd) must be healthy before Patroni nodes can initialize. Patroni nodes need proper retry/wait logic or health check dependencies.

Highly encourage contributors to use this thread to chat about any issues you might run into handshake emoji

A few resources to get you started:

$350 Bounty

12 Replies

Am almost done with this one smiley emoji


samgordon

Am almost done with this one

dang was just going to get started sweat_smile emoji looking forward to seeing what you've come up with handshake emoji


I just cannot get ETCD to connect over the private network with IPv6 or 4. I have pretty much everything else working. Railway seems to keep resolving to IPv6.


Finally made a breakthrough with ETCD, fixing another issue and then we're finally done


Is there any way to force my service to use IPv4 or 6? Part of the service uses a linux command on the domain which then resolves to both an IPv6 and a 4 domain, and it breaks Patroni.


This is what the template looks like right now. It's all "running" but Patroni really doesn't live dualstack.

Attachments


The error I'm getting is very silly... but it has to be inside the code.

Attachments


Found the root cause... I'm going to have to modify their startup command but I should be able to do it dynamically with a sed command.


https://railway.com/deploy/patroni

This took me an EXTREMELY long time. But here it is. Have at thee.


brody
EMPLOYEE

8 days ago

Will review.


What's in that PDF? PDFs are disabled on the station.


Google.com.vn


Loading...