Skip to main content

Communication Service Deployment

Docker Deployment

Dockerfile

The service includes a production-ready Dockerfile.

Build Image

cd shared/communication
docker build -t communication:latest .

Run Container

docker run -d \
--name communication \
-p 8010:8010 \
-e DATABASE_URL=postgresql://user:pass@postgres:5432/communication \
-e REDIS_URL=redis://redis:6379 \
communication:latest

Docker Compose

The service is included in infra/compose.yml:

communication:
build: ./shared/communication
ports:
- "8010:8010"
environment:
- DATABASE_URL=postgresql://user:pass@postgres:5432/communication
- REDIS_URL=redis://redis:6379
depends_on:
- postgres
- redis

Production Deployment

Prerequisites

  • PostgreSQL 14+ database
  • Redis instance for Oban
  • Environment variables configured

Steps

  1. Build Release:
cd shared/communication
MIX_ENV=prod mix release
  1. Run Migrations:
_build/prod/rel/communication/bin/communication eval "Communication.Release.migrate()"
  1. Start Service:
_build/prod/rel/communication/bin/communication start

Systemd Service

Create /etc/systemd/system/communication.service:

[Unit]
Description=Communication Service
After=network.target postgresql.service redis.service

[Service]
Type=simple
User=communication
WorkingDirectory=/opt/communication
ExecStart=/opt/communication/bin/communication start
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Health Checks

The service exposes health check endpoints:

  • GET /health - Basic health check
  • GET /health/detailed - Detailed health including database and Redis

Monitoring

Metrics

Prometheus metrics are available at /metrics.

Logging

Logs are written to stdout/stderr. Configure log aggregation in production.

Scaling

The service can be horizontally scaled:

  1. Run multiple instances behind a load balancer
  2. Ensure all instances connect to the same PostgreSQL and Redis
  3. Oban will distribute jobs across instances

Backup

Database Backup

pg_dump -h localhost -U user communication > backup.sql

Template Backup

Templates are stored in PostgreSQL, so database backup includes them.