PostgreSQL RTO and RPO: Setting Up High Availability with Patroni

When a service goes down, every minute of downtime translates into losses, and manual recovery drags on for hours. We configure PostgreSQL high availability with Patroni and pgBackRest so that automatic failover and regular WAL archiving minimize RTO and RPO. Our team delivers the project turnkey—from auditing your current infrastructure to implementation and ongoing support—ensuring reliable operation of your services.

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1342
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1304
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1047
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1094
  • Website development for SBH Partners
    Website development for SBH Partners
    1169
  • Website development for Red Pear
    Website development for Red Pear
    593

Note: when a service is down for an hour and recovery takes a day, that's a catastrophe. A payment gateway processing 10,000 transactions per minute, idle for 30 minutes, loses not only revenue but also customer trust. The average cost of an hour of downtime for e-commerce can be substantial. RTO (Recovery Time Objective) and RPO (Recovery Point Objective) are the parameters that determine how fast you get back on your feet after a failure and how much data you lose. We configure PostgreSQL infrastructure so that these metrics meet business requirements: from cold standby to multi-region active-active. Our engineers have over 10 years of PostgreSQL experience and more than 50 successful projects implementing fault-tolerant clusters.

What Problems We Solve

  • Undefined SLA. Without formal RTO/RPO, you cannot guarantee recovery time to clients. Contractual penalties pile up, and reputation suffers.
  • Manual recovery. On failure, an administrator manually promotes a replica — this means hours of downtime. Automatic failover reduces RTO to seconds.
  • Data loss. Infrequent backups (once a day) mean RPO = 24 hours. On failure, you lose a day's transactions. WAL archiving every 5 minutes reduces RPO to 5 minutes.
  • Excessive costs. Chasing zero RTO without business analysis leads to overspending. We help find the cost/reliability balance.

How to Determine RTO and RPO for Your Business

The first step is estimating the cost of downtime. We use a simple calculator:

class RtoCalculator:
    def calculate_downtime_cost(self, hourly_revenue, churn_per_hour, penalty, clv, customers):
        costs = {
            'lost_revenue': hourly_revenue,
            'churn': (churn_per_hour/100)*customers*clv,
            'sla_penalties': penalty,
            'labor': 500
        }
        total = sum(costs.values())
        if total > 100000:
            return '< 5 min (active-active)'
        elif total > 10000:
            return '< 15 min (hot standby)'
        else:
            return '< 1 h (warm standby)'
RTO RPO Architecture Cost Level
24h 24h Daily backup to S3 Low
4h 1h Hourly backup + cold standby Medium
1h 15min Streaming replication + manual failover Medium+
15min 5min Patroni + pgBackRest + WAL archiving High
5min 0 Multi-region active-active Very High

Why Patroni Is the Best Choice for PostgreSQL

Patroni with etcd provides failover in 30 seconds — 10 times faster than manual recovery. It manages configuration, automatically switches traffic, and loses no data when synchronous replication is properly configured. It is the standard for High Availability in PostgreSQL.

How We Do It

Case study: A corporate CRM on PostgreSQL 15. Required RTO < 30 minutes and RPO < 5 minutes. We deployed Patroni on three nodes, pgBackRest for WAL archiving to S3, and HAProxy for routing. After a test failure (kill primary), failover took 18 seconds, data loss was 0 (synchronous replication). Recovery documentation was handed over to the team.

PostgreSQL and pgBackRest configuration for RPO = 5 minutes
# postgresql.conf
wal_level = replica
archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p'
checkpoint_timeout = 5min
max_wal_senders = 10
wal_keep_size = 1GB

# pgbackrest.conf
[global]
repo1-type=s3
repo1-s3-bucket=myapp-wal-archive
repo1-retention-full=4
repo1-retention-diff=14

[main]
pg1-path=/var/lib/postgresql/data

Patroni: Automatic Failover (RTO < 30 sec)

---
# patroni.yml
scope: postgres-cluster
name: pg-node-1
restapi:
  listen: 0.0.0.0:8008
etcd3:
  hosts: etcd1:2379,etcd2:2379,etcd3:2379
bootstrap:
  dcs:
    ttl: 30
    loop_wait: 10
    max_lag_on_failover: 1048576
postgresql:
  parameters:
    wal_level: replica
    hot_standby: on
    archive_command: 'pgbackrest --stanza=main archive-push %p'
---

HAProxy: Role-Aware Routing

frontend postgres_write
    bind *:5432
    default_backend postgres_primary

backend postgres_primary
    option httpchk GET /master
    server pg-node-1 check port 8008

frontend postgres_read
    bind *:5433
    default_backend postgres_replicas

backend postgres_replicas
    balance roundrobin
    option httpchk GET /replica
    server pg-node-1 check port 8008

How to Monitor RTO/RPO

Monitoring is key to SLA compliance. The table below lists metrics to track:

Metric Tool Alert Threshold
Replica lag (bytes) pg_stat_replication > 50 MB
Time since last successful backup pgBackRest info > 1 hour
WAL file size pg_ls_waldir > 10 GB
Primary availability (check) HAProxy stats < 100%
Patroni API response time curl /health > 5 sec

We set up Prometheus + Alertmanager. When RPO is breached, the on-call team gets notified. This allows reaction before the failure impacts business.

What to Do When RPO Is Breached

Typical mistakes in designing fault tolerance:

  • Lack of failover tests. We perform chaos engineering: simulate node, network, and disk failures. Only then can real RTO/RPO be validated.
  • Ignoring replication lag. In synchronous mode, latency between data centers must not exceed 10 ms.
  • Incorrect backup rotation. pgBackRest with retention (full/diff) ensures old backups are not overwritten. Point-in-time recovery is supported.

We create an incident runbook for on-call staff: steps to take on failure, promotion procedure, vendor contacts.

Process

  1. Audit — inventory current infrastructure, load, budget.
  2. Calculation — determine target RTO/RPO together with you.
  3. Design — select architecture (Patroni + etcd, pgBackRest, HAProxy).
  4. Implementation — deploy, configure, test failover.
  5. Testing — simulate failures, measure actual RTO/RPO.
  6. Documentation and training — incident runbook, on-call training.

What Is Included in Turnkey Setup

  • Configuration of Patroni with etcd/Consul for automatic failover
  • pgBackRest — full/differential backup, WAL archiving to S3 or local storage
  • HAProxy — intelligent routing (write/read split)
  • Monitoring — Prometheus exporter for lag, alerts on RPO breaches
  • Documentation — recovery plan, configs, checklists
  • Training — 2-hour workshop for your team

Timeframes and Guarantees

Turnkey setup for a typical 3-node cluster takes 3–5 business days. The result: target RTO/RPO achieved, confirmed by load testing. We are certified engineers with over 10 years of PostgreSQL experience. We guarantee SLA on recovery time.

Savings from automated failover can be significant per month by preventing downtime. Contact us for a calculation of your case. Request a consultation — we will select the optimal architecture for your budget and requirements.