Skip to main content

Task Interleaving

task-interleaving is a WES-tier Supporting bounded context of the warehouse-systems fleet. When a station completes a task, it looks at the open tasks of the site, ranks them by how far each one starts from where the operator now stands, and issues an interleaving hint: a short, ranked, expiring list of candidate tasks. Operators chain compatible work instead of walking empty.

The hint is advisory. fulfillment-execution stays pull-based (claimNext(stationId, capabilities) remains its only claim path) and may use a hint only as a tie-break inside one priority band, failing open when the hint is absent, expired or unknown. This context never assigns work and never writes task state (ADR 0001).

:::info What runs on develop The service merged to develop in PR #7: one binary, cmd/api, with a chi REST adapter (RFC 7807 problems, Idempotency-Key middleware), Postgres repositories with embedded migrations, a transactional outbox with a Kafka relay, a hint-expiry worker, and two Kafka consumers (fulfillment-execution and facility-layout) with retry, a dead-letter topic and processed-event de-duplication. It runs on real Postgres and real Kafka only: there is no in-memory mode, the consumers and the relay are always on, and DATABASE_URL, KAFKA_BROKERS and both consumer group ids are mandatory (ADR 0006).

Also built: a read-only MCP server (cmd/mcp, ADR 0007), a read-only A2A server (cmd/a2a, ADR 0009), the analytics read side (cmd/ti-projector and cmd/ti-reports over a separate analytical database, ADR 0008) and the task_interleaving_mfe web remote (web/).

Packaged: a Dockerfile that builds every cmd/*, a web image and the Helm chart charts/task-interleaving (optional mcp, a2a, analytics and frontend components, off by default).

Instrumented: cmd/api registers five OpenTelemetry metrics (three hint lifecycle counters, a recommender-duration histogram and a Kafka consumer-lag histogram) and serves them on GET /metrics through the OTel Prometheus exporter; the A2A adapter starts one OpenTelemetry span per skill call, but no binary installs a tracer provider, so no span is recorded or exported (Observability).

Wired around it (read on each repository's origin/develop, 2026-11-09): warehouse-infra registers the service in terraform/apps.yaml (database, analytics secret and the task_interleaving_mfe web remote) and switches on its mcp, a2a, analytics and frontend components in helm-values/task-interleaving.yaml; warehouse-console registers the remote and a Hint Adoption report; and fulfillment-execution consumes InterleavingHintIssued. Whether the cluster currently runs any of it is not verified here. Not wired: the infra values file does not set metrics.prometheus.enabled, so the chart renders no pod scrape annotations for /metrics. The Runbook and Integration pages say exactly where each edge stands. :::

What the context owns​

ConceptWhere it livesRule in one line
InterleavingPolicy (one per site)internal/domain/policyHow far (MaxDetourM), how many (MaxCandidates, 1 to 5), how long (HintTTL), which task types, how much vertical travel weighs. A site with no policy is inert: no hint.
StationTrip (one per station)internal/domain/stationtripWhere the operator stands (the end of the last completed task) and the most recent hint: Active, Consumed, Expired or Superseded. At most one Active hint.
Recommenderinternal/domain/recommendPure function: same pool in any order, same ranked candidates. Rank by detour, then task id.
Travel modelinternal/domain/travelThe port that measures distance; v1 is rectilinear-v1: |dx| + |dy| + verticalWeight * |dz|, metres, rounded to 0.1 m. Unknown geometry is unknown, never 0.
Local copiestask_pool, zones, locations tablesEvent-fed read models of the open-task pool (from fulfillment-execution) and of location geometry (from facility-layout); not aggregate state (ADR 0003).

Classification and tier​

  • Supporting subdomain. The detour rule is a replaceable policy object behind a port, and the output is advisory; the competitive core stays the WES conductor and the task lifecycle (Subdomain classification).
  • WES tier, CloudEvents subdomain segment wes: types look like com.warehouse.wes.task-interleaving.<entity>.<EventName>.

Main capabilities​

  1. Declare a per-site policy with optimistic concurrency (PUT /sites/{siteId}/policy, If-Match / ETag).
  2. Keep the open-task pool and the location geometry current from Kafka (TaskAvailable, TaskClaimed, TaskCompleted; zone, location and geometry events), always on.
  3. After a TaskCompleted, record the station's position and issue a hint of up to five nearby open tasks.
  4. Mark the hint Consumed when the hinted station claims one of its candidates, Expired at its TTL (swept every 5 s by default), Superseded when a newer hint is issued.
  5. Read policies, hints and stations over REST, and simulate the recommender read-only (POST /recommendations).
  6. Publish InterleavingHintIssued on warehouse.task-interleaving.events and the hint outcomes on warehouse.task-interleaving.analytics, through the transactional outbox.

Where to go next​

You want toRead
See the layers, packages, binary and the rules that police themArchitecture
Run it and make the first callsQuickstart
Know every settingConfiguration
Deploy and operate itRunbook, Observability
Fix something that brokeTroubleshooting
Know what tests and CI gates existTesting
See who talks to whom and what is builtIntegration
See the application use cases and their invariantsUse cases
Read the design in ddd-crew artifactsDDD artifacts, Ubiquitous language
Read the contractsAPI overview, Event catalogue
Read the decisionsADR index

Published at https://iqvo.github.io/task-interleaving/.

Disclaimer

This project is a domain-driven design study. It is not associated with, endorsed by or affiliated with any company, and it uses no company's code, data, logos or trademarks. All names, figures and examples are illustrative or synthetic.