Zero downtime requires two things: instances are replaced without dropping traffic, and old and new versions can run against the same database at the same time. Application rollout - Kubernetes rolling updates (maxUnavailable: 0, maxSurge: 1) or blue-green and canary releases (Argo Rollouts, service mesh traffic splitting). - Spring Boot Actuator health groups for probes: readiness (/actuator/health/readiness) so traffic only reaches ready pods, liveness for restarts. - Graceful shutdown: server.shutdown=graceful and spring.lifecycle.timeout-per-shutdown-phase, plus a short preStop sleep so the load balancer stops sending traffic before the pod shuts down. - Warm-up: pre-initialise connection pools and caches before marking ready. - Messaging consumers must also stop cleanly and not lose in-flight messages. Backward-compatible database changes (expand and contract) 1. Expand: add new tables or nullable columns, create indexes concurrently (CREATE INDEX CONCURRENTLY in PostgreSQL). Run the migration before deploying new code. 2. Deploy code that writes both old and new columns and can read either. 3. Backfill data in small batches (a Spring Batch job or a background task) to avoid long locks. 4. Switch reads to the new structure in the next release. 5. Contract: remove old columns only after no running version uses them, in a later release. Never rename or drop columns, or add NOT NULL constraints without defaults, in the same release as the code change. Migration tooling - Flyway or Liquibase versioned migrations, reviewed in pull requests and run as a separate pipeline step or Kubernetes Job (not concurrently by every starting instance). - Watch for locking statements on large tables; set lock timeouts so a migration fails fast rather than blocking production. API compatibility - Old and new versions serve traffic simultaneously during a rollout, so API changes must be backward compatible too (additive fields, tolerant JSON readers). Safety nets - Feature flags to enable new behaviour gradually. - Automated smoke tests after deployment and monitoring of error rates and latency, with automatic rollback. - Rollback means deploying the previous image, which still works because the schema change was backward compatible. - Backups and point-in-time recovery before risky data migrations.
Ravindra Wadile · · 0 likes