0
0
Microservicessystem_design~20 mins

Docker Compose for local development in Microservices - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Compose Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
2:00remaining
Designing a Docker Compose setup for a multi-service app

You have three microservices: a frontend, a backend API, and a database. You want to run them locally using Docker Compose. Which of the following docker-compose.yml snippets correctly defines the services with proper network and volume setup for local development?

A
version: '3'
services:
  frontend:
    build: ./frontend
    ports:
      - '3000:3000'
    depends_on:
      - backend
  backend:
    build: ./backend
    ports:
      - '8000:8000'
    environment:
      - DATABASE_URL=postgres://user:pass@db:5432/app
    depends_on:
      - db
  db:
    image: postgres:15
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data: {}
B
version: '2'
services:
  frontend:
    image: node:latest
    ports:
      - '3000:3000'
  backend:
    image: python:3.9
    ports:
      - '8000:8000'
  db:
    image: postgres:latest
    volumes:
      - ./data:/var/lib/postgresql/data
C
version: '3.8'
services:
  frontend:
    build: ./frontend
    ports:
      - '3000:3000'
  backend:
    build: ./backend
    ports:
      - '8000:8000'
    environment:
      DATABASE_URL: postgres://user:pass@localhost:5432/app
  db:
    image: postgres:15
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data: {}
D
version: '3'
services:
  frontend:
    build: ./frontend
    ports:
      - '3000:3000'
    depends_on:
      - backend
  backend:
    build: ./backend
    ports:
      - '8000:8000'
    environment:
      - DATABASE_URL=postgres://user:pass@localhost:5432/app
    depends_on:
      - db
  db:
    image: postgres:15
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data: {}
Attempts:
2 left
💡 Hint

Check how services communicate using service names and how volumes are defined for persistent data.

scaling
intermediate
1:00remaining
Scaling services with Docker Compose

You want to test how your backend service handles multiple instances locally using Docker Compose. Which command correctly scales the backend service to 3 instances?

Adocker-compose up --scale backend=3
Bdocker-compose scale backend=3
Cdocker-compose run --scale backend=3
Ddocker-compose up -d backend=3
Attempts:
2 left
💡 Hint

Remember the modern syntax for scaling services with docker-compose up.

tradeoff
advanced
1:30remaining
Tradeoffs of using Docker Compose for local development

Which of the following is a common tradeoff when using Docker Compose for local development of microservices?

AIt guarantees identical performance and behavior as production environments.
BIt simplifies environment setup but may not perfectly mimic production networking and scaling.
CIt eliminates the need for any configuration files or environment variables.
DIt automatically scales services to production-level traffic without manual setup.
Attempts:
2 left
💡 Hint

Think about differences between local and production environments.

🧠 Conceptual
advanced
1:30remaining
Understanding service dependencies in Docker Compose

In Docker Compose, what does the depends_on key do when defined between services?

AIt guarantees the dependent service is fully ready and healthy before starting the current service.
BIt automatically restarts the dependent service if the current service fails.
CIt ensures the dependent service starts before the current service but does not wait for it to be ready.
DIt links the dependent service's ports to the current service.
Attempts:
2 left
💡 Hint

Consider what depends_on controls in startup order versus readiness.

estimation
expert
3:00remaining
Estimating resource usage for Docker Compose local setup

You plan to run 5 microservices locally with Docker Compose. Each service requires approximately 500MB RAM and 0.5 CPU cores. Your laptop has 8 CPU cores and 16GB RAM. Considering Docker and OS overhead, what is the maximum number of service instances you can run simultaneously without swapping or CPU throttling?

A24 instances (limited by RAM: 16GB / 0.5GB = 32, CPU limits to 8 cores * 3 instances)
B10 instances (limited by RAM: 16GB / 0.5GB = 32 but CPU limits to 8 cores * 1 instance each)
C28 instances (16GB / 0.5GB = 32 RAM, 8 cores * 3.5 instances per core CPU)
D16 instances (8 cores * 2 per core, RAM is sufficient)
Attempts:
2 left
💡 Hint

Calculate max instances by RAM and CPU separately, then take the smaller number.