Skip to content

ADR-0002. One deployable, split into api and worker roles at runtime

FieldValue
StatusAccepted
Date2026-03-30
Decidersledger-team
Supersedes

Context

  • The REST surface (enqueue, lifecycle, download) and the heavy generation pipeline have very different resource and scaling profiles.
  • Bundling everything into every replica wastes CPU on API pods and couples ingress to render capacity.
  • Splitting into two separate packages would duplicate schemas, DI wiring, and deployment plumbing.

Decision

We will ship a single image and select behavior at boot with APP_ENV_APPLICATION_ROLES (CSV of api, worker; invalid/empty falls back to both). configureControllers() registers controllers only for api; configureServices()/configureComponents() register the worker pipeline (LedgerWorkerService, generators), the WebSocket emitter, and the recovery sweep only for worker. The Kafka consumer and recovery components are registered unconditionally but self-skip when the worker role is absent.

Consequences

ProsCons
Scale API and worker independentlyRole gating spread across application.ts + components
One image, one CI artifact, shared schema/DIA misconfigured APP_ENV_APPLICATION_ROLES silently falls back to both
worker-only pods need no ingressMust verify role in two places (registration + component self-skip)

Alternatives Considered

OptionProsConsWhy rejected
Two separate packagesHard isolationSchema/DI duplication, double deployToo much duplication for one bounded context
Always run both roles per replicaSimplest configWasted CPU on API pods; coupled scalingDefeats the purpose of the split
Feature flags per componentFine-grainedCombinatorial config surfaceTwo coarse roles cover all real topologies

References

  • ledger/src/common/roles.ts (getAppRoles)
  • ledger/src/application.ts (configureComponents/Services/Controllers)
  • ledger/src/components/kafka.component.ts, recovery.component.ts (self-skip)
  • Configuration

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.