deferred-init

command
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 Imported by: 0

README

Deferred-init lifecycle

Demonstrates serving /healthz immediately while a long-running bootstrap (warmCaches) runs in the background. Application routes return 503 Service Unavailable until both the deferred init and the OnReady hook succeed; then the server flips to ready and traffic flows.

The pattern is for processes that need to register with an orchestrator (k8s readiness, ALB target health, etc.) before they finish their slow startup work — warming a cache, opening a long-lived database connection, fetching config from a remote secret store.

Run

go run ./examples/deferred-init &

In another shell:

curl -i http://localhost:8080/healthz      # 200 immediately
curl -i http://localhost:8080/api/users    # 503 until ready (~3s), then 200

The 503 is the contract — your orchestrator probes /healthz for liveness and /api/... for traffic readiness. Don't probe traffic routes with liveness intervals.

Documentation

Overview

Deferred-init example.

Demonstrates serving /healthz immediately while long-running bootstrap work (warmCaches) runs in the background. Application routes return 503 until bootstrap and the OnReady hook both succeed, then the server flips to ready.

Run it:

go run examples/deferred-init/main.go

Then in another shell:

curl -i http://localhost:8080/healthz  # 200 immediately
curl -i http://localhost:8080/api/users  # 503 until ready (~3s), then 200

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL