HTTPS health and migration gates
You can route API traffic through Caddy and distinguish liveness from readiness, so the production stack waits for migrations before serving requests.
Learning outcomes
- Explain how Caddy provides HTTPS, redirects HTTP traffic, and routes requests to the Go API through a reverse proxy.
- Distinguish liveness from readiness and design concurrent dependency checks with independent timeouts.
- Explain how a one-shot migration job gates API startup and why application rollbacks do not necessarily reverse data changes.
- Create consistent, timestamped MySQL dumps with safe publication and retention.
- Verify database recovery by restoring a dump into an isolated database and checking its orders.
A running API container does not mean your food-delivery service is ready for customers. MySQL might still be starting, the database schema might not have been migrated, or the server might be exposing an unencrypted connection. Even when the application works, a backup nobody has restored is not a proven recovery mechanism.
You already have the Go API, worker, MySQL, Redis and Redpanda running together with Docker Compose. Now you need a deployment that controls how traffic reaches the API, when the application starts, and how you recover its database.
The public entry point
The Go API listens on port 8080 inside the Docker network. Customers should not connect directly to that container. You need a reverse proxy between the public internet and your application.
A reverse proxy accepts incoming connections and forwards requests to backend services. It can also handle TLS termination, HTTP-to-HTTPS redirects and upstream health monitoring.
For example, a customer requests:
https://api.example.com/v1/restaurantsThe request reaches Caddy first. Caddy handles the HTTPS connection and forwards the HTTP request to the Go API at api:8080. The API does not need to manage public TLS certificates.
This separation gives you two useful boundaries:
- Customers interact with a public domain and do not need to know your internal container names.
- The API and its dependencies communicate through the private Docker network.
Caddy is the only service that should be publicly accessible. MySQL, Redis, Redpanda, the API and the worker do not need public host ports.
Automatic HTTPS with Caddy
Automatic HTTPS means Caddy obtains and renews certificates without requiring you to implement certificate management in the Go application.
For a public domain, Caddy can obtain a certificate from a public certificate authority such as Let's Encrypt. Certificate issuance requires the domain to resolve to your server and the server to be reachable for domain validation.
Suppose your server has this public IPv4 address:
203.0.113.10You configure a DNS A record:
api.example.com A 203.0.113.10Three conditions matter for the initial public deployment:
- The domain's DNS record points to the server.
- Incoming connections on ports
80and443reach Caddy. - Caddy can preserve its certificate data across container recreation.
Port 80 supports HTTP requests and certificate validation. Port 443 handles HTTPS traffic.
Caddy also redirects ordinary HTTP requests to HTTPS when automatic HTTPS is enabled. You do not need to implement that redirect in the Go API.
For local practice, you do not need a public domain or server. Configure:
API_DOMAIN=localhostCaddy recognizes localhost and uses its local certificate authority. Your browser may need to trust the local CA before showing the connection as trusted.
The supplied deployment helper uses curl -k because this local certificate is not issued by a publicly trusted certificate authority. That option skips certificate verification for the test request. Do not treat it as a general-purpose production client configuration.
Caddy configuration
Caddy reads its configuration from a file named Caddyfile. You can use an environment variable for the site address so the configuration works with both localhost and a public domain.
{$API_DOMAIN} {
reverse_proxy api:8080 {
health_uri /readyz
}
}Notice two details.
First, {$API_DOMAIN} tells Caddy which domain to serve. The Caddy service must receive the corresponding API_DOMAIN environment variable.
Second, the upstream is api:8080, not localhost:8080.
Inside a container, localhost refers to that same container. It does not refer to another service. Docker Compose provides internal DNS, so Caddy can resolve the API using its service name.
The health_uri directive configures an active upstream health check. Caddy periodically requests /readyz and uses its response to determine whether the API should receive traffic.
This distinction matters because an API can respond to HTTP requests while being unable to access its dependencies. You will examine that problem through liveness and readiness.
Caddy's persistent storage
Caddy stores certificate information and other persistent state under /data. Its configuration-related state is stored under /config.
Mount named volumes for these directories:
services:
caddy:
image: caddy:2
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
api:
condition: service_healthy
volumes:
caddy_data:
caddy_config:The read-only Caddyfile mount prevents the container from modifying your source configuration. The named volumes preserve certificate and configuration data when Compose recreates the container.
Without persistent certificate storage, recreating Caddy can discard previously obtained certificates. Caddy may need to obtain them again, potentially encountering certificate authority rate limits.
The depends_on condition also has a specific meaning. Caddy waits for the API's Compose healthcheck rather than starting as soon as the API container process exists.
Network exposure
Only Caddy needs public host ports.
The other services communicate over the Compose network. This means MySQL can be reached using mysql:3306, Redis using redis:6379, and Redpanda using redpanda:9092 without exposing those ports to the internet.
For local debugging, a service can have a host port mapping bound to 127.0.0.1, but it should not be exposed on all host interfaces.
Caddy publishes ports 80 and 443. An additional UDP mapping on port 443 supports HTTP/3.
The API, worker and stateful services retain their own internal network access and healthchecks. They do not need to become public services to communicate with one another.
Liveness and readiness
A running container does not necessarily contain an application that can serve requests.
Consider the Go API. Its HTTP server might still be running even when MySQL is unavailable. A customer can establish an HTTP connection, but restaurant listings and order creation may fail.
You need two separate health endpoints because they answer different questions.
Liveness
A liveness probe answers one question:
Can the application process respond to an HTTP request?
Expose:
GET /healthzThe liveness endpoint should be cheap. It checks whether the application can respond, without contacting MySQL, Redis or Kafka.
A successful response looks like this:
HTTP/1.1 200 OK
Content-Type: application/json
{"ok":true}Why should it avoid dependency checks?
Suppose MySQL temporarily becomes unavailable because of a network problem. The Go process might be completely healthy. Restarting that process will not repair MySQL.
Worse, repeated restarts can make an existing outage harder to diagnose and recover from.
Liveness should identify a process that cannot respond. It should not treat every external dependency failure as a reason to restart the application.
Readiness
A readiness probe answers a different question:
Can the application serve requests with its current dependencies?
Expose:
GET /readyzUnlike liveness, readiness checks the dependencies configured for this deployment.
For the current backend, these are:
- MySQL: Can the application establish a database connection?
- Redis: Can the application execute a lightweight command such as
PING? - Kafka: Can the application communicate with its Redpanda broker?
The dependency clients already support context-aware operations.
For example:
err := db.PingContext(ctx)For Redis:
err := client.Ping(ctx).Err()For the franz-go Kafka client:
err := client.Ping(ctx)Each operation receives a context so that a slow dependency cannot block readiness indefinitely.
Suppose MySQL and Redis are reachable, but Kafka is unavailable. The application should still report the healthy dependencies while identifying Kafka as unavailable.
The readiness response should distinguish the overall status from individual dependency results:
{
"status": "unavailable",
"failing": ["kafka"],
"checks": {
"kafka": "unavailable",
"mysql": "ok",
"redis": "ok"
}
}The HTTP status is 503 Service Unavailable.
When every configured dependency succeeds, the response uses:
{
"status": "ok",
"checks": {
"kafka": "ok",
"mysql": "ok",
"redis": "ok"
}
}The HTTP status is 200 OK.
The failing field is omitted when there are no failures. When failures exist, sort their names before constructing the response. Deterministic output makes monitoring and tests easier to reason about.
Never include the actual dependency error in the response. A connection error might contain a private IP address, database hostname or password. Record the failure on the server using slog, and return only the dependency name and availability status to the client.
Concurrent dependency checks
Checking dependencies sequentially makes readiness unnecessarily slow.
Suppose the MySQL check takes 150 ms, Redis takes 150 ms, and Kafka takes another 150 ms. A sequential implementation takes approximately 450 ms.
You can run independent checks concurrently instead.
The health package can represent each dependency check with a named function:
type Check func(ctx context.Context) errorThe API registration code constructs a map of checks. The handler does not need to know which database driver or Redis client each function uses.
The handler receives a timeout and the configured checks:
handler := health.Readyz(2*time.Second, checks)Each check needs its own timeout context.
You can use Go contexts to enforce this deadline. A context carries cancellation and deadline information into the dependency client.
ctx, cancel := context.WithTimeout(parent, timeout)
defer cancel()
err := check(ctx)The parent context comes from the incoming HTTP request. This means request cancellation also reaches the dependency check.
Create a separate timeout context inside each check's goroutine. Do not create one context outside the loop and accidentally make all checks share a single deadline.
Shared results
Concurrent checks need a safe way to record their results.
A sync.WaitGroup lets the handler wait until all checks finish. A mutex protects the results map while goroutines update it.
The conceptual sequence is:
- Create an empty results map.
- Start one goroutine for each configured dependency.
- Create that dependency's timeout context.
- Execute the check.
- Record
okorunavailableunder a mutex. - Wait for all checks to finish.
- Collect and sort the failing dependency names.
- Construct the HTTP response.
The important part is that the checks run independently. One slow dependency should not prevent another healthy dependency from completing.
With three checks taking approximately 150 ms each, concurrent execution should finish in approximately 150 ms plus scheduling and response overhead, rather than approximately 450 ms.
An independent timeout also bounds the wait for a dependency that respects its context. If a check returns ctx.Err() after its deadline, the handler records that dependency as unavailable.
There is an important qualification: a context cannot forcibly terminate an arbitrary function. A check must pass its context to an operation that observes cancellation. A function that ignores its context can continue running after the deadline.
Dependency registration
The API configures health checks using its existing environment variables:
MYSQL_DSN
REDIS_ADDR
KAFKA_BROKERSOnly configure a dependency check when its corresponding variable is present.
For MySQL, use database/sql and PingContext. For Redis, use the go-redis client's Ping method. For Kafka, construct a franz-go client from the configured broker addresses and use its connectivity check.
Keep this client configuration in backend/cmd/api/health.go. The reusable HTTP handlers belong in backend/internal/health/health.go.
The router then registers the two endpoints using the health package:
r.Method(http.MethodGet, "/healthz", health.Healthz())
r.Method(
http.MethodGet,
"/readyz",
health.Readyz(2*time.Second, checks),
)Replace the old inline health route with the health registration function.
The separation gives the health package responsibility for HTTP behaviour while the API executable owns dependency configuration.
Container healthchecks
Docker Compose can periodically execute a healthcheck inside a container.
A service moves through three relevant states:
- Starting: The healthcheck has not succeeded yet.
- Healthy: The healthcheck has succeeded.
- Unhealthy: The configured number of consecutive checks has failed.
You should use the API's liveness endpoint for its Compose healthcheck.
There is a problem with the production image, however. The API uses a distroless runtime stage. It does not include ordinary shell utilities such as curl, wget or /bin/sh.
This command is therefore unsuitable:
healthcheck:
test:
- CMD-SHELL
- curl -f http://localhost:8080/healthzIt assumes that the container has a shell and curl. The production image has neither.
Instead, the Go executable provides a -healthcheck mode. When invoked with that flag, it sends an HTTP request to its own /healthz endpoint and exits with status zero only when the response is HTTP 200.
The Compose healthcheck can invoke the executable directly:
healthcheck:
test: ["CMD", "/api", "-healthcheck"]
interval: 10s
timeout: 3s
retries: 3The CMD form executes the binary without starting a shell. The healthcheck must not start another application HTTP server.
Caddy's upstream health check and the API's Compose healthcheck have different responsibilities:
- The API healthcheck uses liveness to determine whether the application process responds.
- Caddy checks readiness to determine whether the application can currently receive traffic.
A Compose healthcheck also does not automatically restart a container merely because it becomes unhealthy. Restart policies and health states are separate mechanisms.
Database migration jobs
The API depends on a MySQL schema containing tables for users, restaurants, menu items, orders and other project entities.
When the schema changes, you need to apply the corresponding migrations before starting a new API version against it.
A migration job is a separate, one-shot container that applies database migrations and then exits.
You already use golang-migrate to manage versioned schema changes. Each migration has an up file and, where reversal is possible, a down file.
For example, the migration directory contains pairs of SQL files:
backend/db/migrations/
0001_example.up.sql
0001_example.down.sql
0002_example.up.sql
0002_example.down.sqlAn up migration applies a schema change. A down migration describes how to reverse it.
The migration tool records which versions have been applied. On a later deployment, it can identify pending migrations rather than executing every migration again.
Migration service
The official migrate/migrate image can execute migrations independently of the API.
A simplified service looks like this:
services:
migrate:
image: migrate/migrate:latest
restart: "no"
volumes:
- ./db/migrations:/migrations:ro
command:
- "-path=/migrations"
- "-database=mysql://root:${MYSQL_ROOT_PASSWORD}@tcp(mysql:3306)/zomato"
- "up"
depends_on:
mysql:
condition: service_healthyThe migration directory is mounted read-only. The database URL uses the MySQL root password supplied through the Compose environment.
The command runs pending migrations and exits when it finishes.
Notice the startup dependency:
depends_on:
migrate:
condition: service_completed_successfullyThis condition allows a dependent service to start only after the migration service exits successfully.
The full deployment has several dependencies:
- MySQL starts and passes its healthcheck.
- Redis and Redpanda start and pass their healthchecks.
- The migration service waits for healthy MySQL.
- The migration service applies pending migrations and exits successfully.
- The API and worker start after their infrastructure dependencies are healthy and migration completion is successful.
- Caddy waits for the API to become healthy.
The worker also needs the migrated schema. Starting the worker before migrations finish can cause database queries against tables or columns that do not exist yet.
A healthy MySQL container alone does not prove that the application schema is ready. Container health and migration completion represent different conditions.
The migration service uses restart: "no" because it is a job, not a long-running application process.
Deployment coordination
Why not run migrations whenever an API process starts?
Imagine deploying three API replicas at the same time. Each instance attempts to apply migrations during startup. The database can then receive multiple concurrent migration attempts.
Migration tools can provide locking, but making every application instance responsible for schema changes adds coordination and failure-handling complexity.
A dedicated migration job gives schema changes one controlled execution point.
Manual migration commands introduce another problem. Someone must remember to run the correct command before starting the API. A missed migration can leave the application running against an incompatible schema.
With Compose dependency conditions, the migration job becomes part of the deployment's startup contract.
Migration rollback considerations
A down migration can reverse a schema change, but it cannot necessarily recover the data that was removed or overwritten.
Suppose an up migration adds a column for a new customer preference. The new application version starts writing values into that column. A later down migration drops the column.
The column disappears, and its contents disappear with it.
It is useful to distinguish three operations:
- Schema rollback: Apply a down migration to reverse a schema change.
- Application rollback: Deploy a previously working application version.
- Data recovery: Restore database contents from a backup or another recovery mechanism.
These operations are related, but they are not interchangeable.
A safer deployment strategy uses backward-compatible migrations. Add a new column first, deploy code that can work with both representations, migrate existing data, and remove obsolete columns in a later deployment.
This approach reduces the risk that an application rollback becomes impossible because the newer schema is incompatible with the older binary.
Never assume that running a down migration restores every affected application record.
Logical database backups
Even a correctly deployed application can lose data.
An accidental deletion, database corruption or server failure can destroy orders and customer information. Your deployment therefore needs a separate mechanism for database recovery.
A logical backup exports database objects and their data as SQL statements.
MySQL provides mysqldump for this purpose. Unlike copying MySQL's internal data directory, a logical dump can be inspected and loaded into another compatible MySQL database.
For the project's zomato database, a consistent dump uses:
mysqldump \
--single-transaction \
--routines \
--triggers \
-h mysql \
-u root \
zomatoThe flags have specific purposes:
--single-transactioncreates a consistent snapshot for transactional tables such as InnoDB without requiring a long-running table lock.--routinesincludes stored procedures and functions.--triggersincludes database triggers.
The MySQL user needs the appropriate permissions to read the database and export these objects.
--single-transaction has a limitation. It does not guarantee a consistent backup of non-transactional tables. Concurrent schema changes can also interfere with the dump. Coordinate schema changes with backup execution.
Database credentials
The backup script needs the MySQL root password to authenticate.
Putting the password directly into a command-line argument can expose it in process listings or command logs. Instead, export it through the MYSQL_PWD environment variable for the child process.
if [ -z "${MYSQL_ROOT_PASSWORD:-}" ]; then
printf '%s\n' "MYSQL_ROOT_PASSWORD is required" >&2
exit 1
fi
export MYSQL_PWD="$MYSQL_ROOT_PASSWORD"The mysqldump invocation can then use -u root without adding the password to its arguments.
The script should use these defaults:
: "${BACKUP_DIR:=/backups}"
: "${KEEP:=7}"
: "${MYSQL_HOST:=mysql}"
: "${DB_NAME:=zomato}"
: "${BACKUP_TIMESTAMP:=$(date -u +%Y%m%dT%H%M%SZ)}"The timestamp is in UTC. A test run with a fixed timestamp such as 20261104T020000Z should produce:
/backups/zomato-20261104T020000Z.sql.gzThis naming convention makes backup files easy to identify and sort chronologically.
The scripts must use POSIX sh syntax because they are executed through sh. Do not use Bash-only features such as arrays or rely on set -o pipefail.
Safe backup publication
Creating a dump and publishing a successful backup are two different operations.
Suppose mysqldump fails halfway through its output. A direct pipeline into the final .sql.gz filename might leave a partial file that looks like a completed backup.
You should not update latest.sql.gz until the entire dump and compression process succeeds.
Use temporary files in the backup directory:
raw_file=$(mktemp "$BACKUP_DIR/.backup-raw.XXXXXX")
compressed_file=$(mktemp "$BACKUP_DIR/.backup-gzip.XXXXXX")
mysqldump --single-transaction --routines --triggers \
-h "$MYSQL_HOST" -u root "$DB_NAME" > "$raw_file"
gzip -c "$raw_file" > "$compressed_file"Each command has its own exit status. If either command fails, the backup script must stop and remove its temporary files.
After compression succeeds, publish the completed backup:
mv "$compressed_file" "$destination"Using a temporary file in the same directory allows the rename to publish a complete file without exposing partially compressed output under the final filename.
Install a cleanup trap so temporary files are removed when the script exits, including after a failed dump or compression operation.
The previous latest.sql.gz pointer must remain unchanged when backup creation fails.
The latest backup pointer
The file latest.sql.gz identifies the most recently published successful backup.
You can implement it as a relative symbolic link:
latest.sql.gz -> zomato-20261104T020000Z.sql.gzA relative link keeps the pointer valid when the volume is mounted at the same location in another container.
Create the new link only after the completed backup has been published. Replace the previous pointer atomically using a temporary link and a rename.
Do not point latest.sql.gz at a temporary file. Do not replace a previously valid pointer when a new dump fails.
Retention
Keeping every backup forever causes the backup volume to grow indefinitely.
Retention defines how many completed backups remain available.
The script defaults to KEEP=7. A configured value of KEEP=3, for example, means that only the three newest matching dumps should remain.
Timestamp filenames use a format that sorts chronologically. You can therefore sort the matching files in reverse filename order and retain the newest configured number.
The deletion pattern must be narrow:
zomato-*.sql.gzNever delete every file in the backup directory. It might contain manually created notes or other unrelated files.
For example:
/backups/
latest.sql.gz
zomato-20261103T020000Z.sql.gz
zomato-20261104T020000Z.sql.gz
notes.txtWith KEEP=1, the older matching dump can be removed while notes.txt remains untouched.
Run retention only after a successful backup has been published. A failed backup should not cause a previously useful history to be pruned.
The nightly backup service
A backup script that someone must execute manually is not a complete scheduling mechanism.
You can run the script in a dedicated Docker Compose service using mysql:8.4. That image includes both mysqldump and the MySQL client.
The backup service needs its own persistent named volume and read-only access to the scripts:
services:
backup:
image: mysql:8.4
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_HOST: mysql
volumes:
- backups:/backups
- ./scripts:/scripts:ro
depends_on:
mysql:
condition: service_healthy
volumes:
backups:The service waits until MySQL is healthy before starting. Its scripts are mounted read-only so the container can execute them without modifying the source files.
The named volume preserves backups when the backup container is recreated.
Scheduling at 02:00 UTC
The backup service needs to remain running and execute the script every night at 02:00 UTC.
Calculate the current Unix timestamp and the timestamp for the next scheduled run. If today's 02:00 UTC has already passed, calculate tomorrow's scheduled time.
The core scheduling logic looks like this:
while :; do
now=$(date -u +%s)
target=$(date -u -d 'today 02:00' +%s)
if [ "$target" -le "$now" ]; then
target=$(date -u -d 'tomorrow 02:00' +%s)
fi
sleep "$((target - now))"
sh /scripts/backup.sh
doneThis uses a UTC clock, so the backup does not depend on the server's local timezone.
The Compose service can run this loop through /bin/sh -c. Because Compose performs its own environment-variable interpolation, dollar signs intended for the container shell must be written as $$ in the Compose command.
After each backup completes, the loop calculates the next scheduled run. The container remains alive rather than exiting after one backup.
The service uses restart: unless-stopped so Docker can restart the scheduler after an unexpected container exit.
A running scheduler is not proof of a successful backup. Monitor backup creation and periodically verify recovery.
Restore tests
A successful dump command does not prove that the database can be recovered.
The gzip file might be incomplete, SQL statements might fail during import, or an important table might be absent.
A restore test proves that a backup can be loaded into a separate database and that the resulting data is usable.
Never test recovery by overwriting the live zomato database. Use a fresh database with a separate name, such as restore_test.
Preparing the restore database
The restore script first validates its configuration.
It uses BACKUP_DIR and MYSQL_HOST, requires MYSQL_ROOT_PASSWORD, and defaults RESTORE_DB to restore_test.
It should also reject a restore database name equal to zomato. Otherwise, a mistake in the configuration could destroy the live database.
Before connecting, check that the latest backup exists:
backup="$BACKUP_DIR/latest.sql.gz"
if [ ! -f "$backup" ]; then
printf '%s\n' "No backup found" >&2
exit 1
fiThere is no point attempting a restoration when no backup has been published.
Next, establish a cleanup trap and recreate the isolated database:
DROP DATABASE IF EXISTS restore_test;
CREATE DATABASE restore_test;Dropping an earlier test database prevents the new restore from mixing with data from a previous run.
The cleanup trap must drop restore_test when the script finishes, whether restoration succeeds or fails.
Loading and verifying the dump
Use gunzip -c to write the decompressed SQL to standard output. Pipe that output to the MySQL client, targeting only the restore database.
gunzip -c "$backup" |
mysql -h "$MYSQL_HOST" -u root "$RESTORE_DB"The live zomato database must not appear as the target of this import.
After loading the dump, query the orders table:
SELECT COUNT(*) FROM orders;The MySQL client's batch mode and --skip-column-names option make it easier to capture the numeric result in a shell variable.
The script should print the count and reject an empty result or a count of zero.
For example:
125This indicates that 125 orders were restored into the test database.
A zero count means the restore did not meet the exercise's verification requirement. The script must exit non-zero rather than reporting success.
The count does not prove that every row or relationship is correct. It is a basic sanity check that the expected table exists and contains data. A more thorough recovery test can verify sample orders, relationships and other database objects.
Cleanup after failure
Cleanup must run on every exit path, not only after a successful import.
A shell trap lets you register a cleanup function:
cleanup() {
mysql -h "$MYSQL_HOST" -u root \
-e "DROP DATABASE IF EXISTS \`$RESTORE_DB\`"
}
trap cleanup 0The exit trap runs when the script finishes. Signal handling should also allow the script to exit through its cleanup path.
This matters because a failed import can leave a partially populated database behind. Repeated test runs should start from a fresh database rather than accidentally reusing that partial state.
There are two separate safety requirements:
- The script must never drop, recreate or import into the live
zomatodatabase. - The temporary restore database must be cleaned up even when verification fails.
The restore script should use MYSQL_PWD for authentication, just like the backup script. Do not put the root password directly into MySQL command-line arguments.
Recovery objectives
A backup policy needs to account for both potential data loss and recovery time.
Recovery Point Objective (RPO) describes how much data loss, measured in time, the business can tolerate after a failure.
Suppose backups run every night at 02:00 UTC. If the MySQL server fails at 01:50 the following night, the newest available dump might be almost 24 hours old.
Changes made after that backup may be lost.
If the business requires losing no more than one hour of data, nightly backups alone do not satisfy that requirement. You need a more frequent backup or another recovery mechanism that meets the same objective.
Retention does not directly change the RPO. Keeping thirty days of nightly dumps gives you more historical recovery points, but it does not reduce the time between consecutive backups.
Recovery Time Objective (RTO) describes how long the business can tolerate the application being unavailable while you recover it.
Suppose your latest database dump takes six hours to restore. A business that needs the application available again within thirty minutes cannot meet its recovery requirement with that procedure alone.
RTO depends on more than the existence of a backup. It includes the time required to provision the database, transfer the dump, restore its contents and verify the application.
These objectives influence backup frequency, retention, storage and restore procedures.
Backup location
A named Docker volume protects backup files against ordinary container recreation. It does not protect them against every server failure.
If MySQL and its backup volume live on the same physical server, a disk failure can destroy both the database and its backups.
Production systems commonly copy encrypted backups to separate storage. They also verify successful transfers and periodically restore backups from that separate location.
For this course, the local backups volume is sufficient to exercise the complete workflow. You do not need an external storage account to perform the backup and restore tests.
The important distinction is that backup creation, backup storage and recovery verification are three separate responsibilities.
Deployment and recovery boundaries
The production stack has several independent conditions that must hold before you consider it operational.
The public entry point must use HTTPS. Caddy must route traffic only to the API service, and its upstream health check must use readiness rather than liveness.
The API must respond to its liveness endpoint without depending on MySQL, Redis or Kafka. Its readiness endpoint must execute configured dependency checks concurrently, apply independent timeouts and report unavailable dependencies without exposing internal errors.
The migration job must finish successfully before the API and worker start. A healthy database container does not guarantee that the application schema is ready.
Finally, the backup service must publish complete compressed dumps, maintain a safe latest.sql.gz pointer, apply bounded retention and allow restoration into an isolated database.
The exercise Production HTTPS Compose stack brings the HTTPS, healthcheck and migration boundaries together. It uses backend/Caddyfile, backend/compose.prod.yml, the health package and the API's healthcheck mode.
The next exercise, Nightly mysqldump and one restore test, adds the scheduled backup service and the two recovery scripts. It extends the same production Compose configuration rather than replacing the existing services.
These two exercises establish different parts of production operation. One controls how the application becomes available. The other verifies that its persistent data can be recovered.
Check your understanding
MySQL is reachable, Redis is reachable, but the Redpanda broker becomes unavailable. The API process is still responding normally. What should happen when Caddy checks the API's readiness?
References
Everything above is explained on this page; these are where it comes from (Caddy, Docker Compose, MySQL).