Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 96

    High Availability

    High availability means surviving failures invisibly: machine loss, AZ loss, dependency brownouts, and the human deploy at 17:00 on Friday.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    High availability means surviving failures invisibly: machine loss, AZ loss, dependency brownouts, and the human deploy at 17:00 on Friday. TechLearningPRO Orders aims for redundant pods across zones, correct readiness/liveness probes, automated DB failover where the platform supports it, and graceful shutdown that drains in-flight checkouts.

    HA is redundancy + health checks + failover + practice. Runbooks linked from every alert beat heroics. Retries use jittered backoff so Orders does not become a thundering herd against Postgres or Inventory.

    Boot 3 Actuator health groups feed Kubernetes probes; Java 21 does not change the ops math. Multi-region is for tier-0 when RPO/RTO demand it — not a default for every service.

    This lesson closes the production/enterprise arc with failure-first thinking.

    Purpose of this lesson

    Design Orders for HA: multi-AZ replicas, correct probes, graceful shutdown, failover, and practiced runbooks.

    Understanding the topic

    Survive failure without users noticing.

    • Redundancy: N replicas, multi-AZ; multi-region for tier-0.
    • Health checks: readiness vs liveness done right.
    • Load balancing: least-connections; sticky only when forced.
    • Failover: primary/replica DB with automatic promotion where offered.
    • Graceful shutdown: drain connections; finish in-flight requests.
    • Retries: jittered backoff — never thundering-herd.
    • Runbooks: every alert links to one; game-day practice.

    Step-by-step explanation

    1. Deploy Orders with at least two replicas across AZs.
    2. Wire readiness to dependency health (DB) and liveness to process health — do not restart on downstream blips.
    3. Enable graceful shutdown (server.shutdown=graceful) with a drain period that matches the LB.
    4. Attach runbooks to latency/error alerts; schedule a game day that kills a pod and a DB failover.

    Informative example

    HA-oriented Boot 3 + Kubernetes probes for Orders.

    yaml
    # application.yml
    server:
    shutdown: graceful
    spring:
    lifecycle:
    timeout-per-shutdown-phase: 30s
    management:
    endpoint:
    health:
    probes:
    enabled: true
    health:
    livenessstate:
    enabled: true
    readinessstate:
    enabled: true
    # Deployment probes
    livenessProbe:
    httpGet: { path: /actuator/health/liveness, port: 8080 }
    periodSeconds: 10
    readinessProbe:
    httpGet: { path: /actuator/health/readiness, port: 8080 }
    periodSeconds: 5
    terminationGracePeriodSeconds: 40

    Real-world use

    A rolling deploy once killed Orders pods mid-checkout because shutdown was immediate and readiness never went false. Enabling graceful shutdown and separating readiness from liveness stopped 502 spikes; a later game day proved DB failover runbooks before a real AZ incident.

    Security implications

    HA controls must not weaken isolation during failover.

    • Failover targets use the same least-privilege credentials — rotated via the secret store.
    • Health endpoints stay non-sensitive; detailed health only when authorized.
    • Do not disable auth during incidents 'to keep the site up'.

    Best practices

    • Redundancy in every critical tier — app, LB, data.
    • Practice failure (game days) before production teaches you.
    • Link every alert to a runbook with owners and rollback steps.

    Common mistakes

    • Using the same probe for liveness and readiness and restarting pods on DB blips.
    • Single-replica 'HA' PowerPoint architectures.
    • Retries without jitter that amplify outages.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionWhat is the difference between liveness and readiness?+

    Answer

    Liveness asks if the process should be restarted; readiness asks if it should receive traffic — conflating them causes restart storms.
    2IntermediateQuestionWhy is graceful shutdown required for HA deploys?+

    Answer

    It drains in-flight requests and deregisters from the LB so clients do not hit a dying pod.
    3IntermediateQuestionWhy practice game days?+

    Answer

    So failover and runbooks are proven before a real outage — never debug production HA for the first time during an incident.

    Hands-on exercise

    Lab. Configure graceful shutdown and distinct liveness/readiness probes on Orders. Kill one pod under load and confirm the LB stops sending traffic before process exit; write a half-page runbook for that alert.

    Summary

    High availability keeps TechLearningPRO Orders up when pieces fail. You now have the production and enterprise architecture toolkit to operate Boot 3 services with confidence.

    Ready to mark this lesson complete?Track your journey across the entire course.