﻿# Dask rebalance: equal memory occupancy can undo useful data locality

Review Dask locality, strict worker restrictions and rebalance scope before moving reusable preprocessing data simply to equalize memory charts.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/dask-data-locality-rebalance/
Language: en

A feature pipeline leaves large reusable data on one worker. Its memory chart looks uneven, so an operator redistributes the data. The next stage then transfers it back to the only worker with the required capability. Balanced occupancy and useful locality were different objectives.

## Identify the next consumer

Record which tasks will use the retained values and which workers are permitted to execute them. The [locality guide](https://distributed.dask.org/en/stable/locality.html) describes a preference for workers holding dependencies and minimizing required transfers when dependencies are distributed. That preference is not an unconditional guarantee. An isolated memory chart omits future consumers, resource constraints and the cost of moving a value that the next stage will immediately need elsewhere.

## Review strict worker restrictions

The guide documents workers restrictions and allow_other_workers. A strict restriction can require data to move to the selected worker despite a large transfer. A preference with fallback expresses a different contract. Preserve why the restriction exists, such as a specialized runtime or authorized data location. Do not relax a real correctness or access requirement solely to make the scheduler look balanced. Compare only workers that can legitimately execute the intended computation.

## Scope the rebalance operation

The [Client API](https://distributed.dask.org/en/stable/api.html) defines rebalance as moving data to roughly balance memory burden, optionally within selected futures and workers. Its warning advises against using it while waiting on computations. Plan an appropriate controlled boundary and preserve the exact selection. An unrestricted call can move unrelated reusable values. Do not infer that a successful rebalance optimized the next stage's transfer path or that a balanced graph establishes more useful processing capacity.

## Keep pressure relief separate from locality

Sometimes relieving a heavily loaded worker justifies additional transfers. State that goal explicitly and inspect actual memory categories. The [spill granularity guide](/journal/fg2-dask-cuda-spill-task-buffer-granularity/) explains why managed data and transient allocations differ; moving retained values may not solve an active intermediate peak. The [worker initialization guide](/journal/fg2-kedro-runner-process-boundary-state-ownership/) highlights another limit: transferring an object cannot move every process-local runtime resource needed to use it.

## Compare complete downstream work

In a disposable equivalent, compare the same retained data and downstream task set with and without the scoped rebalance. Preserve worker restrictions, object locations, transfer observations and final outputs. Observe memory relief and later reload separately. Acceptance should demonstrate the intended pressure benefit without changing the computation or violating placement requirements. This proposed protocol asserts no measured transfer savings or performance result, and a prettier memory distribution alone is not a passing criterion.

## Retain an actionable placement record

Save the data identities, permitted consumers, rebalance scope and observed location changes. Revisit the decision if the next stage or eligible workers change. Dask can move data and choose placement, but it cannot infer an application's future reuse or authorization objective from uniform memory targets. The useful result is an explainable tradeoff for this pipeline phase, not a universal instruction to rebalance whenever memory differs between workers or a claim that automatic locality eliminates every transfer.
