How do you implement database backup, recovery, and high availability strategies?
Database protection ensures data survives hardware failures, human errors, and disasters. Backup types: full backup (complete database copy, largest size, longest to create), incremental backup (changes since last backup, small and fast), and continuous archiving (WAL shipping for point-in-time recovery). PostgreSQL backup: pgdump for logical backups (SQL output, portable across versions, slower for large databases), pgbasebackup for physical backups (binary copy, faster, same version only), and continuous WAL archiving (ship WAL files to object storage for continuous point-in-time recovery). Recovery objectives: RPO (Recovery Point Objective, maximum acceptable data loss, determines backup frequency), and RTO (Recovery Time Objective, maximum acceptable downtime, determines recovery infrastructure). Implementation: automate daily full backups with pgdump or pgbasebackup to object storage (S3, GCS), implement continuous WAL archiving for point-in-time recovery capability (RPO near zero), encrypt backups at rest, test restore procedures monthly (a backup you can't restore is not a backup), and maintain backups in a different region from the primary database. High availability: streaming replication (primary to one or more standby replicas, synchronous for zero data loss or asynchronous for better performance), automatic failover (using Patroni, stolon, or cloud-managed HA like RDS Multi-AZ), and read replica load balancing for read-heavy workloads. Supabase HA: managed point-in-time recovery, daily backups, and high-availability configurations available on Pro plans. Disaster recovery: maintain backups in a separate region, document recovery procedures step by step, practice recovery drills quarterly, and maintain infrastructure-as-code for rapid environment reconstruction. Monitoring: alert on backup failures, replication lag exceeding threshold, and storage approaching capacity.