Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Your company runs 60 PostgreSQL clusters on cloud VMs, each tuned by hand. Design the standard for storage, WAL and backup layout so that any cluster can be restored to a point in time and the on-call team understands all of them the same way.

We would define one standard that every cluster follows: pg_wal on its own volume or at least monitored separately, with alerts on WAL growth from inactive replication slots or failing archiving; continuous WAL archiving plus scheduled base backups with pgBackRest or Barman, with retention and encryption set per data class; automated restore tests that measure real recovery time against RTO and RPO; configuration generated from version-controlled templates per instance size; and the same dashboards everywhere.

Why this question is asked

Sixty hand-tuned clusters means sixty slightly different ways to fail. One has WAL on the root disk, another archives to a bucket nobody checks, a third has never been restored. Interviewers ask this design question to see whether we can turn tribal knowledge into a standard that makes point-in-time recovery reliable and on-call predictable. In this answer, we will look at how WAL storage fails, design the backup and archiving layer, make restore testing automatic, generate configuration from templates, and define a common set of dashboards.

1A Quick Recap: What Point-in-Time Recovery Needs

Point-in-time recovery (PITR) means restoring a database to any chosen moment, for example 14:03, just before a bad deploy dropped a table. It needs two things: a base backup, which is a full physical copy of the data directory taken at some point, and every WAL segment written since that backup. Restoring the base backup and replaying the archived WAL up to 14:03 rebuilds the database as it was at that moment.

So the whole standard rests on one promise: every WAL segment reaches safe storage, and we can prove we can replay it. RPO, the recovery point objective, is how much data we may lose, which depends on how quickly WAL leaves the server. RTO, the recovery time objective, is how long a restore may take.

2Storage Layout and WAL Monitoring

pg_wal goes on its own volume, or, if the cloud setup makes that awkward, gets its own disk usage alerts. The reason is that pg_wal grows for reasons unrelated to data size. If archiving fails, PostgreSQL keeps every segment until it succeeds. If a replication slot is inactive, for example a CDC consumer that was switched off, the slot keeps all WAL since that consumer's position. Either way pg_wal can fill the disk in hours, and when it is full the server stops.

With a separate volume, a full pg_wal does not also fill the data volume, and a fast-growing pg_wal is obvious on a graph. We alert on three things: pg_wal size, archiver failures, and the amount of WAL retained per replication slot.

Java
-- WAL each slot is holding back
SELECT slot_name, active,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained
FROM pg_replication_slots;
-- debezium_orders | f | 212 GB -> inactive slot, page someone
-- is archiving working?
SELECT archived_count, failed_count, last_failed_wal, last_failed_time
FROM pg_stat_archiver;

We also set max_slot_wal_keep_size, so one abandoned slot cannot fill the disk; past that limit the slot is invalidated instead. That is a deliberate choice: losing a CDC consumer's position is better than losing the database.

3Backups: Archiving Plus Base Backups

Every cluster uses the same tool, pgBackRest or Barman, so the commands and runbooks are identical. WAL archiving runs continuously through the tool's archive command, which compresses, encrypts and pushes each segment to object storage in another region. Base backups run on a schedule, for example a full backup weekly and incremental or differential backups daily, so restores do not have to replay a week of WAL.

Retention and encryption are defined per data class, not per cluster. Customer payment data might need 35 days of PITR, encryption with keys managed per environment and a copy in a second region; an internal analytics cache might need 7 days. Each cluster declares its class in its template, and the backup configuration follows from it.

Step throughBackup layout for every cluster
  1. Object storage, second regionencrypted, retention by data class
  2. pgBackRest or Barman repositoryfull weekly, incremental daily
  3. Continuous WAL archivingevery 16 MB segment, compressed
  4. pg_wal on its own volumealerts on size, archiver and slots
  5. Data directory volumesized from the instance class template

5 layers, from the top down. Step through them one at a time.

4Restore Tests: The Only Real Proof

A backup that has never been restored is a hope, not a backup. So every cluster gets an automated restore drill: a job provisions a scratch host, restores the latest base backup, replays WAL to a random recent timestamp, starts PostgreSQL, runs a few sanity queries, and then destroys the host.

The job records the actual recovery time and the gap between the target time and the newest data it could recover. These numbers are compared with each cluster's RTO and RPO. If a 2 TB cluster takes 5 hours to restore against a 2-hour RTO, we learn that on a Tuesday afternoon, not during an outage, and we fix it with more frequent base backups, parallel restore or a standby.

Step throughAutomated restore drill
  1. Provision a scratch host
  2. Restore latest base backuppgBackRest restore
  3. Replay archived WAL to a random recent timerecovery_target_time
  4. Start and run sanity queriesrow counts, latest timestamps
  5. Within RTO and RPO?
    YesRecord success, destroy hostNoOpen an incident ticket for the cluster

5 steps in order. Play them, or step through them one at a time.

5Configuration From Templates

Hand tuning is replaced by templates in version control. An instance class, for example small (4 vCPU, 16 GB), medium or large, determines shared_buffers, work_mem, max_wal_size, checkpoint settings, autovacuum workers and volume sizes. A cluster's file says only its class, its data class and any exceptions, and the full configuration is generated and applied by the deployment tooling.

Exceptions are allowed, but each one is written next to the setting with the reason and an owner, for example a higher max_wal_size because of a nightly bulk load. When the on-call engineer looks at any cluster, the differences from the standard are visible in one place.

6Standard Dashboards for On-Call

Every cluster exports the same metrics and appears on the same dashboards, so the on-call team reads all sixty the same way. The core panels are checkpoint frequency (timed versus requested), WAL generation rate and pg_wal size, replication lag per standby and slot, table and index bloat estimates, transaction ID wraparound age per database, and connections by state compared with max_connections. Backup age and the result of the last restore drill sit on the same page.

7Follow-up questions

How often would you run restore drills?

Automated drills for every cluster at least weekly, and daily for the most critical data classes, because they are cheap once automated and they catch silent archiving failures quickly. In addition, a human-led drill per quarter where on-call engineers follow the runbook end to end, including promoting a restored copy, so the procedure is practised by people, not only scripts.

When would you move these clusters to a managed service instead?

When the team spends most of its time on undifferentiated work such as patching, backups and failover, and the managed service meets our needs: the extensions we use, the PostgreSQL versions we need, acceptable PITR windows, and an acceptable cost at our size. We would weigh lost control, for example over superuser access and some settings, against the hours saved. A managed service still needs our monitoring and our restore tests.

Why not rely on replicas instead of backups?

A replica copies mistakes instantly: a dropped table is dropped on the replica a second later. Replicas protect against hardware failure; backups with PITR protect against human and software errors.

8Conclusion

In this answer, we designed a standard for 60 PostgreSQL clusters. pg_wal gets its own volume or monitoring, with alerts on inactive slots and archiving failures. Continuous WAL archiving and scheduled base backups with pgBackRest or Barman provide point-in-time recovery, with retention and encryption set per data class. Automated restore drills measure real recovery time against RTO and RPO. Configuration comes from version-controlled templates per instance class with documented exceptions, and standard dashboards let on-call read every cluster the same way.

What to say in the interviewAbout 70 seconds aloud

Open with

I would make every cluster follow one standard so restores are reliable and on-call sees the same thing everywhere. First, storage: pg_wal on a separate volume, or at least monitored separately, with alerts on pg_wal size, on archive failures from pg_stat_archiver, and on WAL retained by inactive replication slots, plus max_slot_wal_keep_size as a safety limit.

Then, if they want more

Second, backups: one tool for all clusters, pgBackRest or Barman, with continuous WAL archiving to encrypted object storage in another region and scheduled full and incremental base backups. Retention and encryption are defined per data class, not per cluster.

Third, and most important, automated restore drills: a job restores each cluster to a scratch host at a random recent point in time, runs sanity checks, and records the real recovery time and data gap against the RTO and RPO.

Fourth, configuration comes from version-controlled templates by instance class, and any exception is documented next to the setting with a reason and an owner. Finally, standard dashboards for checkpoint frequency, WAL rate, replication lag, bloat, wraparound age, connections, backup age and the last drill result.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
PostgreSQL documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your company runs 60 PostgreSQL clusters on cloud VMs, each tuned by hand. Design the...": https://scrivio-interview-library.netlify.app/databases/postgresql/ea16b5111f/