keepcalculator

06 Numbers and Powers

Zero Downtime Server Upgrade: Step-by-Step

Card No. 06·69765 · Updated · Standard formula, shown below

This guide walks you through upgrading a server (hardware or software) without interrupting service. You’ll learn strategies like rolling updates, blue-green deployments, and load balancer draining, so users stay connected while you make changes. Start by reading the prerequisites, then follow the steps in order.

What You’ll Need

  • Two servers or a cluster (for rolling/blue-green). If you only have one, you’ll need a temporary second one or accept a brief failover.
  • Access to a load balancer or reverse proxy (e.g., Nginx, HAProxy, cloud LB) that can route traffic.
  • SSH access with sudo or admin rights on all servers.
  • A backup of your data and configuration files.
  • A rollback plan (e.g., previous version of software, database snapshot).
  • Monitoring tools (even just ping and logs) to verify health.

Step-by-Step

  1. Prepare a staging environment. Test the upgrade on a non-production server first. This catches compatibility issues before they hit live traffic.
  2. Back up everything. Take a full backup of your application files, configuration, and database. Store it offsite or on a separate machine.
  3. Set up health checks. Configure your load balancer to check a specific endpoint (e.g., /health) on each server. This will be used to automatically stop sending traffic to a server that fails.
  4. Drain one server at a time (rolling upgrade). If you have multiple servers, take the first one out of rotation. In your load balancer, mark it as “draining” or “maintenance”. Wait for active connections to finish (usually a timeout of 30-60 seconds).
  5. Perform the upgrade on that server. SSH in, stop the service, apply the upgrade (package update, code deploy, hardware swap), then start the service.
  6. Verify health. Check that the server passes its health check and that your application responds correctly. Look at logs for errors.
  7. Put the server back in rotation. Re-enable it in the load balancer. Traffic will gradually flow back to it.
  8. Repeat for each server. Move to the next server, drain, upgrade, verify, and re-add. Do this one at a time, never taking more than one server down at once (unless you have spare capacity).
  9. If you have only one server, use blue-green. Set up a second, identical server (the “green” environment). Upgrade it fully while the old one (“blue”) still serves traffic.
  10. Switch traffic. Once green is healthy, update the load balancer to point all traffic to green. Keep blue running for a while as a fallback.
  11. Monitor after the switch. Watch for errors, latency, and resource usage. If something goes wrong, you can switch back to blue immediately.
  12. Clean up. After a stable period (e.g., 24 hours), you can decommission the old server or repurpose it.

Common Mistakes

  • Upgrading the database first without compatibility. If your new code needs a different DB schema, upgrade the database first, but ensure the old code still works with the new schema (backward compatibility). Otherwise, you’ll break the old version.
  • Not draining connections. If you just kill the service, users lose their session. Always drain.
  • Assuming health checks are enough. A server might pass a simple ping but still have broken functionality. Use a health check that exercises the actual application.
  • Upgrading all servers at once. This defeats the purpose. Do it one by one.
  • Forgetting to test rollback. Practice rolling back before you need it.

Tips

  • Use feature flags. Deploy code that is dormant behind a flag, then enable it gradually. This decouples deployment from release.
  • Automate as much as possible. Use configuration management (Ansible, Puppet) to apply upgrades consistently.
  • Schedule during low traffic. Even with zero downtime, it’s safer to do it when fewer users are active.
  • Keep a rollback script ready. Have a script that can quickly restore the previous version.
  • Monitor resource usage. After upgrade, check CPU, memory, and disk. A new version might have higher requirements.
  • Document the exact steps. Write down what you did, so next time is faster.

Troubleshooting

If something goes wrong during the upgrade, follow these steps:

  • Server fails health check after upgrade. Immediately take it out of rotation (if not already). SSH in and check logs. Common causes: missing dependencies, permission issues, or a service that didn’t start. Fix, then re-test.
  • Users report errors during draining. Increase the drain timeout or force-close idle connections. If errors persist, put the server back in service and investigate.
  • Database migration fails. Stop the upgrade process. Restore the database from backup, or roll back the migration. Never leave the database in a half-migrated state.
  • Load balancer not sending traffic to upgraded server. Check that the server is marked as healthy in the LB. Verify the health check URL is accessible from the LB’s network.
  • Performance degrades after upgrade. Could be a code issue or resource leak. Check logs for errors, monitor memory, and consider rolling back if it’s severe.
  • You need to rollback. Switch the load balancer back to the old server(s). If you did a rolling upgrade, you’ll need to reverse the steps on each server, using your backups.

Frequently Asked Questions

Can I do zero downtime upgrade on a single server?

Not truly. You need at least two instances to have one serve while the other upgrades. If you only have one, you’ll have to accept a short outage or use a temporary second server.

How long should I drain a server?

It depends on your application. Typically 30-60 seconds is enough for most web requests. For long-lived connections (like WebSockets), you may need to wait longer or implement a graceful shutdown that lets clients reconnect.

What’s the difference between rolling and blue-green?

Rolling upgrades update servers one at a time in the same environment. Blue-green uses two separate environments (blue = current, green = new) and switches traffic all at once. Blue-green is safer but requires more resources.

Do I need to upgrade the database first?

Usually yes, but only if the new schema is backward compatible with the old code. If not, you need a more complex strategy like expand-contract (add new columns, then migrate data, then remove old columns).

How can I verify zero downtime actually happened?

Monitor your load balancer logs for 5xx errors during the upgrade. Also, watch your application’s error rate and user session counts. If they stay stable, you’ve achieved zero downtime.

What if I don’t have a load balancer?

You can use DNS round-robin, but that’s less reliable. Better to set up a simple reverse proxy like Nginx or HAProxy. Even a basic one is worth it for the ability to drain and switch.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →