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.
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=25sFor 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 unreachable | API service | Settlement worker |
|---|---|---|
| Readiness | Not ready: the load balancer stops sending it requests, so callers get a fast 503 from healthy tasks or the gateway instead of timeouts | Not about traffic: the worker pauses polling, so messages stay in the queue and return after their visibility timeout |
| Liveness | Stays healthy; no restart, because a restart cannot fix the database | Stays healthy; no restart loop |
| Recovery | Ready again automatically when the database answers | Resumes polling with backoff; idempotent processing makes redelivered messages safe |
| What to alert on | The readiness failure and the 503 rate | The 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.
- Non-root execution and a minimal trusted base image.
- Explicit runtime configuration and secret retrieval.
- Liveness and readiness probes, graceful shutdown and resource limits.
- 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
What you can do now
- Configure liveness, readiness and dependency health.
- Implement graceful shutdown.
- Keep secrets out of images and code.