Backup and disaster recovery in Supabase - Time & Space Complexity
When backing up data or recovering from a disaster, it's important to know how long these processes take as data grows.
We want to understand how the time to backup or restore changes when the amount of data increases.
Analyze the time complexity of the following backup operation using Supabase.
// Export all rows from a table
const { data, error } = await supabase
.from('orders')
.select('*')
// Save data to backup storage
await saveToBackupStorage(data)
This sequence fetches all records from a database table and saves them as a backup.
Look at what repeats as data grows:
- Primary operation: Fetching all rows from the database table.
- How many times: Once per backup, but the amount of data fetched grows with table size.
As the number of rows increases, the amount of data fetched and saved grows proportionally.
| Input Size (n rows) | Approx. Data Fetched & Saved |
|---|---|
| 10 | Small data, quick fetch and save |
| 100 | 10 times more data, takes longer |
| 1000 | 100 times more data, much longer |
Pattern observation: Time grows roughly in direct proportion to the number of rows.
Time Complexity: O(n)
This means the time to backup grows linearly with the amount of data.
[X] Wrong: "Backing up twice the data only takes twice as many API calls, so it's always fast."
[OK] Correct: While API calls may be few, the data size transferred grows with data amount, which slows the process.
Understanding how backup time grows helps you design systems that handle data safely and efficiently, a key skill in cloud roles.
What if we only backed up changed rows instead of all rows? How would the time complexity change?
Practice
Solution
Step 1: Understand what backups do
Backups create copies of your data so you can restore it if something goes wrong.Step 2: Identify the main goal in Supabase context
Supabase backups protect your data from accidental loss or corruption.Final Answer:
To save copies of data to prevent loss -> Option AQuick Check:
Backups = Data safety [OK]
- Confusing backups with performance improvements
- Thinking backups reduce costs
- Mixing backups with security features
Solution
Step 1: Identify manual backup options in Supabase
Manual snapshots let you create backups whenever you want, on demand.Step 2: Differentiate from automated backups
Automated backups happen on a schedule, not manually triggered by users.Final Answer:
Manual snapshots -> Option DQuick Check:
Manual backup = Manual snapshots [OK]
- Confusing automated backups with manual ones
- Thinking real-time replication is a backup
- Mixing indexing with backup features
const backup = await supabase.storage.from('backups').upload('backup-2024-06-01.sql', file);
console.log(backup.error);What will be the output if the upload succeeds?
Solution
Step 1: Understand Supabase upload response
If the upload is successful, the error property is null, meaning no error occurred.Step 2: Check console.log output
Logging backup.error will print null on success, not a string or undefined.Final Answer:
null -> Option CQuick Check:
Success error = null [OK]
- Expecting error to be undefined on success
- Confusing error messages with success
- Assuming upload returns a string on success
const { data, error } = await supabase.rpc('restore_backup', { backup_id: 123 });
if (error) console.log(error.message);What is a likely cause of the error?
Solution
Step 1: Check the RPC function existence
If the 'restore_backup' function is not defined in the database, calling it causes an error.Step 2: Verify parameters and storage
The backup_id is provided, and storage fullness or file format errors usually cause different messages.Final Answer:
The 'restore_backup' function does not exist in the database -> Option AQuick Check:
Missing function = error [OK]
- Assuming parameter missing without checking code
- Blaming storage when error is function-related
- Confusing file format issues with RPC errors
Solution
Step 1: Understand backup types and frequency
Automated backups provide regular safety, while manual snapshots add extra protection before big changes.Step 2: Combine strategies for fast disaster recovery
Using both ensures you can restore recent data and specific points before updates, minimizing data loss and downtime.Final Answer:
Automated backups daily plus manual snapshots before big updates -> Option BQuick Check:
Combine automated + manual for best recovery [OK]
- Relying only on manual snapshots risks missing backups
- Ignoring manual snapshots before big changes
- Assuming real-time replication replaces backups
Ready to prove it?
Pass the test and this pattern moves unknown
