An intermediate Coolify scenario that deploys a complete order processing backend as microservices.
ACME Corp's e-commerce platform needs an order processing backend. The REST API handles incoming orders, a background worker processes payments and sends notifications. PostgreSQL stores orders, Redis handles job queues and caching.
All services are deployed to a single Coolify server, connected via internal Docker networking, and managed entirely through Terraform.
| # | Resource | Type | Purpose |
|---|---|---|---|
| 1 | coolify_project.acme |
Project | Groups all order-processing resources |
| 2 | coolify_database_postgresql.orders |
Database | Stores orders, customers, payments |
| 3 | coolify_database_redis.queue |
Database | Job queues and response caching |
| 4 | coolify_application_dockerfile.api |
Application | REST API built from a Dockerfile |
| 5 | coolify_application_docker_image.worker |
Application | Background worker from a Docker image |
| 6 | coolify_environment_variable.api_db_url |
Env var | Connects the API to PostgreSQL |
| 7 | coolify_environment_variable.api_redis_url |
Env var | Connects the API to Redis |
| 8 | coolify_environment_variable.worker_db_url |
Env var | Connects the worker to PostgreSQL |
| 9 | coolify_environment_variable.worker_redis_url |
Env var | Connects the worker to Redis |
| 10 | coolify_scheduled_task.cleanup |
Scheduled task | Nightly cleanup of old orders |
| 11 | coolify_database_backup.orders |
Backup | Daily local backup of the orders DB |
┌─────────────────────────────────────────────┐
│ Coolify Server │
│ │
HTTP requests ──────►│ ┌──────────────────┐ │
│ │ API (Dockerfile)│──┐ │
│ │ :3000 │ │ │
│ └──────────────────┘ │ │
│ │ │ │
│ env vars env vars │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────┐ ┌──────────────┐ │
│ │PostgreSQL│ │ Redis │ │
│ │ :5432 │ │ :6379 │ │
│ └──────────┘ └──────────────┘ │
│ ▲ ▲ │
│ env vars env vars │
│ │ │ │
│ ┌──────────────────┐ │ │
│ │ Worker (Docker │──┘ │
│ │ Image) :8080 │ │
│ └──────────────────┘ │
│ │
│ ┌──────────────────┐ ┌────────────────┐ │
│ │ Scheduled Task: │ │ Daily Backup: │ │
│ │ nightly-cleanup │ │ orders DB │ │
│ └──────────────────┘ └────────────────┘ │
└─────────────────────────────────────────────┘
- A running Coolify instance (v4+)
- An API token (Security > API Tokens)
- A registered server UUID (Settings → Servers)
- Terraform ≥ 1.0
# Initialize providers
terraform init
# Preview the plan
terraform plan \
-var="coolify_endpoint=https://coolify.example.com" \
-var="coolify_token=your-api-token" \
-var="server_uuid=your-server-uuid"
# Apply
terraform apply \
-var="coolify_endpoint=https://coolify.example.com" \
-var="coolify_token=your-api-token" \
-var="server_uuid=your-server-uuid"Or use a terraform.tfvars file:
coolify_endpoint = "https://coolify.example.com"
coolify_token = "your-api-token"
server_uuid = "your-server-uuid"- Project: a
coolify_projectgroups all resources under "acme-orders". - Databases: PostgreSQL stores order data; Redis provides job queues and caching. Both are internal-only (not publicly exposed).
- API application: built from a Dockerfile (
coolify_application_dockerfile). Environment variables inject the database and Redis connection strings. - Worker application: deployed from a pre-built Docker image
(
coolify_application_docker_image). Shares the same database and Redis connections so it can pick up jobs enqueued by the API. - Scheduled task: a
coolify_scheduled_taskruns a nightly cleanup command inside the API container. - Backup: a
coolify_database_backupschedules daily local backups of the PostgreSQL database.
terraform destroy \
-var="coolify_endpoint=https://coolify.example.com" \
-var="coolify_token=your-api-token" \
-var="server_uuid=your-server-uuid"coolify_application_dockerfile: Coolify builds the image from a Dockerfile you provide. Use this when you have source code and a build step.coolify_application_docker_image: Coolify pulls a pre-built image from a registry (Docker Hub, GHCR, etc.). Use this for off-the-shelf images or images built by your CI/CD pipeline.
A coolify_scheduled_task runs a shell command inside an application container
on a cron schedule. Tasks are useful for maintenance jobs (cleanup, reports,
health checks) without deploying a separate cron container.
In Coolify, a resource's name doubles as its Docker container name and
internal DNS hostname. Services on the same server can reach each other
using <name>:<port>, so no public exposure is needed. This scenario connects
the API and worker to PostgreSQL and Redis entirely through internal
environment variables.