Replication, Backup & High Availability
How I keep a relational database alive through crashes and scale its reads: replication modes, failover, backups, and recovery objectives. Interviewers use this area to test whether I can run a database in production, not just query one.
part ofRelational database conceptsoverview, primer and where to startread it →on this pageshowhide
explore
- Replication & Read Scaling20 questions
- Physical vs Logical Replication5 questions
- Synchronous vs Asynchronous Replication5 questions
- Replication Lag5 questions
- Read Replicas & Stale-Read Semantics5 questions
- Failover & Availability15 questions
- Failover and Switchover5 questions
- Split-Brain and Fencing5 questions
- Connection Routing and Proxies5 questions
- Backup & Recovery19 questions
- Point-in-Time Recovery5 questions
- Backup Validation and Restore Testing5 questions
- Measuring RPO and RTO5 questions
- DevOps / SRE Engineerroleanchors this topic
- PostgreSQL DBAroleanchors this topic
- AI & Data Scientistrole
- AI Engineerrole
- Backend Developerrole
- Computer Scienceskill
- Cyber Security Expertrole
- Data Analystrole
- Data Engineerrole
- Forward Deployed Engineerrole
- Full Stack Developerrole
- Java Backend Developerrole
- Kotlin Backend Developerrole
- MLOps Engineerrole
- Machine Learning Engineerrole
- Server-Side Game Developerrole
- Software Architectrole
questions
page 2 of 2Beyond simply returning older rows, what user-visible anomalies appear when an application spreads its reads over a pool of asynchronous replicas, and how do you prevent them?
basics
~20 sDifferent replicas are at different positions, so a user can see time go backwards between two requests, see an effect without its cause, or get inconsistent halves of one page. Prevent it by pinning a session (or a page render) to one replica, and by ejecting replicas whose lag exceeds a threshold.
A recovery can be aimed at a wall-clock timestamp, at a transaction-log position, or at a named marker created earlier. How do you choose between them, and why is a timestamp target less precise than it appears?
basics
~20 sUse a log position when you can identify the exact transaction, a named marker when you planned ahead of a risky change, and a timestamp only to narrow a search. Timestamps rely on commit-time clocks, have coarse practical resolution, and cannot separate transactions committing in the same instant.
After a database is recovered to an earlier point and then opened for writes, its history forks into a new branch. What does that fork mean for the archived transaction logs, for existing replicas, and for future recoveries?
basics
~20 sPromotion starts a new timeline: new log records get a new branch identifier so they do not collide with the abandoned records at the same positions. The old log stays valid for recovering to points on the old branch, replicas that followed the old branch are divergent and must be rebuilt or rewound, and you should take a fresh base backup immediately.
Your database backups are encrypted at rest. What can go wrong at restore time because of that encryption, and how do you manage backup encryption keys so a restore is still possible during a real disaster?
basics
~20 sAn encrypted backup is only as recoverable as its key. Keys stored on the lost host, rotated away, region-pinned, or reachable only through the failed environment make backups unrecoverable. Keep keys in a separate, replicated, escrowed key store, retain old key versions for the backup's lifetime, and prove it by restoring.
How would you design a retention and rotation policy for database backups - which tiers to keep, how long to keep each, and how retention interacts with the window over which you can still recover the database to an arbitrary past moment?
basics
~20 sTier it: dense recent backups plus retained log for a fine-grained recovery window (say 7-14 days), then weekly and monthly copies kept for months or years for compliance and slow-burn corruption. Expire the base backup and its dependent log together, and never expire a backup another one depends on.
A runbook claims a database recovery point objective of 5 minutes and a recovery time objective of 30 minutes. How would you determine whether those numbers are actually true, and what continuous telemetry would tell you when they stop being true?
basics
~20 sMeasure, do not assume. Run timed restore and failover drills to get real recovery times, and monitor replication byte lag, archive backlog, and backup age continuously as live proxies for the recovery point. Alert when either exceeds the promised number, and trend restore times against data growth.
A nightly logical dump (pg_dump or mysqldump) of a busy production database now runs for hours. What consistency guarantee does such a dump actually give, and what side effects does a long-running dump have on the live system?
basics
~20 sA dump is consistent only if it reads inside one long transaction snapshot; otherwise tables are copied at different times. That snapshot blocks cleanup of old row versions, so the database bloats, and the dump also holds locks that block DDL and pollutes the buffer cache.
How would you design the health check that a database proxy uses to decide which backend node is the writable primary, and what makes a naive check dangerous?
basics
~20 sCheck role, not just liveness: open a real connection as a real user and run a query that reports whether the node is writable. TCP-connect checks pass on a demoted or wedged node. Add timeouts, rise/fall thresholds against flapping, a reserved connection slot, and fail closed for writes.
Explain lease-based leadership in an automated relational failover setup such as Patroni backed by etcd: what the leader key and its TTL are, what each agent does on every loop, and how this arrangement stops two primaries from existing.
basics
~20 sLeadership is a short-lived key in a quorum-backed store (etcd) that the primary's agent must keep renewing. If it cannot renew before the TTL expires, it demotes its own database; only after the key expires can another agent create it and promote. One key, one writer.
After a failover has already promoted a replica, the old primary comes back online. Why can you usually not just restart it as a replica, and how does a tool such as pg_rewind get it back into the cluster without a full rebuild?
basics
~20 sThe old primary may have committed transactions the new one never received, so its history diverged at the failover point and it cannot follow the new stream. A rewind finds the divergence point and undoes only the blocks changed after it, copying those from the new primary, which is far cheaper than a full rebuild.
Time-based replication-lag metrics can report zero or null while a replica is genuinely far behind. Why does that happen, and how would you measure lag so the number is trustworthy?
basics
~20 sTime-based lag is derived from the newest change record the replica applied. With no new records — an idle primary, or a dead receiver whose backlog has drained — there is nothing to compare against, so it reads zero or null. Trustworthy measurement combines byte distance from the primary, thread/connection state, and a heartbeat write.
In row-level logical replication, how does the receiving database find the row to change when it receives an UPDATE or DELETE event, and what goes wrong when the source table has no primary key?
basics
~20 sThe change event carries an identifying value set — the row's replica identity, by default its primary key — and the receiver looks the row up by it. With no primary key, either the operation is rejected outright, or the full old row must be logged and matched column-by-column, forcing a scan per event and collapsing throughput.
Instead of pinning a user to the primary for a fixed window after they write, how can an application make a replica read wait until that replica has applied that specific write, using a replication position such as a PostgreSQL LSN or a MySQL GTID?
basics
~20 sAfter committing, read the write's position in the change stream (an LSN or GTID) and carry it with the session or request. Before serving a read, compare it with the replica's applied position: if the replica is behind, wait briefly for it to catch up, or fall back to the primary.
With three or more standbys, how does quorum-based synchronous commit (waiting for any k of n acknowledgements) differ from naming a single synchronous standby, and what does it change for durability and availability?
basics
~20 sWith one named synchronous standby, that standby is a single point of failure for writes and the only node guaranteed to hold every acknowledged commit. Quorum commit waits for any k of n standbys, so any n minus k can be slow or dead without blocking writes, and commit latency follows the k-th fastest rather than one fixed node.
A bad script deleted 200 rows from one table an hour ago, but the rest of the database has taken an hour of valid writes since. How do you get those rows back, and what does that imply about how you size your recovery window?
basics
~20 sPoint-in-time recovery rolls back the whole instance, so do not roll production back. Restore a copy to a scratch instance targeted just before the script, extract the 200 rows logically, and merge them into live data. This costs a full restore, so backup cadence, archive retention and spare restore capacity define what is feasible.
How do you decide what recovery point and recovery time objectives a given database should have, when every tightening of those numbers costs money and adds write latency or operational complexity? Walk through how you would tier a portfolio of databases.
basics
~20 sDerive the numbers from business impact, not engineering taste: what a minute of downtime and a minute of lost data cost, and whether the data is reconstructible elsewhere. Then define three or four standard tiers with fixed architectures and prices, and make owners choose a tier and fund it.
You own a 4 TB relational OLTP database with a two-hour nightly low-traffic window. Design its backup strategy in terms of backup types, and explain the tradeoffs behind your choices.
basics
~20 sPhysical backups are the base: a weekly full plus daily block-level incrementals, because a 4 TB logical dump will not fit a two-hour window. Add a periodic logical dump for portability and object-level recovery, keep copies off-site, and size retention around how far back you must be able to go.
Where should the database routing and pooling layer live — inside the application's driver, as a sidecar next to each application instance, or as a centralized proxy tier — and how do you keep it from becoming the system's single point of failure?
basics
~20 sDriver-based routing has no extra hop but is per-language and cannot drain. A sidecar limits blast radius but gives no global connection cap. A central tier gives one control point and true pooling but needs redundancy plus its own front-end routing. Most large systems combine a sidecar pooler with a redundant central router.
You must run a highly available relational database across two data centres with automatic failover. How do you place voting members so that losing one site does not either strand the cluster read-only or allow two primaries, and what tradeoff would you accept?
basics
~20 sTwo sites cannot give symmetric automatic failover: whichever side holds the majority survives, the other cannot promote. Either add a third independent site or region for the tiebreaking vote, or accept an asymmetric design where one site is primary-capable and the other requires a manual, fenced promotion.
Would you enable fully automatic failover for a production OLTP relational database, and how would you set detection thresholds, promotion criteria, and failback policy? Justify the tradeoffs.
basics
~20 sUsually yes, because humans are slower than the outage budget, but only with quorum-gated promotion, confirmed fencing, a maximum-lag rule, hysteresis against flapping, and automated rejoin. Failback should be a separate, scheduled switchover, never automatic.
How would you choose replication-lag alerting thresholds for a fleet of read replicas, and what should happen automatically when a replica exceeds them?
basics
~20 sDerive thresholds from what each replica is for: a staleness budget in seconds for read traffic, a recovery-point budget for failover candidates, and a hard byte threshold from log retention. Alert on sustained growth, not single spikes. Above the staleness budget, drain the replica from the read pool automatically, with hysteresis before re-adding.
How do you decide whether a system genuinely needs zero-data-loss replication given its latency and availability costs, and what would you configure differently for a payments ledger versus a clickstream ingestion pipeline?
basics
~20 sDecide from the cost of losing the last second of writes and whether they can be reconstructed upstream. A ledger cannot reconstruct them, so it pays a same-region synchronous quorum plus asynchronous cross-region copies. Clickstream data is replayable from the producer, so asynchronous replication and relaxed local commit are the right trade.
What is a deliberately delayed replica, one configured to stay (say) one hour behind the primary, and which failure does it protect against that a normal standby and a nightly backup do not?
basics
~20 sA delayed replica receives the change stream immediately but deliberately withholds applying it for a fixed interval, so it holds a live copy of the database as it was an hour ago. That gives you a fast rewind after a destructive human or application error, which normal standbys replicate instantly.
How does row-level logical replication make a near-zero-downtime major-version upgrade of a relational database possible, and why can block/WAL-level physical replication not be used for the same purpose?
basics
~20 sLogical replication ships decoded row changes, which a target on a newer major version can apply as ordinary writes — so you build the new-version database alongside, let it catch up, and cut over in seconds. Physical replication replays version-specific page-level records, so both nodes must run the identical major version.
showing 31–54 of 54