Template Request: Patroni (PostgreSQL High Availability)
chandrika
EMPLOYEEOP

4 months 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:

Closed$350 Bounty

13 Replies

4 months ago

Am almost done with this one smiley emoji


samgordon

Am almost done with this one

4 months ago

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


4 months ago

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.


4 months ago

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


4 months ago

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.


4 months ago

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

Attachments


4 months ago

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

Attachments


4 months ago

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.


4 months ago

https://railway.com/deploy/patroni

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


4 months ago

Will review.


3 months ago

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


aditya41150
FREE

2 months ago

I am working on this


2 months ago

Going to close this out as we will be developing something for this internally.


Status changed to Closed brody about 2 months ago


Loading...