MegaFlow: Large-Scale Distributed Orchestration System for the Agentic Era

Lei Zhang, Mouxiang Chen, Ruisheng Cao, Jiawei Chen, Fan Zhou, Yiheng Xu, Jiaxi Yang, Zeyao Ma, Liang Chen, Changwei Luo, Kai Zhang, Fan Yan, KaShun Shum, Jiajun Zhang, Zeyu Cui, Feng Hu, Junyang Lin, Binyuan Hui, Min Yang

TL;DR

MegaFlow is an open-source distributed orchestration system designed to scale up the training and evaluation of AI agents on complex, multi-step tasks like software engineering. By decoupling the infrastructure into three independent, unified services (Model, Agent, and Environment), MegaFlow successfully orchestrates tens of thousands of concurrent agent tasks, achieving a 32% cost reduction and eliminating traditional resource bottlenecks.

What Problem Does This Paper Address?

As we enter the "agentic era," AI agents are expected to perform complex, multi-step tasks like writing software or navigating operating systems. Training these agents via reinforcement learning (RL) requires them to constantly interact with an environment (e.g., a containerized Linux sandbox).

While modern distributed frameworks have mastered scaling model training and inference, they fail at coordinating massive, concurrent agent-environment interactions. The authors identify three critical bottlenecks in traditional infrastructure:

  1. Security and Isolation Constraints: Training clusters often prohibit running arbitrary, user-generated containers due to security policies.
  2. Storage Scalability Limitations: Complex tasks require massive software dependencies. Modest datasets like SWE-bench can require over 25TB of storage for their associated container images, making local storage prohibitively expensive.
  3. Computational Throughput Bottlenecks: Running thousands of resource-intensive containers simultaneously chokes network bandwidth (especially during image pulls) and causes severe CPU/memory contention.

Methods

MegaFlow addresses these challenges by abandoning monolithic designs in favor of a specialized three-service architecture:

The proposed three-service architecture for agent training.
  • Model Service: Handles pure computation (inference via engines like vLLM/SGLang and training via frameworks like VeRL/Megatron).
  • Agent Service: Acts as the coordinator, managing rollout execution strategies and aggregating experience data.
  • Environment Service: The most resource-intensive component, responsible for provisioning and executing containerized agent tasks.

Key Architectural Innovations:

  • Elastic "Many-Small-Instances" Strategy: Instead of relying on a few massive, high-specification machines, MegaFlow uses thousands of standardized, lightweight cloud instances (e.g., 8-core, 16GB). This provides superior elasticity and prevents local resource contention.
  • Hybrid Execution Model: It supports ephemeral execution (provisioning a clean instance per task for perfect isolation) and persistent execution (reusing a pool of instances for maximum resource efficiency).
  • Event-Driven Coordination: Rather than using heavy consensus protocols or expensive polling, MegaFlow utilizes cloud event services (an Event Bridge) to track task states and instance lifecycles reactively.
  • On-Demand Image Provisioning: Container images are pre-provisioned in cloud registries and pulled via high-bandwidth internal networks, turning a fixed local storage problem into an elastic, usage-based model.
Figure 2: The architecture of MegaFlow. (bottom) The Model Service provides inference and training capabilities through various engines and distributed frameworks. (middle) The Agent Ser- vice coordinates execution strategies, integrates with agent frameworks, and manages experience feedback loops. (top) The Environment Service provides containerized execution environments and handles distributed task scheduling.

Datasets

The system was evaluated using large-scale software engineering agent training datasets, including:

  • SWE-bench & SWE-Gym
  • SWE-rebench
  • Multi-SWE-RL
  • Synthesized (Internal) SWE-style repair tasks

MegaFlow demonstrated out-of-the-box compatibility with major agent frameworks including OpenHands, SWE-Agent, Qwen Code, and Claude Code.

Key Insights and Ideas

  • Coordination is the Real Bottleneck: The primary scalability limit in large-scale agent training isn't model math or FLOPs—it's the overhead of managing dynamic, short-lived environment interactions.
  • Local vs. Cloud Constraints: Centralized high-spec servers degrade rapidly when thousands of tasks try to pull images simultaneously. Distributing these tasks across thousands of small cloud instances completely bypasses local network and OS bottlenecks.
  • Predictable Resource Profiles: Centralized approaches suffer from "bursty" resource spikes (CPU usage peaking early, memory peaking mid-execution). MegaFlow’s distributed model flattens this utilization curve, maintaining a stable 5-10% CPU and 12% memory footprint per instance, making capacity planning trivial.

Key Results

  • Consistent Scaling: MegaFlow maintained a flat execution time of ~100 minutes when scaling from 1 to 10,000 concurrent tasks. In contrast, traditional centralized high-spec approaches suffered severe degradation due to resource contention.
  • Significant Cost Savings: At 2,000 concurrent tasks, MegaFlow achieved a 32% cost reduction ($1,005 vs $1,470 USD) compared to high-specification centralized baselines.
Total cost comparison with 32% cost reduction at 2,000 concurrent tasks.
  • Rapid Startup Times: Under the persistent execution mode, environment startup times remained consistently under 1 minute across all concurrency levels, whereas centralized methods degraded up to 13 minutes due to image-pull bottlenecks.

Limitations and Future Work

While MegaFlow excels at orchestrating single-environment agent tasks, the authors note several areas for future expansion:

  • Multi-Environment Tasks: Future iterations will need to explore orchestrating tasks that require complex, multi-container service dependencies (potentially integrating with Kubernetes).
  • Dynamic Execution Switching: Implementing policies that can automatically toggle between ephemeral and persistent execution modes mid-run based on real-time task characteristics.
  • Multi-Cloud Deployment: Extending the abstracted APIs to seamlessly span across multiple cloud providers (AWS, Azure, GCP) simultaneously to mitigate single-provider capacity limits.

Summary updated

BibTeX
@misc{zhang2026megaflow,
  author = {Lei Zhang and Mouxiang Chen and Ruisheng Cao and Jiawei Chen and Fan Zhou and Yiheng Xu and Jiaxi Yang and Zeyao Ma and Liang Chen and Changwei Luo and Kai Zhang and Fan Yan and KaShun Shum and Jiajun Zhang and Zeyu Cui and Feng Hu and Junyang Lin and Binyuan Hui and Min Yang},
  title = {{MegaFlow: Large-Scale Distributed Orchestration System for the Agentic Era}},
  year = {2026},
  eprint = {2601.07526},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.07526},
}
Figure