Cloud Engineer: Deterministic Multi-Service Local Environments with Docker Compose Healthcheck DAGs

Nothing slows down a distributed engineering team faster than a brittle local development setup where Django or Go API containers crash on boot because PostgreSQL 16, Redis 7, or Google Cloud Pub/Sub emulators have not finished initializing TCP listeners and database migrations. As a Cloud Engineer and Full Stack Engineer, I design deterministic, offline-capable Docker Compose topologies driven by readiness healthcheck Directed Acyclic Graphs (DAGs), ephemeral migration init-containers, and cloud emulator parity.

1. Why Naive depends_on Lists Fail in Multi-Service Stacks

A basic depends_on: [postgres, redis] clause only waits for the container process PID 1 to start—not for PostgreSQL to finish WAL recovery or accept connections on port 5432. By combining explicit healthcheck probes with condition: service_healthy and condition: service_completed_successfully, we enforce strict startup ordering identical to Kubernetes initContainers:

# docker-compose.yml
services:
  postgres:
    image: pgvector/pgvector:pg16
    environment:
      POSTGRES_DB: afcom_dev
      POSTGRES_USER: afcom
      POSTGRES_PASSWORD: local_dev_password
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U afcom -d afcom_dev"]
      interval: 3s
      timeout: 3s
      retries: 10

  redis:
    image: redis:7.2-alpine
    command: ["redis-server", "--appendonly", "yes"]
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 3s
      timeout: 2s
      retries: 10

  pubsub-emulator:
    image: gcr.io/google.com/cloudsdktool/google-cloud-cli:emulators
    command: ["gcloud", "beta", "emulators", "pubsub", "start", "--host-port=0.0.0.0:8085"]
    ports:
      - "8085:8085"
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://localhost:8085/ || exit 1"]
      interval: 4s
      timeout: 3s
      retries: 10

  db-migrate:
    build:
      context: .
      target: runtime
    command: ["python", "django/manage.py", "migrate", "--noinput"]
    environment:
      DATABASE_URL: postgres://afcom:local_dev_password@postgres:5432/afcom_dev
    depends_on:
      postgres:
        condition: service_healthy
    restart: "no"

  backend-api:
    build:
      context: .
      target: runtime
    command: ["uvicorn", "core.asgi:application", "--host", "0.0.0.0", "--port", "8000", "--reload"]
    environment:
      DATABASE_URL: postgres://afcom:local_dev_password@postgres:5432/afcom_dev
      REDIS_URL: redis://redis:6379/0
      PUBSUB_EMULATOR_HOST: pubsub-emulator:8085
    ports:
      - "8000:8000"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      pubsub-emulator:
        condition: service_healthy
      db-migrate:
        condition: service_completed_successfully
volumes:
  pgdata:

2. Automated Topic & Bucket Seeding for Offline Cloud Parity

When developing event-driven microservices offline, applications expect Google Cloud Pub/Sub topics, subscriptions, and S3/GCS buckets to exist before workers subscribe. We pair the emulator with a lightweight Python bootstrapper that idempotently provisions local topics and dead-letter subscriptions so engineers can run full integration test suites on an airplane without internet access.

3. Bridging Local Compose Topologies to Production Cloud Run & GKE

By sharing the exact same multi-stage Dockerfile across local Compose development, GitHub Actions CI integration matrices, and production AWS & GCP Cloud Engineer architectures or Kubernetes & Helm deployments, we eliminate "works on my machine" drift completely.

Need a Cloud Engineer or Backend Engineer to standardize your team's local Docker Compose and CI/CD pipelines? Book a 1-Day Engineering Sprint.


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs