skip to content

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 pageshow

questions

page 1 of 2

A nightly database backup job has reported success every night for six months. What does that success signal actually prove, and what would you do before trusting those backups in a real outage?

level: juniorimportance: must knowfreq 62%

answer

  1. green job = producer, not artifact
  2. untested backup = Schrodinger's backup
  3. restore from the off-site copy
  4. start the engine, then assert on data
  5. time the drill; that is your real recovery time

basics

~20 s

It proves the job ran and wrote bytes somewhere. It does not prove the backup is complete, readable, or restorable. The only proof is restoring it onto a separate instance, starting the database, and querying the data.

solid answer

~50 s

A green backup job is a statement about the **producer**, not the **artifact**. It means a process exited zero. It does not mean the file is complete, that it is uncorrupted, that the encryption key still exists, that the restore procedure still works, or that a restore finishes inside the time budget. Before trusting it I run a restore drill: fetch the backup from the same place a real recovery would fetch it (the off-site copy, not a local scratch directory), restore onto a clean isolated instance, start the database, and run application-level checks - row counts on the biggest tables, the newest timestamp in an append-only table, object counts versus production, and a couple of known business queries. The drill has to be timed and written down: how long it took, how much recent data was missing, and every manual step someone had to improvise. Those numbers are the real recovery capability; the runbook's numbers are only a claim.

go deeper

for a junior

Say plainly that a successful job only proves the job ran, and that the real test is restoring the backup onto a separate machine and checking the data is there and current.

for a middle

Add the mechanics: restore from the off-site copy, start the engine, run row-count and freshness assertions, and time the whole thing. Name concrete silent-failure modes such as backing up a stalled replica or a missing schema.

for a senior

Frame it as evidence generation: cheap verification on every backup, automated restore-and-assert on a schedule, periodic full game days with a rotating operator, and trended timings that feed the recovery-time objective.

for a principal

Talk about it as an organisational control - restorability as a measured, reported property of every data store, with ownership, sampling strategy across a fleet, and an escalation path when a cluster's last successful proof-of-restore ages out.

## The job versus the artifact A backup pipeline has two separable things: the **process** that produces a backup, and the **artifact** that must survive to be used. Monitoring almost always watches the process - exit code, log line, scheduler status - because that is trivially instrumentable. The artifact is what you actually need, and nothing about a zero exit code speaks to it. Real-world failures that coexist happily with six months of green jobs: - The dump ran against a replica that stopped replicating in March, so every backup since then is a snapshot of stale data. - Only one schema was included because the tool's include-list was never updated when a new schema was added. - The archive is written to a volume that silently filled; the tool truncated and still exited zero (or the exit code was swallowed by a shell pipeline). - Bit rot or a bad disk corrupted blocks in the middle of the archive; nothing reads those blocks until a restore does. - The backups are encrypted with a key that lives only on the database host being backed up - the host you just lost. - The restore works but takes 14 hours, and the business promised 1 hour. - Large objects, sequences, or extensions were not captured, so the restored database will not run the application. None of these are exotic. Each is a routine post-incident finding. ## What a restore drill is A restore drill is an end-to-end rehearsal that produces evidence. The essential properties: 1. **Use the real source.** Pull from the off-site or object-store copy through the same credentials and network path a disaster recovery would use. Restoring from a file that is still sitting on the primary proves nothing about the copy that survives the primary. 2. **Restore to an isolated target.** A scratch instance, container, or throwaway cloud host - never anything sharing storage, credentials, or a connection string with production. A restore drill that can overwrite production is a bigger risk than no drill. 3. **Actually start the database.** Recovering files is not recovery. The engine must open the data, replay whatever log it needs, and reach a consistent, writable state. 4. **Validate at the application layer.** The engine starting is a low bar. Check that the newest row in an append-only table is as recent as the backup claims, compare table and index counts against production, verify a few referential-integrity spots, and run two or three queries the application actually issues. 5. **Time everything and record it.** Fetch time, restore time, replay time, validation time, plus every step a human had to figure out live. The gap between the wall-clock total and the target recovery time is your risk. 6. **Have a non-expert drive it.** If only one engineer can execute the runbook, the runbook fails whenever that engineer is asleep or gone. Rotating the operator flushes out undocumented steps faster than any review. ## Cadence and automation An annual drill is theatre. The practical pattern is layered: cheap automated verification on every backup (checksum/manifest validation), an automated restore of at least one cluster per day or per week into a scratch environment with automated data assertions, and a full human-driven game day - including failover, DNS, credentials, and application startup - once or twice a year. Anything you can automate should run unattended and page when it fails, because a drill that requires a person to remember it eventually stops happening. ## What to answer when asked The answer an interviewer wants is short: job success measures the job, not the backup; only a completed restore with data-level assertions and a stopwatch validates a backup; run it regularly, automatically, from the off-site copy, with someone other than the author driving. Then note the second-order point - the drill also produces the only honest measurement of how long recovery takes, which is what the business actually buys.

  • How often would you run restore drills, and does the cadence depend on the system?
    Cheap checks (checksum and manifest verification) run on every backup; an automated restore-and-assert runs at least weekly, and daily for tier-1 systems. A full human game day - failover, credentials, DNS, application startup - happens once or twice a year and after any material change to the backup tooling, storage layout, or schema footprint. Lower-tier systems can drop to quarterly automated restores, but never to zero.
  • What evidence should each drill produce, and where does it go?
    A dated record with: which backup was used, where it was fetched from, wall-clock time for fetch/restore/replay/validation, the data-freshness gap measured against the failure moment, the assertions run and their results, and every manual or undocumented step. Store it where auditors and on-call engineers both look, and trend the timings - a restore that has crept from 20 minutes to 3 hours is a recovery-objective breach nobody declared.

A fire extinguisher with a current inspection sticker. The sticker says someone walked past it, not that it will spray anything when the kitchen is on fire.

saying these in an interview costs you the question

  • Treating a successful backup job or a monitoring green tick as proof the backup is restorable.
  • Validating by checking that the file exists and is roughly the expected size.
  • Doing the drill by restoring the local copy on the database host, which never exercises the off-site path or the credentials a real disaster needs.
  • Restoring but never starting the engine or querying the data, so a structurally broken or stale dataset passes.
  • Not timing the drill, so the organisation never learns that its recovery-time promise is fiction.

context

open as a page

Define Recovery Point Objective (RPO) and Recovery Time Objective (RTO) for a database, and give a concrete example of a system where the two numbers are very different.

level: juniorimportance: must knowfreq 74%

basics

~20 s

RPO is how much recent data you can afford to lose, measured in time before the failure. RTO is how long the system may stay unavailable before it is serving again. RPO is about data loss; RTO is about downtime.

open as a page

Explain the difference between full, incremental, and differential backups of a relational database, and how each choice affects the backup window, storage cost, and restore time.

level: juniorimportance: must knowfreq 58%

basics

~20 s

A full backup copies everything. An incremental copies only what changed since the previous backup of any type. A differential copies everything changed since the last full. Incrementals are smallest to take but slowest to restore, because the whole chain must be replayed.

open as a page

In a replicated database cluster with one primary and several standbys, what is split-brain, how does it arise during a failover, and what damage does it do to the data?

level: juniorimportance: must knowfreq 55%

basics

~20 s

Split-brain is two nodes both believing they are primary and accepting writes, usually after a network partition hid a still-running primary. Their histories diverge, and reconciling them means discarding writes the application already saw committed.

open as a page

What is the difference between a planned switchover and an unplanned failover in a primary/replica relational database setup, and how does each affect the risk of losing committed data?

level: juniorimportance: must knowfreq 58%

basics

~20 s

A switchover is a controlled role swap: writes are stopped, the replica catches up fully, then roles change with no data loss and the old primary can rejoin as a replica. A failover is reactive after a crash, so unreplicated commits can be lost.

open as a page

What is replication lag between a primary database and its replica, and in what two units is it normally measured?

level: juniorimportance: must knowfreq 66%

basics

~20 s

Replication lag is how far a replica trails its primary. It is measured in bytes — how much of the primary's change log the replica has not consumed yet — and in seconds — how old the newest change the replica has applied is.

open as a page

What is a read replica in a relational database, and how do you decide which of your application's reads are safe to send to one instead of to the primary?

level: juniorimportance: must knowfreq 68%

basics

~20 s

A read replica is a read-only copy that continuously applies the primary's change stream, so it trails the primary slightly. Send it reads that tolerate slightly old data (listings, reports, exports). Keep writes, and any read that must reflect a just-made write, on the primary.

open as a page

What is the difference between synchronous and asynchronous replication in a relational database, and what does each mean for data loss if the primary dies suddenly?

level: juniorimportance: must knowfreq 70%

basics

~20 s

Asynchronous: the primary confirms the commit as soon as it is durable locally and ships the change afterwards, so a sudden primary loss can lose recently committed transactions. Synchronous: the primary waits for a standby to acknowledge before confirming, so no acknowledged transaction is lost, at the cost of extra latency on every commit.

open as a page

What is point-in-time recovery in a relational database, and what two things must you have been collecting beforehand for it to be possible at all?

level: middleimportance: must knowfreq 58%

basics

~20 s

Point-in-time recovery restores a database to any chosen moment in the past. It needs a base backup of the data files plus an unbroken chain of archived transaction-log records covering everything from the start of that backup onward. You restore the backup, then replay the log and stop at the chosen point.

open as a page

How do the replication commit mode (asynchronous versus synchronous) and the frequency with which write-ahead log segments are shipped off the primary determine the recovery point objective you can honestly promise? What do you pay for a tighter one?

level: middleimportance: must knowfreq 55%

basics

~20 s

Your recovery point equals the newest data that survived the primary. Synchronous commit to another node gives near-zero loss; asynchronous gives loss equal to replication lag; log archiving gives loss up to the archive interval. Tighter costs write latency and couples your availability to the standby.

open as a page

What is the difference between a logical database backup (the kind produced by tools such as pg_dump or mysqldump) and a physical backup (the kind produced by pg_basebackup or Percona XtraBackup), and when would you choose each?

level: middleimportance: must knowfreq 64%

basics

~20 s

A logical backup exports data as SQL statements or rows that must be re-executed to restore. A physical backup copies the database's data files byte for byte. Logical is portable and selective but slow to restore; physical is fast but version- and platform-bound.

open as a page

Your routing layer sends writes to the primary and SELECTs to read replicas. What correctness problems does that split introduce, and how do you deal with them?

level: middleimportance: must knowfreq 55%

basics

~20 s

Replicas lag, so a read right after a write may not see it, and successive reads can go backwards in time. Fixes: keep reads inside a transaction on the primary, pin a session to the primary for a short window after it writes, or route only when the replica has caught up to the write's log position.

open as a page

Compare three ways of pointing application traffic at whichever database node is currently the primary: a floating virtual IP, updating a DNS record, and a proxy layer such as HAProxy, PgBouncer or ProxySQL. What are the failure modes of each?

level: middleimportance: must knowfreq 50%

basics

~20 s

A floating IP moves in seconds but needs the nodes on one network segment and kills existing connections. DNS works anywhere but is hostage to TTL and client-side caching. A proxy decides per connection and can health-check and drain, but adds a hop and must itself be made highly available.

open as a page

Why does automated database failover require a majority quorum, and what is a witness (or arbiter) node used for in a cluster that would otherwise have an even number of members?

level: middleimportance: must knowfreq 48%

basics

~20 s

Only a majority of a fixed member set may elect a primary, because at most one majority can exist, so a minority partition can never promote. A witness is a cheap vote-only member that makes the member count odd without storing data.

open as a page

When a replica is promoted to primary, for example using the PostgreSQL pg_promote() function or MySQL's CHANGE REPLICATION SOURCE command, what actually changes on that node, and what must then happen to the other replicas?

level: middleimportance: must knowfreq 46%

basics

~20 s

Promotion ends recovery on that node: it finishes applying what it already received, opens for writes, and starts its own branch of the change stream (a new PostgreSQL timeline or a new binlog source). Every other replica must be repointed at it, and any replica ahead of it must be rewound or rebuilt.

open as a page

Replication from a primary to a replica happens in several stages. Which stages can lag independently, and what do PostgreSQL's pg_stat_replication view and MySQL's Seconds_Behind_Source field each tell you about them?

level: middleimportance: must knowfreq 56%

basics

~20 s

Stages: the primary generates log records, sends them, the replica writes them, flushes them to disk, then replays them. pg_stat_replication exposes sent/write/flush/replay positions and the matching lag intervals per stage. MySQL's Seconds_Behind_Source covers only the apply stage — receive lag is separate.

open as a page

Explain the difference between physical (block/WAL-shipping) replication and logical (row-level) replication between relational databases, and what each produces on the receiving side.

level: middleimportance: must knowfreq 56%

basics

~20 s

Physical replication ships the low-level change log describing byte and page edits, so the replica is a block-for-block clone — same version, all objects, read-only. Logical replication decodes changes into row-level events (insert/update/delete with column values) that the target executes, so it can differ in version, schema and contents.

open as a page

A user saves their profile, the application immediately re-reads it from an asynchronous read replica, and the old values come back. Explain why this happens and what the standard fixes are.

level: middleimportance: must knowfreq 60%

basics

~20 s

The primary acknowledged the commit before the replica applied it, so the follow-up read hit a copy that does not yet contain the change. Fixes: read that user's data from the primary for a short window after their write, or make the read wait until the replica has applied that write's position.

open as a page

When a system is described as synchronously replicated, the acknowledgement may mean the standby received the change, flushed it to its own log, or replayed it so queries can see it. Why does that distinction matter, and what does each level buy you?

level: middleimportance: must knowfreq 50%

basics

~20 s

Each level survives a different failure. Received in memory survives losing only the primary; flushed to the standby's disk also survives the standby restarting; replayed additionally makes the change visible to readers on the standby. Later levels add latency, so pick the earliest level that covers the failure you care about.

open as a page

At 14:32 someone ran an UPDATE without a WHERE clause against the production database. Walk through recovering the database to the state just before that statement.

level: seniorimportance: must knowfreq 56%

basics

~20 s

Stop further writes and preserve the current data and log archive. Identify the exact target just before the statement. Restore the latest base backup taken before 14:32 onto a separate host, replay archived log up to that target, pause and verify, then either cut over to the restored copy or extract the damaged rows back into production.

open as a page

Break down everything that consumes wall-clock time between a database primary dying and the application serving writes again. Which of those components usually dominate, and which can be engineered away?

level: seniorimportance: must knowfreq 50%

basics

~20 s

Detect, decide, fence the old primary, promote or restore, replay logs, repoint clients, warm caches, verify. Detection and human decision usually dominate, then restore and replay if there is no standby. Automation removes detection and decision time; a warm standby removes restore and replay.

open as a page

During a planned primary switchover behind a database proxy, what has to happen to the connections that clients already hold, and what must the application do so users do not see errors?

level: seniorimportance: must knowfreq 45%

basics

~20 s

In-flight transactions cannot be moved; they are rolled back. The proxy stops issuing the old primary, lets open transactions finish for a bounded time, then closes them, optionally queueing new connections. Clients must discard pooled connections and retry — with backoff, jitter, and only where the operation is safe to repeat.

open as a page

What does fencing mean when a database standby is promoted, and what mechanisms are used to fence the old primary, including the STONITH (shoot the other node in the head) approach?

level: seniorimportance: must knowfreq 42%

basics

~20 s

Fencing means guaranteeing the old primary can no longer commit writes or be reached by clients before the new primary opens. It is done by killing the node (STONITH via power or hypervisor), revoking its storage or network access, or removing it from the routing layer.

open as a page

After an unplanned failover on an asynchronously replicated relational cluster, how much committed data can be lost, how do you measure that exposure before an incident, and what levers reduce it?

level: seniorimportance: must knowfreq 44%

basics

~20 s

You can lose everything the primary committed but had not yet shipped to the promoted replica. Measure it as replication lag in bytes and seconds at the p99, per replica, continuously. Levers: reduce lag, promote the furthest replica, refuse promotion past a lag threshold, or make commits synchronous.

open as a page

A read replica repeatedly falls minutes behind its primary during peak hours, even though the replication network link is nowhere near saturated. What are the usual causes of apply-side replication lag, and how would you narrow it down?

level: seniorimportance: must knowfreq 52%

basics

~20 s

Usual causes: apply is far less parallel than the primary's concurrent writers; long or huge transactions arriving as one burst; row changes on the replica lacking a usable index so each change scans; replica hardware or I/O weaker; and replay blocked by conflicting long-running queries on the replica. Narrow it down by finding which stage and which transaction stalls.

open as a page

What are the practical limitations and operational risks of running row-level logical replication compared with block/WAL-level physical replication?

level: seniorimportance: must knowfreq 41%

basics

~20 s

Logical replication does not carry schema changes, sequence values, or (by default) everything the cluster contains; apply is far slower per change; the writable target can hit conflicts that stall the whole subscription; the initial snapshot is expensive; and an unconsumed change stream retains log on the source until its disk fills.

open as a page

Your database primary's commits suddenly hang for every client, and the only change in the environment is that one standby became unreachable. Explain the mechanism, and how you would configure the system so that losing a standby cannot stall writes.

level: seniorimportance: must knowfreq 44%

basics

~20 s

Synchronous commit makes the primary wait for a standby's acknowledgement before returning; with the only such standby gone, every commit waits forever. Fixes: use a quorum of any k of n with n greater than k, configure an automatic timeout that degrades to asynchronous, and monitor and alert on degraded mode.

open as a page

Explain the 3-2-1 backup rule and how you would apply it to a production relational database. What failure modes do off-site and immutable copies protect against that a second local copy does not?

level: middleimportance: should knowfreq 42%

basics

~20 s

Keep three copies of the data, on two different media or storage systems, with at least one off-site. For a database that means the live cluster, a local or same-region backup repository, and a copy in another region or account - ideally write-once so it cannot be deleted or encrypted by an attacker.

open as a page

Describe the layers of verification you can apply to a database backup, from cheapest to most convincing - for example checksum and manifest verification (as pgBackRest's verify command does) versus a full restore with data assertions. What does each layer catch, and what does each miss?

level: middleimportance: should knowfreq 45%

basics

~20 s

Four layers: metadata checks (file present, size, expected members), checksum and manifest verification of the stored bytes, a restore that starts the engine and replays logs, and application-level assertions on the restored data. Cheap layers catch corruption; only a restore proves recoverability.

open as a page

You need to feed a separate reporting database with just three tables out of a 400-table production database. The reporting database must also hold its own locally-created summary tables and extra indexes tuned for analysts. Would you use physical or logical replication, and what does that choice commit you to?

level: middleimportance: should knowfreq 42%

basics

~20 s

Logical replication. Physical copies the entire cluster byte-for-byte and keeps the target read-only, so neither selective tables nor local tables and extra indexes are possible. Logical costs you: manual DDL coordination, row identity on the three tables, conflict handling, and slot/log retention on the source.

open as a page

showing 1–30 of 54