Spark Right-Sizing: Saving Thousands of PBHrs of Compute at LinkedIn
Summary
- Massive scale: LinkedIn manages 400,000+ daily Spark applications consuming 200+ PB-hours of compute daily across on-premise data centers.
- Memory optimization: An automated right-sizing system reduced OOM failures by 90% and increased memory utilization by 13%, saving thousands of PB-hours annually.
- Policy-based automation: The system dynamically tunes executor memory using historical data and real-time error classification.
Spark Right-Sizing: Saving Thousands of PBHrs of Compute at LinkedIn

Talk by Shreyesh Arangath, Senior Software Engineer, LinkedIn
At LinkedIn, we manage over 400,000 daily Spark applications consuming 200+ PBHrs of compute daily. To address the challenges posed by manual configuration of Spark's memory tuning options, which led to low memory utilization and frequent OOM errors, we developed an automated Spark executor memory right-sizing system. Our approach, utilizing a policy-based system with nearline and real-time feedback loops, automates memory tuning, leading to more efficient resource allocation, improved user productivity and increased job reliability. By leveraging historical data and real-time error classification, we dynamically adjust memory, significantly narrowing the gap between allocated and utilized resources while reducing failures. This initiative has achieved a 13% increase in memory utilization and a 90% drop in OOM-related job failures, saving us 1000s of PBHrs of compute every year.
Here's more to explore:
The best data warehouse is a lakehouse: https://www.databricks.com/product/databricks-sql
How to migrate legacy data warehouses: https://www.databricks.com/resources/ebook/migrate-your-legacy-data-warehouse-databricks
See all the product announcements from Data + AI Summit: https://www.databricks.com/events/dataaisummit-2025-announcements
FAQs
What was LinkedIn's core Spark configuration problem?
Users were making 3,500 manual Spark configuration changes monthly—half for executor memory—leading to low utilization and frequent out-of-memory errors.
How many PB-hours did LinkedIn save annually?
The optimization achieved 13% higher memory utilization and 90% fewer OOM failures, saving thousands of PB-hours of compute every year.
How does the right-sizing system work?
The policy-based system uses historical data and real-time error classification to dynamically adjust executor memory, eliminating manual configuration.
What was the impact on developers?
Developers no longer need to manually tune memory, improving productivity and reliability while reducing infrastructure costs.
Full transcript
Hey. Uh, today I'll walk you through how we save thousands of pabyte hours of compute uh by right sizing Spark's executive memory uh at LinkedIn. A problem that might seem pretty easy to describe but incredibly tricky to roll it out at LinkedIn scale. So a little bit about me. I am a senior software engineer at LinkedIn. I've been with the Apache Spark team at LinkedIn for about two years now. Uh mainly focused on resource optimization, job submission, and user experience related efforts.
Uh something that's not on my LinkedIn profile is that I like lifting and doing jiu-jitsu. Uh yeah, but let's get into the meat of this. Uh what's the motivation behind all of this? So, Spark is the backbone for our offline big data infrastructure at LinkedIn. It's our most popular uh compute engine offering at LinkedIn and it powers a bunch of different use cases for our exabyte scale data lake that we have. LinkedIn uh pretty much relies on Spark for offline analytics, powering our internal data warehousing, AB testing, AI, ML use cases.
Uh so things such as people you may know, feed jobs you may be interested in, everything is powered using Spark. Uh just to give you a little bit of idea of how the scale looks like, we're launching about 500,000 executions on the daily. Uh out of this 150,000 of them are unique jobs and this equates to about 200 pabyte hours of compute consumed daily. Uh and all of this is done on our on-prem data centers. Um, and Spark provides a bunch of different configurations you might know uh to support all of these use cases.
But Spark's configurations start becoming a problem at LinkedIn scale because they become hard to manage. And as the Spark team, it's our mission to provide great developer experience throughout the company. Uh, we do so in a very datadriven fashion. Uh so as we dug into the data we found that there are recurring pain points uh related to spark tuning that becomes a real issue uh at LinkedIn scale and at LinkedIn scale smallest of small inefficiencies becomes the biggest or biggest problems.
Uh yeah so what are the actual challenges? First, on the user productivity front, on average, our users were making about 3,500 uh configuration changes every single month. And half of these configuration changes just came from executed memory. That's a very large number of execut uh memory configuration changes. And this wasn't just noisy data. These are manual changes that people have to make, go make the change, resubmit the job, and hope for the best.
Uh and this it really is not ideal. uh and we started digging deeper into the data and once we did that we found out that these executed memory changes were because partially related to the out ofmemory uh errors that happen within Spark and on an average there were 300 out of memory errors that happen on a on a daily basis that's a lot of automemory errors that happen um so this is not a great developer experience at all third on the resource efficiency run we saw that the aggregate memory savings or like memory utilization was at 50%.
U so it's not taking use of the exeutor memory that we're given to the executors instead it's just wasting 50% of the memory and executors are often overallocated because users are just like I don't want to deal with so I'm just going to bump it up and let it run. Um that's not great for a cluster management perspective. So what is the solution? So before we design a solution, we had to make sure that we had our goal set and our guiding principles right.
Uh from a resource efficiency standpoint, we wanted to close the gap between the utilized memory and the allocated memory. From a user p uh user productivity standpoint, we wanted to minimize the number of out of memory errors that happen. And from an engineering perspective, we wanted to create a simple enough solution that would eliminate the need for users to come in and manually make changes to the Spark code. Right?
But to make all of this actually work, we wanted to make it understandable, safe, and scalable. So once we knew our goals, uh we started thinking about how do we do it. Uh we considered two main approaches. The first approach was a machine learning based approach where we trained a forecasting based uh machine learning model using our uh LinkedIn data science team's help uh with a bunch of memory features uh just threw it in there and the model was reasonably performant predicted the memory with pretty good accuracy and with the AI ML craze it seemed like the thing to do.
We also looked at a huristic based model which relied on simple deterministic rules. It checked things such as like the peak executive memory usage uh over time if it oomed or not um and applied conservative scale up and scale down uh policies just to tweak the executive memory. We did all this and we refer back to our goal about managing efficiency and reliability at the same time. Uh and we tried to track these KPIs.
The first KPI was to reduce the number of out ofmemory errors. The second one was to increase the memory utilization across executors. So let's talk through what we found performance-wise. The simple huristic based model was as good if not better at sometimes as the machine learning based model. So the real win with the heristic based approach was that it was interpretable and maintainable. And for the first version of right sizing, we wanted to look at a config value and be like I know exactly why we chose that value.
Uh and that huristic based model let us do that. Users could also see the inputs that went into the model and what policies were applied uh on our dashboard. And as infrastructure engineers uh we were far more comfortable maintaining a heristic than a machine learning model. A heristic was something we could see, test, verify, unit test. Uh and the output was deterministic. It was not a black box. Uh and so ultimately the choice was just not performance but also production safety, trust and operability at scale.
So a little bit about the architecture. Let's start with the policy engine. The heart of all this. Um every time a Spark job is submitted, we evaluate a set of policies. uh in priority order and decide how much executive memory to give the job. Um we apply only one policy at a time to not make multiple decisions at once or multiple clashing decisions at once. Um and if no policies applied, let's say the job is new, it doesn't have enough history, then we just use the userdefined memory configs to try and build history or use the cluster defined uh defaults to try and build history on the job.
Uh we also had a set of guardrails to make sure there's no aggressive scale ups or scale downs between runs. So jobs are not oming just because we wanted to save resources. Um now here's the fun part of right sizing. This is what makes it actually scalable and a long-term solution. It's the feedback loops that we have. Uh so first is the nearline feedback loop. Um on every app completion on the cluster we produce a event that contains all the metadata utilization metrics uh and all the metrics related to the job within that uh event that is consumed by a SAMA job uh which pretty much does a rolling aggregate over 30 days to extract out operational signals uh that represent the max P75 P50 50 memory values uh and this feeds into the huristic that we are talking about uh and all of this is persisted into my SQL and which is the source of truth for us.
These nearline signals help us make safe and gradual changes to the executed memory over time because each execution feeds into the feedback loop and adjusts the executive memory as required. On the other hand, we have uh real-time feedback uh that happens. So let's say an out of memory happens on the submission side. We're able to capture the out ofmemory error, record it as a feature into MySQL and on the next run will automatically scale up the memory for that specific job.
So users don't have to worry about scaling up the memory at all. So u this is pretty much to reinforce resiliency allowing us to catch and recover from failures rapidly. Um so just to summarize what's happening the policy engine uh decides uh the memory values at submission time the nearline pipeline just maintains uh history or like the feedback for the for the job and the real time uh feedback loop helps recover from out of memory failures.
Here's a closer look at some of our policies. So like I said we have um the out of memory based scaleup policy. Uh the trigger condition for that is executor out of memory or the container memory violation detected. We scale up the memory by 50% on the next retry. Um and the second one is the uristic based tuning that we do. Uh we use a bunch of different aggregate metrics over the last 30 days and use that plus a buffer uh to tune the job on the fly.
So even though we're applying the right sizers, we want to make sure we have the right set of guardrails applied uh with each of the right sized application. So we have dynamic guardrails which prevent aggressive growth or aggressive decay uh between runs and we have static guardrails for like the cluster minimums. So we're making sure like we're compliant with the clusters uh requirements. Okay. So right sizing might sound simple in principle.
Uh but rolling it out at LinkedIn scale is anything but that. Uh we're talking about a system that could affect the runtime behavior of all the jobs, everything that you see. Uh so one bad push and everything starts to fail because this is the executive memory that we're talking about. So it was very important for us to make calculated decisions uh to roll this change out. So for from day one, our philosophy was optimize safely. uh we did so by introducing something called the shadow mode uh where we pretty much would generate the recommendations by the huristic model uh and have it persisted so we could go and compare how it's doing if our hypothesis to begin with begin with was all right in the first place or not and also since we had so many different workloads within our ecosystem it helped build more confidence as to if our system actually works for all the different use cases that we have Um it also helped us build a bunch of trust with our internal teams cuz we could show them that the jobs are like performing uh with a certain amount of uh executive memory.
Uh and we manually tuned a few of the jobs to even build more confidence with our system that it's working as expected. So this we also had a bunch of dashboards uh that we published out to the users. This was done to build transparency with the users. It was a trust building tool. So users could come and see how their job was doing over time. So as you can see in one of these examples, we're saving 66% of the container memory and 73% of the heap memory.
That's uh that's pretty huge. Uh this is one of our internal jobs. Um so once we had the confidence built out, uh we started rolling it out to our some of our pilot customers in an opt out out f opt-in fashion. And uh once we did that, we built a bunch of confidence and then we started slowly rolling it out as an opt out feature uh throughout the cluster. Uh and right now it's at 100%. It's it's been operating at 100% for about a year.
Uh and it's working great. So let's come back to our KPIs that we set. uh one of them was resource efficiency and the other was user efficient user experience. On the resource efficiency front, we saved the company's 7,000 pabyte hours of compute every single year. That's a lot of compute. Uh and we also had a 80% reduction in out of memory errors throughout our clusters. Uh which is pretty good because we're giving back time to our uh users. uh in our initial analysis that we did, we found out that users were spending about 10 engineering years worth of time every single year just tuning configs.
Uh so this involves tuning configs, setting a job, letting it run, letting it fail, uh retuning it. So things like that. Um digging slightly deeper into the results. Um so the first graph would kind of show you the decrease in the number of out of memory errors that we seeing. uh the yellow block that you see is the rollout phase. So as soon as we started rolling out the feature uh the number of out of memory ers reduced drastically.
Uh the tail off at the end kind of shows our near line and uh real time uh loop working in tandem with each other. Uh like feeding uh responses to each other and making sure that we're not scaling down the memory too fast or scaling up the memory too much. On the second graph, you can see the utilization curve. So, it was at about 54 when we started and it landed at 66 by the end of the ramp, which is huge. We increased it by 15 16%.
Uh, and there's room for more. Uh, I'll talk about it in a second. Um but we also were able to validate our hypothesis that 70% of the jobs at LinkedIn were overprovisioned and 8% of the jobs did require more memory uh because of data changes or like job characteristics changes and we were able to recover from out of memory errors because of the pipeline that we have built. So what's next for right sizing? Right sizing executed memory was only the first step.
There's still a lot more we can do uh to drive uh to simplify Spark for users and drive efficiency at scale. In the near-term future, we're planning to extend the same principles for driver memory tuning. We've already started ramping it to all of our production jobs. It's at a pretty good state right now. Um and it's part of a broader initiative meant to have a config free Spark experience. And I think we're very close uh because by rolling out driver right sizing we'll be like eliminating 70% of all the configuration changes at LinkedIn.
Um and what about the long-term vision? The long-term vision here is that right now job memory it memory is set at a job level but memory requirements could vary between stages. So we're thinking of ways to do stage level tuning to further drive down utilization. Um we are also looking at tuning multiple configs at once. So this could be things such as shuffle partitions, cores and memory at the same time. Uh all of these are still a work in progress, but our ultimate goal is to just have a config free Spark experience for all our users.
Yeah. So before I wrap up, uh quickly want to give a big shout out to the team at LinkedIn and all the core contributors. Uh Rob is here as well, uh one of the core contributors to the project. Uh yeah, thank you guys for your time.
Learn more about the Databricks Data and AI platform.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.