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
| Concept | Where it lives | Rule in one line |
|---|---|---|
| InterleavingPolicy (one per site) | internal/domain/policy | How 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/stationtrip | Where 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. |
| Recommender | internal/domain/recommend | Pure function: same pool in any order, same ranked candidates. Rank by detour, then task id. |
| Travel model | internal/domain/travel | The 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 copies | task_pool, zones, locations tables | Event-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 likecom.warehouse.wes.task-interleaving.<entity>.<EventName>.
Main capabilities
- Declare a per-site policy with optimistic concurrency
(
PUT /sites/{siteId}/policy,If-Match/ETag). - Keep the open-task pool and the location geometry current from Kafka
(
TaskAvailable,TaskClaimed,TaskCompleted; zone, location and geometry events), always on. - After a
TaskCompleted, record the station's position and issue a hint of up to five nearby open tasks. - Mark the hint
Consumedwhen the hinted station claims one of its candidates,Expiredat its TTL (swept every 5 s by default),Supersededwhen a newer hint is issued. - Read policies, hints and stations over REST, and simulate the recommender
read-only (
POST /recommendations). - Publish
InterleavingHintIssuedonwarehouse.task-interleaving.eventsand the hint outcomes onwarehouse.task-interleaving.analytics, through the transactional outbox.
Where to go next
| You want to | Read |
|---|---|
| See the layers, packages, binary and the rules that police them | Architecture |
| Run it and make the first calls | Quickstart |
| Know every setting | Configuration |
| Deploy and operate it | Runbook, Observability |
| Fix something that broke | Troubleshooting |
| Know what tests and CI gates exist | Testing |
| See who talks to whom and what is built | Integration |
| See the application use cases and their invariants | Use cases |
| Read the design in ddd-crew artifacts | DDD artifacts, Ubiquitous language |
| Read the contracts | API overview, Event catalogue |
| Read the decisions | ADR index |
Published at https://iqvo.github.io/task-interleaving/.
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.