You probably can't remember the last time WhatsApp or Facebook told you it was closed for an update. How they deploy internally I don't know. What I do know is the general technique for any service that runs on many servers: update a few at a time while the rest keep serving, then move on to the next few. Nobody is switched over all at once, and nobody notices.
Many older systems were built differently. A system designed around a nightly batch often has to stop writes while the batch runs, because the batch needs a consistent view of the day and locking everything is the simplest way to get one. "Closed for maintenance" is the visible result of that design. It is not a law of nature.
If you are designing something today, ask for zero-downtime updates from day one. Retrofitting them into a system that assumes a quiet night is far harder than building them in. Below are the seven things I would check, with the failure modes that make each one more than a checkbox.
One idea runs through all of them. During a rolling deploy, version N and version N+1 run side by side, and they share everything: the database, the cache, the queues and the API clients. Every shared thing has to work with both versions, in both directions.
Roll out gradually, and let health checks decide
Rolling, blue-green and canary deployments differ in how much of the fleet changes at once, but all of them need a gate that stops the rollout when something is wrong. Here is a Kubernetes-flavoured config. The same ideas exist in other orchestrators.
apiVersion: apps/v1 kind: Deployment metadata: name: api spec: replicas: 6 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 # start one new instance before stopping an old one maxUnavailable: 0 # never drop below the desired replica count selector: matchLabels: { app: api } template: metadata: labels: { app: api } spec: terminationGracePeriodSeconds: 45 # covers preStop plus shutdown containers: - name: api image: registry.example.com/api:2026-11-19 readinessProbe: httpGet: { path: /ready, port: 8080 } periodSeconds: 5 failureThreshold: 2 lifecycle: preStop: exec: { command: ["sleep", "10"] } # needs a sleep binary in the image With maxUnavailable: 0, an instance that never becomes ready stalls the rollout and the old instances keep serving. That is the behavior you want.
The probe is where teams go wrong. A readiness check that only returns 200 proves the process is up, not that the new version works. Gate on the things users feel: error rate and latency of the new instances compared with the old ones, after a bake period long enough to see them. Keep readiness separate from liveness. If a liveness probe depends on the database, a database blip restarts every instance at once, which turns a slow dependency into a full outage.
Blue-green gives you an instant switch at the cost of roughly double capacity during the rollout. Canary sends a small share of traffic first and is only as good as the metrics you compare.
Drain connections before removing an instance
When an instance is told to stop, requests are in flight. If it exits immediately, they fail. The order should be:
- Stop receiving new traffic: fail the readiness check.
- Wait for the load balancer to notice. Endpoint removal propagates asynchronously, which is the reason for the
preStoppause in the config above. - Stop accepting new connections and let in-flight requests finish, up to a deadline.
- Exit before the grace period ends, or the orchestrator kills the process anyway.
Long-lived connections need extra care. A WebSocket does not finish on its own, so the server has to close it and the client has to reconnect. If every client reconnects at the same moment, the new instances take a burst they were not sized for. Reconnect with a random delay, and close connections gradually rather than all at once.
Make database changes backward compatible
This is the part that most often forces downtime. Renaming or replacing a column in one release means that during the rollout, half the fleet runs code that does not understand the schema. The pattern that avoids it is expand, migrate, contract, spread over separate releases:
-- Release 1 (expand): additive only, so nothing running today can break. SET lock_timeout = '3s'; -- fail fast instead of queueing behind a long transaction ALTER TABLE customers ADD COLUMN phone_e164 text; -- Release 2 ships code that writes both columns and reads phone_e164, -- falling back to phone when it is NULL. -- Backfill in small batches, repeated until it updates 0 rows. -- normalize_phone() is a stand-in for your own function. UPDATE customers SET phone_e164 = normalize_phone(phone) WHERE id IN ( SELECT id FROM customers WHERE phone_e164 IS NULL AND phone IS NOT NULL ORDER BY id LIMIT 1000 ); -- Release 3 stops reading and writing phone. -- Release 4 (contract): only now remove the old column. ALTER TABLE customers DROP COLUMN phone; The reason for the wait between steps is rollback. Until release 4, any earlier release can be redeployed and still works. If the column had been dropped in the same release as the code that stops using it, rolling back the code would break against the new schema.
Some PostgreSQL specifics worth knowing. An ALTER TABLE needs a strong lock. If a long-running transaction holds a conflicting lock, the ALTER waits, and every query that arrives after it queues behind it, so a harmless-looking migration becomes an outage. That is why lock_timeout is set above: fail, then retry. Adding a column with a constant default is fast since PostgreSQL 11 because it only touches the catalog; a volatile default such as clock_timestamp() still rewrites the table. Adding a constraint to a large table is safer as ADD CONSTRAINT ... NOT VALID followed by VALIDATE CONSTRAINT, and indexes should be built with CREATE INDEX CONCURRENTLY.
The cost is real: a rename becomes four releases. I accept that for tables that serve live traffic. For a table nobody reads during the day, a single release is fine.
Version your APIs and keep old mobile clients working
On the web you control what the user runs. On mobile you do not. People stay on old versions for weeks or months, so every server release has to work with every client version you still support. Mobile releases also pass through store review, which means a fix to a broken old client is not instant.
The server side of that is mostly discipline: add fields, never remove or repurpose them, and make new behavior opt-in. The client side is a tolerant reader. A client written before a new enum value existed must not crash when the server sends it:
enum OrderStatus { pending, shipped, delivered, unknown; static OrderStatus parse(String? raw) => OrderStatus.values.firstWhere( (s) => s.name == raw, orElse: () => OrderStatus.unknown, ); } The UI then shows something neutral for unknown instead of throwing. Ship that behavior in the first version of the app, because it only protects clients that already contain it.
Have the app send its version in a header, and log which versions still call which endpoints. That data tells you when an old endpoint can be retired. A forced-update screen is the last resort, not the plan.
Decouple "end of day" from availability
Day-close, reconciliation and reports do not need a lock on the whole system. They need a consistent view of a point in time, and databases can provide that without stopping anyone. In PostgreSQL, a repeatable-read transaction sees one snapshot for its whole life:
BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY; SELECT sum(amount) FROM ledger_entries WHERE business_date = DATE '2026-11-18'; -- every further query in this transaction sees the same snapshot COMMIT; The second half of the design is in the data model. Stamp each entry with a business_date. Closing a day becomes a state change on that date, and anything posted afterwards goes to the next day or to a clearly marked adjustment that references the closed one. The system keeps taking writes the whole time.
Run heavy reports on a read replica. A long transaction on the primary holds back cleanup of old row versions, and on a busy table that cost shows up.
Use feature flags so deploy and enable are separate decisions
When shipping code and turning on behavior are one event, every deploy is a release. A flag splits them: deploy dark, enable for a small group, widen, and switch it off in seconds if it misbehaves, without a rollback.
Flags have failure modes of their own. Decide what the code does when the flag service is unreachable, and keep sensible defaults compiled into the app, since mobile clients cannot wait for a network call. Remove flags once a rollout is finished, because a codebase full of stale flags has more states than anyone can test. Flags also pair with expand-contract: flipping the read path from phone to phone_e164 becomes a flag, not a deploy.
Keep a rollback path you have rehearsed
A rollback you have never run is a hope. It also has more parts than "deploy the previous version": the previous artifact must still exist, its configuration must still be valid, and the database must still work with it. The expand-contract rule above exists to keep that last part true.
Rehearse it. In staging, deploy N+1 under load, roll back to N while the load continues, and measure the time and the errors. Write down the criteria for choosing between rolling back and rolling forward, so nobody invents them at 2 a.m. Wire an automatic rollback to the same metrics that gate the rollout, so a bad canary reverts without waiting for a person.
When the answer is a maintenance window
Zero downtime has a price. It needs spare capacity during rollouts, more releases for schema changes, a test matrix of mixed versions, and flag hygiene. A small internal tool used by one office from nine to five may be better served by a short, announced window. The argument is not that every system needs this. It is that the window should be a decision someone made on purpose, because the alternative is the architecture making it for you.
There's a 41-second Arabic version of this in my «خلف الكواليس» series: https://youtube.com/shorts/UJSlV2iNrVg
