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
- Audit — inventory current infrastructure, load, budget.
- Calculation — determine target RTO/RPO together with you.
- Design — select architecture (Patroni + etcd, pgBackRest, HAProxy).
- Implementation — deploy, configure, test failover.
- Testing — simulate failures, measure actual RTO/RPO.
- 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.







