Many engineering teams face the same challenge: they need to decide which objects go into which bins while respecting capacity limits, spreading replicas, balancing loads, or matching tickets to experts. Turning policies into precise formulas is hard, and the resulting assignment problems are often NP‑hard and too large for commercial solvers to handle in reasonable time.
Meta’s open‑sourced Rebalancer library tackles exactly this pain point. It is a C++ core with a Python interface that lets you describe an assignment problem in a high‑level spec language and then lets the library choose the best solving strategy. Installing it is straightforward: run pip install rebalancer (pre‑built wheels exist for Linux x86‑64 and macOS 14+ ARM64; deb, rpm and Homebrew packages are also available). The project is released under Apache 2.0 and the source lives on GitHub.
The spec language separates problem definition from solution mechanics. You model objects with dimensions (CPU, storage, etc.), group them into partitions and scopes, and then express goals using predefined constructs such as CapacitySpec, GroupCountSpec and BalanceSpec. An expression API lets you aggregate or transform utilizations (SUM, MAX, SQUARE, …). The Spec API supplies dozens of ready‑made objectives and constraints that you can combine to capture your exact requirements.
Once a spec is written, Rebalancer builds a directed acyclic expression graph. For small to medium instances it can translate the graph into a mixed‑integer program and hand it to solvers like FICO Xpress, Gurobi or HiGHS. For the large‑scale problems that dominate production, it switches to a local‑search solver that works directly on the graph, evaluates millions of moves per second, and prunes the search space intelligently. Meta runs local search on almost all production workloads and reserves MIP for prototyping or smaller clusters.
Debugging is supported by Rebalancer Explorer, a Dockerized web UI that visualises binding constraints, shows why an object landed in a particular bin, and lets you experiment with relaxation steps.
Typical use cases include placing shards or containers on servers under CPU and memory caps while spreading replicas across racks, routing user traffic or ML training jobs across datacenters to balance latency and load, and mapping support tickets, meetings or desks to people under capacity rules.
Adopting Rebalancer lets you move from hand‑crafted heuristics to a principled, scalable solver that handles millions of assignment problems daily with predictable solve times.