Beyond Manual Tuning: How RL Agents Learned to Optimize Apache Spark
Hina Gandhi34:492026
Spark's 200-partition default fails small jobs and skewed ones alike
Split a 1,000-row job into Spark's default 200 shuffle partitions and it drowns in empty tasks; give a skewed monthly job the same setting and it hits stragglers and memory pressure. Data teams answer with endless rounds of tweak and rerun. Cisco software engineering technical leader Hina Gandhi shows a Q-learning agent that picks configurations before a job starts, but can learned tuning beat Spark's own runtime fixes, or does it need them?
See the agent's design, the benchmark numbers and a multi-agent blueprint for self-tuning Spark
Hina Gandhi, Software Engineering Technical Leader at Cisco, shows how a Q-learning agent wrapped around the Spark driver learns to choose configurations such as shuffle partitions before a job runs. She argues that pairing this pre-execution intelligence with Spark's Adaptive Query Execution beats either approach alone, reporting 46% and 68.6% gains in her experiments, and proposes a multi-agent design with a deterministic coordinator for memory, compute and caching.
“So the exact same configuration leads to completely opposite problems depending on the workload.”
“If you have only RL, you are smart upfront, but blind during execution. If you only have AQE, you react well, but start from, you know, suboptimal decisions.”
What you will learn
Explain why a static Spark default such as 200 shuffle partitions over-parallelizes small jobs and overloads large skewed ones.
Design a non-intrusive Q-learning wrapper that samples a dataset, buckets size, cardinality and skew, and picks configurations before execution.
Tune exploration with an epsilon that decays over time but never drops to zero, so the agent keeps adapting to changing code and data.
Combine pre-execution RL decisions with Spark's Adaptive Query Execution to capture complementary performance gains.
Structure multi-parameter optimization as specialist agents coordinated by a simple deterministic orchestrator rather than one monolithic AI.
Key takeaways from the speaker
How Q-learning agents learn from job execution feedback to build configuration policies
Why hybrid RL+AQE optimization outperforms either approach alone
Multi-agent architecture for scaling autonomous optimization across all Spark parameters
Practical deployment strategies for production environments
Details
Level
Intermediate
Format
Tech talk
Technical depth
Practitioner
For
Mid-career, Senior individual contributor
Length
34:49
Published
June 2026
Questions this talk answers
Why doesn't Adaptive Query Execution solve Spark tuning on its own?
AQE only kicks in after a job has started executing, so the cost of suboptimal initial decisions such as partitioning has already been incurred. It can correct course but cannot fully undo that inefficiency.
How does the RL agent understand a dataset without slowing the job down?
It samples a small set of rows (about 1,000 in her experiment, taking roughly 100 milliseconds) to estimate size, cardinality and skew, then groups these signals into buckets so similar workloads share learned configurations.
How much faster was the hybrid RL plus AQE approach?
As the speaker reported, on a 1,000-row low-skew dataset the hybrid ran in 0.142 seconds versus 0.263 seconds for AQE alone (46% faster), and on a 75,000-row skewed dataset in 0.143 seconds versus 0.457 seconds (a 68.6% improvement).
How do multiple learning agents avoid conflicting with each other?
Each agent (partition, memory, cache, core) learns independently in its own domain, and a lightweight coordinator that is not an AI applies their decisions in a fixed deterministic order, keeping the system predictable and debuggable.
How can a team start using this approach in production?
Start incrementally: instrument jobs to capture performance signals, add a lightweight Q-learning wrapper for pre-execution decisions, keep AQE enabled for runtime adaptation, and let the infrastructure learn from production traffic over time.
About this talk
Apache Spark's performance depends heavily on configuration parameters like shuffle partitions, memory allocation, and parallelism settings. Data engineering teams typically rely on static defaults (which rarely match workload reality) or time-consuming manual tuning that doesn't adapt as data patterns evolve. A configuration optimized for small daily reports fails catastrophically on massive end-of-month aggregations—yet tuning each workload variant manually is unsustainable as organizations process increasingly diverse datasets.
This talk demonstrates how reinforcement learning transforms Spark configuration from a manual bottleneck into an autonomous, adaptive system. We built a Q-learning agent that observes dataset characteristics (size, cardinality, skew), experiments with different configurations, measures performance, and learns optimal settings for varying workload patterns—developing expertise comparable to experienced engineers but with perfect memory and systematic exploration.
Through comparative experiments, we show that combining our RL agent with Spark's Adaptive Query Execution (AQE) delivers 46-68% performance improvements over AQE alone. The RL agent provides pre-execution intelligence by selecting optimal initial configurations, while AQE handles runtime adaptations—addressing complementary optimization opportunities.
We then extend this to Multi-Agent Reinforcement Learning (MARL), where specialized agents independently optimize different domains: partitions, memory allocation, CPU cores, and caching strategies. Each agent becomes an expert in its area while collectively achieving comprehensive workload optimization, demonstrating a practical path toward intelligent, self-tuning big data infrastructure.
Key Takeaways:
1.How Q-learning agents learn from job execution feedback to build configuration policies
2. Why hybrid RL+AQE optimization outperforms either approach alone
3. Multi-agent architecture for scaling autonomous optimization across all Spark parameters
4. Practical deployment strategies for production environments
Speaker: Thank you everyone for joining. Let's get started. So today I'm going to talk on optimizing performance with reinforcement learning. And yeah, so before we get started a little bit about myself, I am working as software engineering technical leader at Cisco. I'm leading large scale security solutions for our customers. Previously, I have worked at VMware and Cloudhead technologies where my main focus was leading backend solutions. And I'm currently serving as the chair of women in engineering, IEEE chapter for New Jersey Coast section. And I'm also the secretary of young professional chapter within the same section.
Speaker 1: Yep. So, yeah. So, so this is the problem we everyone have seen with large scale data system. The problem is performance tuning, especially like how we can move from manual tuning system, like Apache spark to system that actually learn how to optimize themselves using reinforcement learning. If you ever worked with spark, you have probably gone through cycles of tweaking configurations, re-running jobs, checking metrics, and then tweaking again. And even after all that effort, there is always this lingering feeling that, you know, maybe there is still, you know, better configuration out there that you just haven't found yet. That uncertainty is exactly what makes this problem so interesting. So the central question is, I want to explore today, you know, instead of relying on like human intuition and trial and error, can we build systems that learn from past execution and automatically improve,
improve like improve over time. So by the end of this talk, you know, we will go through why this problem is inherently hard and how reinforcement learning provides a compelling solution and what this means for the future of distributed system. So, so here, you know, we have like, you know, for Apache spark, there are, uh, shuffle partitions by default, the configuration is 200, which meant like, you know, it will, uh, will be like, you know, different for different situation.
Um, so, um, let's say in real world data pipelines, they're not consistent, they're dynamic and unpredictable. So if you look at the examples here, a small daily job with around 1000 rows, uh, suffers when we apply a static configuration, like 200 partitions, because we end up creating many empty or underutilized tasks. Instead of gaining like parallelism, we will like introduce overhead, extra scheduling, metadata handling and wasted compute.
So the system, you know, becomes inefficient by over parallel, like, you know, over paralyzing. On the other hand, a much larger monthly job with around a million rows and significant skew behaves very differently under the same configuration. Now, instead of underutilization, a few partitions become overloaded, leading to stragglers, uh, memory pressure and even potential out of memory failures.
So the exact same configuration leads to completely opposite problems depending on the workload. That's the core issue, you know, static defaults fundamentally break in dynamic environment. And this is what, you know, we call the tuning crisis. We are trying to apply fixed configurations to system where the workload is constantly changing. So if you see over here, you know, this is how the spark optimization works today and more importantly, what's missing.
So if you go on the left side of the slide, we start with the manual tuning, which is still surprisingly common in production systems. Engineers configure parameters like number of partitions, executor memory and shuffle settings by hand. So the problem is that this approach depends heavily on domain, you know, deep domain expertise. You need someone who understands both the workload and the infrastructure.
And even then, you know, it's time consuming and fragile. As soon as the data distribution shifts or workloads evolve, which they, you know, they will do event. Eventually those carefully tuned configurations break down, leaving teams constantly chasing a moving target. So the industry recognized this limitation, which led to like adaptive query execution or AQE, which is shown in the middle.
AQE is a significant step forward because it allows spark to adjust execution plans dynamically at runtime, such as like changing a joint strategies or rebalancing partitions based on, you know, actual data statistics. However, there is an important limitation. AQE only kicks in after the job has already started executing by the top. By that point, you know, the system has already made some initial decisions like, you know, task scheduling or partitioning that may be suboptimal, meaning the cost of the bad start has already been incurred.
AQE can correct course, but it can't fully undo that inefficiency. This leads us to the core idea on the right side of the slide. That is the missing layer of pre-execution intelligence. What we really want is that for the system to make smart decision before execution even begins. So we need to leverage like, you know, past runs to predict the best configuration, whether that's the right number of partitions, optimal memory setting or ideal parallelism.
Instead of, you know, guessing upfront or fixing issues mid-flight, we begin with the high quality initial configuration. And that's exactly the gap that reinforcement learning, particularly agent based, you know, approaches can fill by observing like, you know, past execution, learning the patterns and continuously improving decisions over time. The system effectively, you know, builds experience much like a human operator would.
So now that, you know, we have identified the gap, the missing pre-execution intelligence, the natural question is how do we build something that can learn the right configurations before execution starts? The approach here is surprisingly elegant. We introduced a Q-learning based reinforcement learning agent that acts like a pre-execution apprentice. Starting from the left, we have the raw data set, which could represent any Spark, you know, workload, such as an ETL pipeline, analytics job or batch process.
Before that data set reaches the Spark execution engine, we insert a lightweight intelligence layer, the RL agent. The importance, important point is that this agent is non-intrusive. It runs on the driver side as a wrapper and does not, you know, modify internal execution engine, which makes it practical from an engineering standpoint. Yeah. So if we try to like, you know, write something inside the purchase part that will be very complex and, you know, we might break the system.
But if we just build a wrapper on top of the purchase part, mainly a wrapper in the Apache driver that can, you know, help with, you know, learning these configuration, learning these experiments and eventually, you know, become start thinking like human beings. So, yeah. So conceptually, you can think of it like a junior engineer learning on the job.
It observed the data set characteristics, experiments with configurations like partition counts and learns from real execution feedback. So over time, it develops the intuition about which configurations work best for which types of workload. So this is where reinforcement learning comes in. The agent takes action, observes rewards such as job run time, updates a strategy. The powerful part is, you know, the perfect memory.
Unlike humans who may forget, you know, experiments or lose tribal knowledge, the agent retains what it learns, you know, tuning, turning like months of trial and error into persistent organizational knowledge. So once it has earned enough, it outputs an optimized configuration before execution begins and only then does the job move into this part. So instead of starting with guesswork, we start with informed, learned decisions.
Yeah. So how it will work, you know, now let's, you know, open that black box and understand how this agent actually works internally at a high level. This is a, like, you know, classic reinforcement learning loop, but adapted very cleverly for Apache or like, you know, Spark workloads. So instead of thinking about it as an extract RL theory, think of it as a three step decision system that happens before execution starts.
First, the agent perceives the state of the job. It does not scan the entire data set because that would be too expensive and would defeat the purpose. Instead, it takes a small sample around 1000 rows, which takes, you know, roughly like 100 millisecond and uses that sample to estimate key signals like, you know, data size, cardinality and skew.
So why, you know, why whole data set is not read because, because that will defeat the purpose of using reinforcement learning, because still, you know, you would, if you try to read whole data set, try to analyze all the rows, it will go through the shuffles, go through that, you know, maybe go through the join. And, you know, the pre execution, you know, you would not be able to gain, you know, you would not be able to gain, you know, if you try to do that.
And same and similarly, you know, your time duration would reach, you know, would, you won't be able to meet that runtime duration that you want to meet with the RL agent. So just taking a small sample to determine like, you know, whether, what type of cardinality this, you know, this particular data set is, I think minimum rows.
I think for my experiment, I just took, you know, a thousand rows, but for your experiment, you could even take like 10,000 rows, which can give you like, you know, good, like understanding of the data set. So the important idea here is that the agent does not need the full data set to make a good decision. It just needed like a representative snapshot.
So next, the agent encodes this information into a form it can learn from. So continuous signals like size or skew are converted into discrete buckets, which allows the agent to generalize across similar workloads. This matters because, you know, no two data sets are exactly the same. So if every job were treated as completely unique, the agent would never learn.
But by grouping workloads into categories like small and skewed or large and uniform, it can reuse, you know, knowledge from previous runs and build experience over time. So let's say if I have a data set of 10K and another data set of 10,001 rows. So it would be like, you know, it would be useless if we treat both these data sets like, you know, different.
So we can create the buckets that, okay, you know, consider the data size of 0 to 20,000 in one bucket, 20,001 to like 30,000 into another bucket and so on. So that, you know, we come up with the same configuration for these types of data set characteristics. So, you know, then finally, you know, the agent selects an action such as like choosing the optimal partition count.
And this decision is based on the queue table, which acts like a memory table storing what configuration worked best for similar workloads in the past. So, yeah, at the same time, the agent does not blindly choose only the best known option. It balances the exploitation, which means using what it already knows works, but with exploration, which means occasionally trying new configuration.
So that balance is crucial because workloads evolve and the system needs to keep learning instead of getting stuck with yesterday's best answer. So I think in reinforcement learning, there is an epsilon parameter that generally, you know, is set for the mathematical formula that we have. And in my experiment, I decided to, it was like, you know, earlier, it was like 70% times you would choose, you know, from your, you know, from your known experiments and 30 times you would do it, you would do the exploration.
So that was the, you know, formula I was going with. And, but, you know, it won't go down to 0%. It would, you know, keep, you know, it would, after performing like certain set of experiment, let's say 100,000 experiment, with each experiment that epsilon will degrade, like, you know, it will come down, maybe by 0.01 every time.
But, um, it will not go down to zero, it will like, you know, once it reached to 0.05, which is 5%, we will just, you know, be, uh, stick to that number. We will, uh, because we still want the agent to do the exploration, uh, because maybe, you know, we have changed the code and now, you know, uh, maybe the configuration that worked previously may, may not.
May perform as, you know, it was performing before, but the new, new configuration that agent can explore can perform better. So that's why, you know, the, the idea is that, you know, you never go to zero percentage, the exploration person, percentage should not be zero, but it should be like at some level that, you know, your agent keeps on exploring rather than, rather than just, you know, sticking to the Q learning values that it has, uh, uh, achieved from the past explorations.
Uh, yeah. So now that, um, now that we have seen the agent decides on a configuration before the execution. So now let's, uh, complete the picture and understand how it actually learns and improves over time, because without the learning, this would just be like, you know, fancy heuristic. So starting, uh, from where we left off, the agent has already observed the data set encoded this state and selected an action.
It now applies that configuration. So instead of like using a default, like 200 partitions, it might choose something very different, such as eight partitions based on like, you know, past exploration or past experiences. So this still happens as a lightweight rep rep rep before the spark joint, a spark job begins without modifying it, like, you know, spark internals internals.
So once the job executes, the most important part of reinforcement learning comes into the play, which is the reward signal. So the system measures actual execution time and uses it as feedback. So for reinforcement learning agent, they are like reward and penalty. So if you are getting positive reward, that means that experiment was successful. Otherwise, if you get negative reward, that means, you know, this experiment does not work in this particular environment or state.
Um, yeah, so the system measures like, you know, actual execution time and use it, uses it as feedback. Faster execution results in higher reward, while slower execution leads to lower reward. And this is powerful because, you know, it's objective directly tied to business value and does not rely on proxies or complex heuristics. We are optimizing exactly what we care about, which is performance.
So the agent then uses this feedback, um, to update its memory, especially the queue table. If a configuration performs, you know, well, the agent reinforces that decision. If it performs poorly, it reduces its confidence in that choice. So over time, you know, this allows the system to continuously refine its understanding, adapt to like changing workloads and avoid assuming that yesterday's best configuration is still optimal today.
Putting it all together, this creates a like closed learning loop. The agent observes the workload, chooses a configuration, executes the job. It performs, you know, measures performance, updates the memory, and the repeats the process getting better with every run. So in my experiment, I only have chosen reward as the runtime, like, you know, but, but we, but, you know, we can also consider other factors like, you know, memory, or like, you know, cost.
So all these can come to the reward formula, which, you know, which can better help, you know, agent to understand how, uh, what configuration to choose to keep, you know, everything, you know, perfect, like cost, memory, and the, uh, CPU, uh, runtime. Yeah. So now that, uh, we, uh, understand how the, our religion work, the next question is how it compares to what we already have.
And more importantly, what actually works best in practice to answer that three different approaches were benchmarked on same workload. So starting with the baseline, we have adaptive query execution or AQE only, which is what most modern, you know, Spark system rely on today. So AQE provides a runtime adaptation and can fix issues like skew or inefficient joint strategies, but it has like two key limitations.
It has no pre-execution intelligence and no ability to learn over time. So every job essentially, you know, starts fresh reacting only after execution has already begun. Next is the RL agent on its own, which introduces pre-execution intelligence and the ability to learn continuously from past workloads, allowing the system to improve over time. However, the trade-off is that it does not adapt during runtime.
So if something unexpected happens, like, you know, extreme skew, the system cannot adjust mid-flight. Finally, the hybrid approach combines the strengths of both RL, which provides like smart initialization before execution and EQE handles like, you know, runtime correctness. This results in the best possible starting configuration, continuous runtime optimization and ongoing learning across workloads. It is the only approach that brings, you know, together all three capabilities, pre-execution intelligence, runtime adaptation and self-learning over time.
So, yeah, now let's look at actual results because this is where things get interesting. This experiment focuses on like, you know, small data set. We just took like thousand rows with very low skew. Intuitively, this should be an easy workload. But in Spark, small data sets often suffer from something counterintuitive, which is over parallelization. By default, Spark might use something like 200 partitions even when the data is tiny, which leads to like, you know, hundreds of small, most empty shuffle files, unnecessary scheduling overhead and wasted compute resources.
Looking at how each approach handles this, AQE alone starts with the default configuration and only reacts after execution begins. So, the initial overhead from those unnecessary partition has already been incurred, resulting in a runtime of 0.263 seconds. With the RL agent, the system recognizes, you know, upfront that this is a small data set and proactively reduces partitions from 200 down to 8, avoiding like the shuffle explosion entirely and bringing the runtime down to 0.175 seconds.
About like, you know, the hybrid approach combines both using RL for the correct starting configuration and AQE for runtime adjustment if needed and achieving the best result at 0.142 seconds, which is like 46% faster than the baseline. So, the key takeaway here is that most of the gain comes from getting the initial configuration right. AQE alone cannot fix bad starting decisions quickly enough while, you know, RL prevents those inefficiencies from happening in the first place.
Yeah. So, now let's see, you know, how it performed for a large data set. So, I only took 75,000 rows data set. It can be like, you know, 1 million or more than that, millions of rows data set. But more importantly was the skew data. It had the skew data, which can, you know, impact the partitioning, like, because, you know, some of the data, some of the partitions can be skewed.
So, yeah, skew, as most of us know, skew is one of the hardest problems in distributed system because some partition become extremely large, while others remain small, causing, like, you know, few tasks to run into bottlenecks. So, this leads to issues like stragglers, poor parallelism, and even out-of-memory failures. So, starting with the baseline, AQE does help with skew by rebalancing partitions during execution, but it still reacts only after the problem has appeared.
So, yeah, so this leads to, like, you know, so sorry, as a result, the initial partitioning can be suboptimal, and some tasks may become, like, overloaded early, leading to a runtime of, like, you know, 0.457 seconds. With the RL agent, the system leverages past experience to recognize this as a high-skew workload and proactively adjust partition scaling before execution begins.
So, this prevents hot partition, reduces memory pressure, and leads to a more balanced task distribution, bringing the runtime, like, you know, down to 0.201 seconds, which is also, like, 56% faster. The hybrid approach performs, you know, best because it combines both strategy, like we saw in the previous slide. And here, AQE continues to adapt dynamically if skew evolves during, you know, execution.
And this combination proactive and reactive optimization results in a runtime of 0.43 seconds, 0.143 seconds, achieving 68.6 improvement over the baseline. So, yeah, so these were, like, you know, performed on comparatively, you know, smaller data sets, but you can see the significant improvements when we compared AQE and RL agent-only mode. And so far, we have seen in both the use cases, hybrid mode, hybrid mode has achieved, you know, better results than, you know, the single mode only, which can be AQE or RL.
So, yeah. So, yeah, so let's now take a step back and connect everything we have seen so far. At a high level, what we are building here is not just a better optimizer, but a new model for autonomous infrastructure. The key insight is that, you know, maximum efficiency does not come from a single technique. It comes from combining, like, two different strengths.
On one side, we have RL agent, which represents, like, you know, learned intuition. It uses past experience, historical patterns, and accumulated knowledge to make smart decisions before execution begins, eliminating structural inefficiencies and poor initial configurations, such as, you know, over parallelism on small workloads. On the other side, we have AQE, which represents, like, real-time reflexes. It does not rely on memory, but instead reacts to what's happening during execution, handling unexpected anomalies and hidden skew, and acting as a fail-safe layer to correct issues mid-flight.
So, you know, the reason why both are needed is simple. If you have only RL, you are smart upfront, but blind during execution. If you only have AQE, you react well, but start from, you know, suboptimal decisions. And when you combine both, you start smart and stay adaptive, which is what ultimately, you know, delivers the maximum efficiency.
And more broadly, this pattern goes beyond spark and points to a general design principle systems, you know, of the future, which will combine, you know, learning-based planning with rule-based execution safeguards, and not one or the another, but both. So, in that sense, you know, truly autonomous systems don't just react. They learn, anticipate, and continuously adapt. Yeah. So, up to this point, we have focused quite a bit on shuffle partition because they are one of the most visible and impactful knobs in SPAR.
But the reality is partition is just one dimension of a much larger optimization problem. In real-world systems, you know, performance depends on multiple interacting factors like partitions, memory, compute, and caching. And the key challenge is that these are not independent. Changing one directly affects the others. What we are effectively asking engineers to do today is understand all these dimensions, predict how they interact, and continuously retune them as workloads evolve.
That's not just difficult. It's exponentially, you know, complex. So, if you look at this diagram, each axis represents a different dimension. Partitions are only the starting point. So, you know, the first thing is that the memory misconfiguration can lead to out-of-memory failures, especially in, like, you know, join heavy workloads where you have shuffles. Even in broadcast join, you can have out-of-memory issues.
So, you know, and also, like, compute can be wasted, you know, if tasks are, like, you know, over-paralyzed and become input-output bound. And caching decisions when ignored can result in redundant computation. So, even if you get one dimension right, the system can still perform poorly because of misalignment elsewhere. The real challenge is coordinating all of these together as a system.
And this is exactly where learning-based approaches become powerful. Instead of trying to handcraft rules for every possible interaction, reinforcement learning can, you know, learn these multi-dimensional trade-offs directly from execution outcomes. So, what we have shown so far with, you know, partition tuning is really just the entry point. The bigger opportunity here is, you know, moving toward fully autonomous system that can optimize across all these dimensions together.
Because ultimately, you know, optimization isn't about tuning a single parameter. It's about managing a complex, you know, interconnected system. And that's where traditional approaches starts to break down. So, if we see, like, you know, if the future is, the future is about the multi-RL agents. And the next question becomes, how do we actually design a system that can handle that complexity?
One approach would be to build a single large monolith AI that tries to optimize everything at once. But in practice, that tends to be fragile, hard to debug, and, you know, difficult to scale. So, instead, what this architecture proposes is something much more modular and robust. A system of specialized domain agents, each focused on a specific aspect of the problem, all coordinated through a central controller.
So, at the central, we have a coordinator that orchestrates decisions across these agents. Surrounding it, each agent develops expertise in its own domain. For example, the partition agent continuously learns how to eliminate shuffle and metadata overhead. Much like, you know, what we have discussed so far. The memory agent, you know, focuses on managing resource pressure, monitoring things like, you know, garbage collection and rebalancing trade-offs between different data structures during execution.
The cache agent, you know, learns reuse patterns over time, deciding, you know, what data should be persisted to avoid redundant computation. And the core agent looks more holistically at compute behavior, balancing parallelism against input-output intensity to ensure resources are used efficiently. The key idea here is separation of concerns. So, instead of one system trying to learn everything, each agent learns deeply with its own domain and the coordinator ensures they work together coherently.
So, this makes the system not only more scalable but more adaptable because you can evolve or, you know, improve one agent without destabilizing the entire system. So, this takes us from a single agent optimization model to something much more powerful, a coordinated ecosystem of learning agents, each contributing to its overall system efficiency. And this is really, you know, where the vision starts to expand from optimizing individual parameters to building fully autonomous self-optimizing data platforms.
So, here, if you see all these, like core, cache, memory, partition, these are all agents, but coordinator is not an agent, it's just, you can think of an orchestrator that will orchestrate, you know, the jobs between these, all these agents. And then, what this slide is really emphasizing is how we make a multi-agent system practical and stable in a real-world setting.
The key idea here is decoupled specialization. So, each agent operates independently within its own domain, whether that's partition, memory, cache, or compute, and learns, you know, using its own feedback loop. So, instead of one system trying to optimize everything at once, each agent builds, you know, deep expertise in a narrow domain, maintaining its own learning model and continuously improving based on outcomes in that specific dimension.
So, now, the important question is, you know, if all these agents are learning independently, how do we prevent them from conflicting with each other? So, that's where, you know, that's where, you know, the coordinator comes in. And this is very intentional design choice. The coordinator itself is not an AI. So, like I mentioned, it's a lightweight orchestration layer that simply applies each agent's, you know, decisions in a fixed deterministic order.
And this keeps the, like, system predictable, debuggable, and easy to reason about while, you know, still benefiting from learning at the edges. So, result is that we call, what we call it is systemic harmony. Each agent contributes its expertise and those decisions naturally come into a full stack optimization of the workload. So, instead of tuning parameters in isolation or relying on fragile, you know, global logic, the system evolved as a coordinated set of specialists.
And because each agent is decoupled, you can, you know, improve or extend one dimension like memory optimization without destabilizing the rest of the system. So, this architecture, you know, gives us the best of both worlds, deep domain-specific learning combined with simple and reliable orchestration. And that's what, you know, makes large-scale multi-dimensional optimization not just, you know, possible but practical.
And on to our, like, you know, last slide. So, to wrap this up, I want to, like, you know, take a step back and focus on the bigger shift we are seeing in how data infrastructure is solving. So, the reality today is that big data systems have simply outgrown manual tuning and static heuristics. The scale, variability, and complexity of modern workload make it impractical for humans to continuously intervene and retune systems.
What used to work as a rule of thumb configuration no longer holds up in dynamic production environments. What we are moving toward instead is a fundamentally different model. One where infrastructure learns from experience, multi-agent reinforcement learning allows system to take what used to be months of costly trial and error and convert that into, you know, persistent, reusable knowledge.
Every job execution become not just a task but a learning opportunity. Over time, the system builds, you know, intuition about workloads, data patterns, and, you know, optimal configurations. And that knowledge, you know, compounds. And importantly, this isn't something that requires a massive overhaul to get started. The path forward can be incremental. You begin by instrumenting your jobs so you can capture meaningful performance signal.
Then you introduce a lightweight learning layer like a, you know, Q-learning wrapper to start making, you know, better pre-execution decisions. You keep systems like AQE enabled for real-time adaptability. And over time, you know, let your infrastructure continuously learn from production traffic, improving without, you know, manual intervention. So the key takeaway here is simple. We are like, you know, moving from systems that are manually tuned and reactive to systems that are autonomous, learning driven, and continuously improving.
And that shift is, you know, what we will define the next generation of data infrastructure. Yeah. Thank you, everyone. Any questions or anything we want to ask? I can see the chat if we have any questions. Okay. If not, um, if not, then have a nice rest of your day, everyone. I gave you back like five minutes and thank you.
Thank you for joining. Thank you so much.
Transcribed automatically; names checked against the speaker record. Select a time to jump there.
Article based on this talk
Can a learning agent tune Apache Spark better than static defaults?
Hina Gandhi shows how a Q-learning agent working alongside Spark's Adaptive Query Execution turns months of trial and error into knowledge the system keeps.
In short
Static Apache Spark configurations rarely match real workloads, and manual tuning cannot keep pace as data changes. Hina Gandhi, Software Engineering Technical Leader at Cisco, argues that a lightweight Q-learning agent that chooses configurations before a job runs, combined with Spark's Adaptive Query Execution (AQE) at runtime, outperforms either approach alone. In her experiments the hybrid improved on AQE alone by 46% and 68.6% on two test datasets, and she sketches how a team of specialist agents could extend the idea to memory, compute and caching.
Key takeaways
How Q-learning agents learn from job execution feedback to build configuration policies
Why hybrid RL and AQE optimization outperforms either approach alone
A multi-agent architecture for scaling autonomous optimization across all Spark parameters
Practical deployment strategies for production environments
Why static defaults break
Gandhi opens with a cycle every Spark user knows: tweak configurations, rerun jobs, check metrics, tweak again, and still wonder whether a better setting exists. Her example is shuffle partitions, which default to 200. For a small daily job of around 1,000 rows, that default creates many empty or underutilized tasks, adding scheduling and metadata overhead instead of useful parallelism. A much larger monthly job with around a million rows and significant skew fails in the opposite direction: a few partitions become overloaded, causing stragglers, memory pressure and potential out-of-memory failures.
"So the exact same configuration leads to completely opposite problems depending on the workload." (3:24)
She calls this the tuning crisis. Manual tuning depends on deep domain expertise and breaks as soon as data distributions shift. AQE was a significant step forward because it adjusts execution plans at runtime, but it only kicks in after the job has started, so the cost of a bad start has already been paid. What is missing, she argues, is a layer of pre-execution intelligence.
A pre-execution apprentice
Her answer is a Q-learning agent that sits between the raw dataset and the Spark execution engine. It is deliberately non-intrusive: it runs on the driver side as a wrapper rather than modifying Spark internals, which she notes would be complex and could break the system.
"So conceptually, you can think of it like a junior engineer learning on the job." (7:21)
The agent works in three steps. First, it perceives the job by sampling a small number of rows (she used about 1,000, which takes roughly 100 milliseconds) to estimate data size, cardinality and skew, because reading the full dataset would defeat the purpose. Second, it encodes those continuous signals into discrete buckets, so a 10,000-row and a 10,001-row dataset are treated alike. "So if every job were treated as completely unique, the agent would never learn." (10:38) Third, it chooses an action, such as a partition count, from its Q-table, the memory of what worked for similar workloads in the past.
Learning from rewards, and never stopping exploration
The agent balances exploitation of known good configurations with exploration of new ones. In her experiment it started at 70% exploitation and 30% exploration, with epsilon decaying gradually but held at a floor of 5%, so the agent keeps experimenting when code or data changes.
"So that balance is crucial because workloads evolve and the system needs to keep learning instead of getting stuck with yesterday's best answer." (12:28)
After each run, the measured execution time becomes the reward. Faster runs earn higher rewards and reinforce the choice; slower runs reduce the agent's confidence in it. Gandhi used runtime alone, but notes that memory or cost could also be built into the reward formula. The result is a closed loop: observe the workload, choose a configuration, execute, measure, update the memory and repeat, getting better with every run.
What the benchmarks showed
Gandhi benchmarked three approaches on the same workloads: AQE only, the RL agent only, and a hybrid of both. On a 1,000-row, low-skew dataset, AQE alone ran in 0.263 seconds. The RL agent recognized the small dataset and cut partitions from 200 to 8, bringing runtime to 0.175 seconds, and the hybrid reached 0.142 seconds, 46% faster than the baseline. On a 75,000-row skewed dataset, AQE alone took 0.457 seconds, the RL agent 0.201 seconds and the hybrid 0.143 seconds, a 68.6% improvement, as she reported. She is open that these were comparatively small datasets.
"So, the key takeaway here is that most of the gain comes from getting the initial configuration right." (20:20)
She frames the two layers as learned intuition and real-time reflexes: "If you have only RL, you are smart upfront, but blind during execution. If you only have AQE, you react well, but start from, you know, suboptimal decisions." (24:31) She sees this pairing of learning-based planning with rule-based execution safeguards as a general design principle for future systems, well beyond Spark.
From one agent to a team of specialists
Partitions are only one dimension. Memory, compute and caching interact with each other, and getting one right while another is misaligned still produces poor performance. Rather than a single monolithic AI, which she describes as fragile, hard to debug and difficult to scale, Gandhi proposes multi-agent reinforcement learning: a partition agent, a memory agent, a cache agent and a core agent, each learning in its own domain through its own feedback loop.
Instead, a lightweight orchestration layer applies each agent's decisions in a fixed, deterministic order, keeping the system predictable and easy to reason about. Because the agents are decoupled, one can be improved or extended without destabilizing the rest.
Her path to production is incremental: instrument jobs to capture meaningful performance signals, add a lightweight Q-learning wrapper for pre-execution decisions, keep AQE enabled for runtime adaptability, and let the infrastructure learn from production traffic. "Every job execution become not just a task but a learning opportunity." (32:56)
Watch the talk
Beyond Manual Tuning: How RL Agents Learned to Optimize Apache Spark, by Hina Gandhi (35 minutes): https://www.womentech.net/video/beyond-manual-tuning-how-rl-agents-learned-optimize-apache-spark
About the speaker
Hina Gandhi is a Software Engineering Technical Leader at Cisco with extensive experience designing scalable, high-performance applications, including earlier roles at VMware and CloudHealth Technologies spanning cloud-based microservices, big data platforms and SaaS development. She was named the 2025 Women in Tech Software Engineering Leader of the Year and gives back by mentoring students and delivering guest lectures at universities.
Questions this talk answers
Why doesn't Adaptive Query Execution solve Spark tuning on its own?
How does the RL agent understand a dataset without slowing the job down?
How much faster was the hybrid RL plus AQE approach?
How do multiple learning agents avoid conflicting with each other?
How can a team start using this approach in production?
Drafted with AI from the talk transcript. Editor review pending.