ADR-002: Separate API and worker processes (same image)


Sep 28, 2026

ACCEPTED

Md Khaled Bin Joha

Status

Accepted

Date

2026-07-24

Context

OCR and hold-expiry workers currently start inside the API process (src/index.ts). Killing OCR for chaos experiments or deploys also kills HTTP. Game-day scenario “stop worker, API stays healthy” requires process isolation.

Decision

Ship one Docker image with two entrypoints:

  • api — Express HTTP only (src/index.ts)
  • worker — OCR + hold-expiry (src/worker.ts)

Compose runs both services sharing env and the same image. Shared loadEnv and shutdown helpers avoid divergent init.

Alternatives Considered

Keep in-process workers

  • Pros: Simpler Compose; one process to operate
  • Cons: Cannot isolate OCR failures from API availability
  • Rejected for chaos-lite / ops goals

Separate worker image

  • Pros: Smaller worker footprint possible
  • Cons: Dual build/cache; drift risk
  • Rejected for closed-beta simplicity

Consequences

  • Dockerfile CMD (or Compose command) selects entrypoint
  • API /health unchanged; worker liveness via process + queue depth logs
  • Primary enabler for game day #2 and resilience worker-crash tests
  • See Phase 5 in tasks/plan.md