Production Engineering / PRODUCTION READINESS & SERVICE OWNERSHIP / PRD-002

Suggested study path · Step 1 of 1 · G2

Health Contract

Explore concept graph

Materi

Target: implementasikan /live dan /ready pada Spring Boot sehingga startup lambat, database down, recovery, dan graceful drain tidak menyebabkan dependency-driven liveness restart loop.

Mulai: tulis status /live dan /ready ketika proses responsif tetapi database yang wajib untuk transfer tidak tersedia.

Peta konsep statis. Ikuti alur teks dari atas ke bawah.
Cold start → startupProbe → process liveness
                                |
                                v
                         /live (restart?)
                                |
              warmup + required DB + drain
                                |
                         /ready (traffic?)
                                |
                      Transfer API / Service
                                |
                    business-level safety

Contoh Spring Boot Actuator

Tambahkan dependency spring-boot-starter-actuator. Spring Boot memiliki health groups /actuator/health/liveness dan /actuator/health/readiness. Ekspos alias ini pada port HTTP utama:

management.endpoint.health.probes.enabled=true
management.endpoint.health.group.liveness.additional-path=server:/live
management.endpoint.health.group.readiness.additional-path=server:/ready
management.endpoint.health.show-details=never

Indikator eksternal tidak otomatis menjadi bagian readiness. Jika ledger DB wajib agar transfer dapat dilayani, implementasikan health indicator transferDbHealthIndicator dengan pemeriksaan berbiaya rendah dan timeout terbatasi, kemudian sertakan dalam readiness saja:

management.endpoint.health.group.readiness.include=readinessState,transferDb

Jangan memasukkan database ke liveness. Shared DB down bisa membuat semua replica menjadi unready: apakah itu benar harus diputuskan berdasarkan kebutuhan service dan risiko semua endpoint hilang.

Kubernetes probe policy (contoh, bukan bukti cluster)

startupProbe:
  httpGet: { path: /live, port: 8080 }
  periodSeconds: 5
  failureThreshold: 24
livenessProbe:
  httpGet: { path: /live, port: 8080 }
  periodSeconds: 10
  failureThreshold: 3
readinessProbe:
  httpGet: { path: /ready, port: 8080 }
  periodSeconds: 5
  failureThreshold: 2

Contoh startup budget sekitar 5 × 24 = 120 detik probe failures, bukan timing guarantee. Jika HTTP server sudah aktif tetapi mandatory warmup belum selesai, /live bisa 200 sementara /ready masih 503. Atur threshold berdasarkan startup yang benar-benar diukur.

Konsep 1 / 3

Define /live and /ready as different Spring Boot health contracts.

An HTTP process may be healthy while a required ledger database cannot serve money movements.

Mulai dari sini

Predict both status codes when a healthy process loses DB connectivity.

Intuisi utama

Liveness is process health and restart eligibility; readiness is traffic admission. Neither proves transaction safety.

Spring Boot Actuator exposes /actuator/health/liveness and /actuator/health/readiness, and can add main-port aliases /live and /ready. Kubernetes uses liveness failure for restarts and readiness failure to remove normal Service traffic. The liveness group must not check external systems. Adding a DB indicator to readiness is an explicit critical-dependency decision; a shared DB outage may make all replicas unready.

Contoh bertahap

An HTTP process may be healthy while a required ledger database cannot serve money movements.

  1. Expose liveness and readiness as independent health groups.

    Mengapa: Their operators have different consequences.

    Hasil yang diharapkan: A health path exists for each decision.

  2. Keep the shared DB outside liveness.

    Mengapa: Restarting replicas cannot repair the remote database.

    Hasil yang diharapkan: /live stays healthy if the process still progresses.

  3. Make critical DB readiness explicit and bounded.

    Mengapa: Unavailable instance should not receive normal transfer traffic.

    Hasil yang diharapkan: /ready may return 503 during the outage.

Konsep 2 / 3

Separate a startupProbe budget from readiness during warming.

A healthy process may take long to initialize before it can serve transfer operations.

Mulai dari sini

Calculate 5 multiplied by 24 and identify its limitation as a timing budget.

Intuisi utama

startupProbe defers regular liveness/readiness checks until it succeeds; readiness can still stay unready afterward.

A startupProbe can protect slow cold boot. For example a 5-second period and failureThreshold of 24 give about 120 seconds of tolerated startup failures, not a precise timing guarantee. Once the HTTP listener is active, /live may return 200 while essential warmup continues and /ready returns 503. Probe settings must follow measured cold-start behavior, and the HTTP fixture does not implement actual kubelet scheduling.

Contoh bertahap

A healthy process may take long to initialize before it can serve transfer operations.

  1. During warmup, report /ready unavailable.

    Mengapa: Serving new work is unsafe before mandatory setup finishes.

    Hasil yang diharapkan: readiness returns 503.

  2. Configure bounded startup failure tolerance.

    Mengapa: Avoid premature liveness restart of a process that is still booting.

    Hasil yang diharapkan: Sample budget is approximately 120 seconds.

  3. After warmup, report ready.

    Mengapa: A ready instance is eligible for routing.

    Hasil yang diharapkan: readiness returns 200 without a process restart.

Konsep 3 / 3

Simulate DB outage and graceful shutdown without dependency-driven restart loops.

Shared DB failures and abrupt rollout termination can amplify incidents across replicas.

Mulai dari sini

Write /live and /ready status for DB down and for a draining instance.

Intuisi utama

A critical DB may affect readiness while a healthy process stays live. Draining stops new traffic while existing work completes within a bounded window.

By default Spring Boot readiness does not include every external health indicator; operators must choose critical ones. When a required DB fails, readiness may report 503 and liveness should remain 200 if the process itself still progresses. DB recovery can restore readiness without restarting. On SIGTERM, graceful shutdown stops accepting new requests and gives in-flight requests a configured phase timeout; Kubernetes terminating endpoints are not eligible for regular Service traffic. An /live 200 is never permission to execute a financial operation. During actual Spring Boot graceful shutdown, readiness availability changes to REFUSING_TRAFFIC, but HTTP connectors may stop accepting new connections, including probe requests. Do not require an observable /ready 503 during the shutdown window; verify drain and EndpointSlice state instead. The local fixture's drain-ready=503 is only a state-model output.

Contoh bertahap

Shared DB failures and abrupt rollout termination can amplify incidents across replicas.

  1. Simulate DB unavailable on a healthy process.

    Mengapa: Availability of a shared dependency does not dictate local process death.

    Hasil yang diharapkan: live=200, ready=503.

  2. Restore DB connectivity.

    Mengapa: A healthy process can resume admission without restart.

    Hasil yang diharapkan: ready=200.

  3. Begin bounded graceful drain.

    Mengapa: Prevent new work while allowing existing requests to finish.

    Hasil yang diharapkan: In the local model /ready returns 503 and /live remains 200; in actual Spring shutdown the probe HTTP connector may reject new connections instead.

Referensi teknis

Sumber

Cross-domain connections

Curated relationships for this unit at G2. Proposed edges are suggestions, not prerequisites.

Concept connectionsG2 · 1 visible concepts · 1 curated links
100%

Dashed = proposed relationship; solid = reviewed connection. Only reviewed prerequisites constrain a learning path. Keyboard and text links remain available.