Rollback deployments in Firebase - Time & Space Complexity
When rolling back deployments in Firebase, it is important to understand how the time to complete the rollback changes as the number of deployment versions grows.
We want to know how the rollback process scales when choosing different previous versions to restore.
Analyze the time complexity of the following rollback operation.
// Rollback to a previous Firebase Hosting version
const admin = require('firebase-admin');
async function rollbackHostingVersion(siteId, versionId) {
const hosting = admin.hosting();
await hosting.sites.versions.patch({
name: `sites/${siteId}/versions/${versionId}`,
updateMask: 'status',
resource: {
status: 'FINALIZED'
}
});
await hosting.sites.releases.create({
parent: `sites/${siteId}`,
requestBody: {
versionName: `sites/${siteId}/versions/${versionId}`
}
});
}
This code finalizes a previous version and updates the site to use that version, effectively rolling back the deployment.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Two API calls per rollback: one to finalize the version, one to update the site release.
- How many times: These calls happen once per rollback action, regardless of the number of versions.
The rollback involves selecting one version and updating the site to that version. The number of API calls stays the same no matter how many versions exist.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 versions | 2 calls |
| 100 versions | 2 calls |
| 1000 versions | 2 calls |
Pattern observation: The number of API calls does not increase with more versions; it remains constant.
Time Complexity: O(1)
This means the rollback time stays about the same no matter how many deployment versions exist.
[X] Wrong: "Rolling back takes longer if there are many versions to choose from because it must update each one."
[OK] Correct: The rollback only updates the selected version and the site release once, so the number of versions does not affect rollback time.
Understanding how rollback operations scale helps you design reliable deployment processes and explain system behavior clearly in real projects.
"What if the rollback process needed to verify or update all previous versions before switching? How would the time complexity change?"
Practice
What is the main purpose of firebase hosting:rollback?
Solution
Step 1: Understand rollback purpose
Rollback is used to undo a deployment that caused issues by restoring the previous stable version.Step 2: Identify command function
The commandfirebase hosting:rollbackspecifically reverts to the last working deployment.Final Answer:
To undo a recent deployment and restore the previous version -> Option DQuick Check:
Rollback = undo deployment [OK]
- Confusing rollback with deploying new versions
- Thinking rollback deletes all versions
- Assuming rollback creates backups
Which of the following is the correct syntax to rollback the last Firebase Hosting deployment?
Solution
Step 1: Recall correct command structure
The official Firebase CLI command for rollback isfirebase hosting:rollback.Step 2: Check option syntax
Options B, C, and D do not match the correct Firebase CLI syntax for rollback.Final Answer:
firebase hosting:rollback -> Option AQuick Check:
Correct syntax = firebase hosting:rollback [OK]
- Swapping command parts order
- Adding extra flags not needed
- Using deploy instead of hosting
Given the deployment history shows versions v5, v6, and v7, with v7 currently live, what will firebase hosting:rollback do?
Solution
Step 1: Identify current live version
The current live version is v7, the latest deployment.Step 2: Understand rollback behavior
Rollback reverts to the previous version before the current one, which is v6.Final Answer:
Rollback to version v6 -> Option AQuick Check:
Rollback = previous version v6 [OK]
- Choosing the oldest version instead of previous
- Thinking rollback redeploys current version
- Assuming rollback deletes versions
You ran firebase hosting:rollback but got an error saying "No previous version found." What is the most likely cause?
Solution
Step 1: Analyze error message meaning
The error "No previous version found" means there is no earlier deployment saved to revert to.Step 2: Consider possible causes
This usually happens if this is the first deployment or all previous versions were deleted.Final Answer:
You have no prior deployments to rollback to -> Option BQuick Check:
No previous version = no rollback possible [OK]
- Assuming command syntax error
- Blaming network issues
- Ignoring deployment history
You deployed version v10 but found a critical bug. You want to rollback to v9. However, v9 was deleted from the history. What is the best approach to recover your site quickly?
Solution
Step 1: Understand rollback limitations
Rollback only works if the previous version exists in deployment history. Since v9 is deleted, rollback cannot restore it.Step 2: Identify recovery method
The best way is to redeploy a saved local copy of v9 manually to restore the stable version quickly.Step 3: Evaluate other options
Options B and C won't work because rollback needs the version present, and Firebase does not auto-restore deleted versions. Contact Firebase support to restore v9 may take too long for urgent fixes.Final Answer:
Redeploy a saved local copy of v9 manually -> Option CQuick Check:
Deleted version = manual redeploy needed [OK]
- Expecting rollback to restore deleted versions
- Waiting for automatic Firebase restore
- Ignoring local backups
Ready to prove it?
Pass the test and this pattern moves unknown
