Containers, Runtime Configuration and Application Health

What a container still needs in production: liveness, readiness and dependency health, graceful shutdown, configuration and secrets.

  • Advanced
  • About 17 minutes
  • Includes an exercise and a knowledge check

The concept An image is not a deployment

The Apex image still needs a runtime: CPU and memory limits, environment configuration, database settings, secrets, health checks, startup and shutdown behavior, logging and a runtime identity. A container is created, started, marked healthy, restarted, stopped and replaced; the application must handle every transition and never assume it runs forever.

Three health checks and what failing each one does. Liveness, is the process stuck: restart the container. Readiness, can it take traffic now: stop routing requests, no restart. Dependency health, are the database and broker reachable: alert, no restart loop. Graceful shutdown after SIGTERM in six steps: stop accepting new requests, finish active requests within a bounded time, stop polling for messages, finish or release in-progress work, close database and broker connections, exit before the stop timeout.
Each check makes a different decision, and a container must know how to leave without losing work.

propertiesapplication.properties: probes and graceful shutdown (Spring Boot)

management.endpoints.web.exposure.include=health,info
management.endpoint.health.probes.enabled=true
# readiness includes the database; liveness does not, so a database outage never causes a restart loop
management.endpoint.health.group.readiness.include=readinessState,db
management.endpoint.health.group.liveness.include=livenessState
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=25s

For queue consumers, graceful shutdown means stopping polling, finishing or releasing the current message before its visibility timeout, and relying on idempotent processing for anything delivered again (Module 07). Secure the operational endpoints: they must not expose environment details publicly.

The API and the worker need different readiness rules, because nothing routes traffic to a worker. The properties above are for the API:

When PostgreSQL is unreachableAPI serviceSettlement worker
ReadinessNot ready: the load balancer stops sending it requests, so callers get a fast 503 from healthy tasks or the gateway instead of timeoutsNot about traffic: the worker pauses polling, so messages stay in the queue and return after their visibility timeout
LivenessStays healthy; no restart, because a restart cannot fix the databaseStays healthy; no restart loop
RecoveryReady again automatically when the database answersResumes polling with backoff; idempotent processing makes redelivered messages safe
What to alert onThe readiness failure and the 503 rateThe age of the oldest message, which shows the business falling behind

A worker that keeps polling with no database pulls messages, fails them and pushes them toward the dead-letter queue for a problem that is not theirs. Pausing is the safe default.

Configuration Secrets and runtime identity

Never put production passwords in Git, Dockerfiles, frontend bundles, plain deployment scripts or logs. Use a managed secrets service with a narrowly scoped task role, rotate credentials as Apex’s policy requires, and make sure the application reconnects cleanly after a rotation.

Practice Prepare the container

Practical exercise

Exercise 04: a production-ready container

Prepare the Apex container and stop it during active processing to see what happens.

  1. Non-root execution and a minimal trusted base image.
  2. Explicit runtime configuration and secret retrieval.
  3. Liveness and readiness probes, graceful shutdown and resource limits.
  4. Structured logs and a documented version.
Show a sample test result
  • Test: stop a worker while it processes settlement record 4,812 of 10,000.
  • Expected: the current record finishes or is released; the next task resumes; no record is processed twice and none is lost (counts match).

2 questions

Check your understanding

1. What is the difference between readiness and liveness?
2. A worker is stopped mid-message. What keeps the result correct?
Answer every question to submit.

What you can do now

  • Configure liveness, readiness and dependency health.
  • Implement graceful shutdown.
  • Keep secrets out of images and code.