Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

You run a payments database on PostgreSQL with one primary and two standbys in different availability zones of one region. Decide on synchronous settings and explain the latency and availability trade-offs.

For payments we want no acknowledged commit to be lost, so we run synchronous replication with a quorum of one out of the two standbys: synchronous_standby_names = 'ANY 1 (s1, s2)' with synchronous_commit = on. Cross-zone round trips add about 1 to 2 ms per commit, which payments can afford; if both standbys fail, writes stall, and we accept that deliberately. Less critical writes can opt out with SET LOCAL synchronous_commit = local, and Patroni must only ever promote a standby that was synchronous.

Why this question is asked

This is a design question with a clear business driver. Payments are the kind of data where losing a confirmed transaction is worse than a short outage, because the customer has been charged, the merchant has been told yes, and the money now has no record. At the same time, every millisecond added to a commit is paid on millions of requests. Interviewers want to see that we can turn that into concrete settings and explain what happens in each failure. In this answer, we will set the goal, choose the synchronous settings, size the latency, walk through the failure cases, carve out exceptions for less critical writes and connect it all to the failover manager.

1Start From the Goal: RPO Near Zero

RPO, the recovery point objective, is how much data we can afford to lose, measured in time. For payments the honest answer is close to zero: once our API has told a caller a payment is recorded, that record must survive the loss of any single server or zone. RTO, the recovery time objective, is how long we may be down. For payments, a minute or two of failover is usually acceptable, while lost records are not.

That ordering, durability first, availability second, decides the design. Asynchronous replication cannot give RPO zero, because the standby trails the primary. So we need synchronous replication, and the remaining question is how to make it as cheap and as available as possible.

2Choosing the Synchronous Settings

We have two standbys in two other zones. If we wrote FIRST 1 (s1, s2), the primary would always wait for s1 and use s2 only if s1 disappeared. The quorum form is better here: ANY 1 (s1, s2) waits for whichever standby confirms first. Each commit is guaranteed to exist in at least two zones, and a slow standby does not slow down every write.

For synchronous_commit we choose on, which means the confirming standby has flushed the WAL to its own disk. remote_write would be slightly faster but only guarantees the standby's operating system received it, so a simultaneous power loss in two zones could lose data. remote_apply is only needed if we read our own writes from the standbys, which a payments service normally does not.

Java
# postgresql.conf on the primary (Patroni manages this for us, see below)
synchronous_standby_names = 'ANY 1 (s1, s2)'
synchronous_commit = on
-- check it
SELECT application_name, sync_state, replay_lag FROM pg_stat_replication;
-- s1 | quorum | 00:00:00.0011
-- s2 | quorum | 00:00:00.0016

3What It Costs in Latency

Availability zones in one region are typically a few kilometres apart with round trips around 0.5 to 2 ms. A synchronous commit adds one round trip plus the standby's disk flush, so a commit that took 1.5 ms locally takes about 3 ms. For a payment request that already spends 50 to 150 ms in fraud checks, card networks and our own code, this is noise.

Throughput suffers less than we might fear, because PostgreSQL groups commits: while one commit waits for the standby, others queue behind it and are confirmed together with the same WAL flush. The real warning is cross-region. If someone later puts a synchronous standby in another region, each commit adds 30 to 100 ms, which would hurt both latency and throughput badly. That decision deserves its own discussion.

4Walking Through the Failure Cases

The value of a design shows when something breaks, so let us walk through it.

What happens when parts fail
FailureWritesData loss
One standby downContinue, the other confirmsNone
Both standbys downStall until one returnsNone
Primary downPatroni promotes a synchronous standbyNone for acknowledged commits
Primary zone lostSame as primary downNone
Two zones lostStall or manual decisionNone if a confirming standby survives
We trade write availability in rare double failures for never losing an acknowledged payment.

The second row is the deliberate choice. If both standbys are unreachable, PostgreSQL keeps waiting rather than confirming a payment that exists in only one place. We could relax this, but for payments we would rather return errors for a few minutes than accept money we might lose. We alert loudly long before this happens, for example when only one standby is connected.

5Letting Less Critical Writes Skip the Wait

Not every write in a payments database is a payment. Audit of page views, rate-limit counters or cached exchange rates can be rebuilt or lost without harm. For those, the transaction can opt out of the standby wait.

SQL
BEGIN;
SET LOCAL synchronous_commit = local; -- only this transaction, flush locally and return
INSERT INTO api_request_log (path, status) VALUES ('/v1/rates', 200);
COMMIT; -- does not wait for s1 or s2

In Spring, the simplest way is a small repository method that runs this statement inside its own transaction, or a separate database role with ALTER ROLE logger SET synchronous_commit = local. The default for everything else stays on, so a developer who forgets about it gets the safe behaviour.

6Making Failover Respect the Guarantee

Synchronous replication only protects us if failover promotes a standby that actually has every acknowledged commit. If an operator or a script promoted a lagging asynchronous replica, all the care above would be wasted. Patroni, the usual failover manager for PostgreSQL, handles this with synchronous_mode: Patroni itself writes synchronous_standby_names and only promotes a member it knows was synchronous. Recent Patroni versions also support a quorum mode that matches ANY 1 (check your version). With synchronous_mode_strict, Patroni refuses to fall back to asynchronous when no standby is available, which matches our choice to stall rather than risk loss.

7Follow-up questions

Why not set synchronous_commit = remote_apply for safety?

remote_apply waits until the standby has replayed the change, which adds replay time to every commit. It only adds value if we read from standbys and need to see our own writes there. For durability, on is enough: the WAL is on the standby's disk and will be replayed at promotion.

Would you ever accept asynchronous replication for payments?

Only with a reconciliation process that can rebuild lost records from another source, for example from the payment provider's settlement files, and only when the latency of synchronous commit is unacceptable, which is the cross-region case. Within one region, synchronous is cheap enough that there is no reason to accept the risk.

How many standbys would you run?

Two in different zones is the minimum for ANY 1 to tolerate one failure without stalling. Some teams add a third, asynchronous replica for reporting so that heavy queries never affect the synchronous standbys.

8Conclusion

In this answer, we saw that payments need RPO near zero, so we chose synchronous replication with the quorum form ANY 1 (s1, s2) and synchronous_commit = on. The cost is about 1 to 2 ms per commit across zones, writes survive one standby failure and stall only when both are gone, a choice made on purpose. Low-value writes can opt out with SET LOCAL, and Patroni's synchronous mode makes sure failover only promotes a standby that holds every acknowledged commit.

What to say in the interviewAbout 90 seconds aloud

Open with

For payments I would start from the targets: losing an acknowledged payment is unacceptable, while a minute or two of failover is fine. So RPO near zero, and that means synchronous replication.

Then, if they want more

With two standbys in different zones I would use the quorum form, synchronous_standby_names = 'ANY 1 (s1, s2)', so each commit waits for whichever standby flushes first, with synchronous_commit = on. That guarantees every acknowledged commit is on disk in two zones.

The latency cost is one cross-zone round trip plus a flush, about 1 to 2 ms, which is small next to the rest of a payment request, and group commit keeps throughput reasonable. I would not put a synchronous standby in another region, because that is tens of milliseconds per commit.

For failures: one standby down, writes continue; both down, writes stall, and I would say that is deliberate, we prefer errors to accepting money we might lose, with alerts well before that point. For low-value writes like request logs, the code can use SET LOCAL synchronous_commit = local so they skip the wait, while the default stays safe.

Finally, I would run Patroni in synchronous mode, ideally strict, so it manages the setting and only ever promotes a standby that was synchronous, otherwise the whole guarantee is lost at failover.

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.
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 "You run a payments database on PostgreSQL with one primary and two standbys in different...": https://scrivio-interview-library.netlify.app/databases/replication-and-ha/2aba82935a/