Pinterest's Medic AI Tames Spark Failures

Pinterest's Drasko Profirovic details Medic, an AI agent designed to diagnose and fix Apache Spark job failures, highlighting the evolution from prototype to a sophisticated multi-agent system.

9 min read
Drasko Profirovic presenting Medic for Apache Spark at Pinterest
AI Engineer

Visual TL;DR. Spark Job Failures leads to Human Troubleshooting Challenges. Spark Job Failures addresses Medic AI Agent. Human Troubleshooting Challenges motivates Medic AI Agent. Medic AI Agent evolved Prototype to Multi-Agent. Prototype to Multi-Agent includes Enhanced Log/Metric Handling. Prototype to Multi-Agent enables Multi-Agent Advantage. Enhanced Log/Metric Handling powers Multi-Agent Advantage. Multi-Agent Advantage results in Streamlined Diagnostics. Streamlined Diagnostics achieves Faster Resolution.

  1. Spark Job Failures: complex, time-consuming troubleshooting in distributed systems like Apache Spark
  2. Human Troubleshooting Challenges: sifting disparate data, ambiguous priorities, difficult for newcomers to diagnose
  3. Medic AI Agent: AI agent designed to diagnose and fix Apache Spark job failures
  4. Prototype to Multi-Agent: evolution from initial prototype to sophisticated multi-agent system architecture
  5. Enhanced Log/Metric Handling: improvements in processing and interpreting diverse log and metric data sources
  6. Multi-Agent Advantage: leveraging multiple specialized agents for comprehensive diagnostics and solutions
  7. Streamlined Diagnostics: automating the process of identifying and resolving Spark job failures
  8. Faster Resolution: significantly reducing the time and effort needed to fix job failures
Visual TL;DR
Visual TL;DR, startuphub.ai Spark Job Failures addresses Medic AI Agent. Multi-Agent Advantage results in Streamlined Diagnostics. Streamlined Diagnostics achieves Faster Resolution addresses results in achieves Spark Job Failures Medic AI Agent Multi-Agent Advantage Streamlined Diagnostics Faster Resolution From startuphub.ai · The publishers behind this format
Visual TL;DR, startuphub.ai Spark Job Failures addresses Medic AI Agent. Multi-Agent Advantage results in Streamlined Diagnostics. Streamlined Diagnostics achieves Faster Resolution addresses results in achieves Spark JobFailures Medic AI Agent Multi-AgentAdvantage StreamlinedDiagnostics Faster Resolution From startuphub.ai · The publishers behind this format
Visual TL;DR, startuphub.ai Spark Job Failures addresses Medic AI Agent. Multi-Agent Advantage results in Streamlined Diagnostics. Streamlined Diagnostics achieves Faster Resolution addresses results in achieves Spark Job Failures complex, time-consuming troubleshooting indistributed systems like Apache Spark Medic AI Agent AI agent designed to diagnose and fixApache Spark job failures Multi-Agent Advantage leveraging multiple specialized agents forcomprehensive diagnostics and solutions Streamlined Diagnostics automating the process of identifying andresolving Spark job failures Faster Resolution significantly reducing the time and effortneeded to fix job failures From startuphub.ai · The publishers behind this format
Visual TL;DR, startuphub.ai Spark Job Failures addresses Medic AI Agent. Multi-Agent Advantage results in Streamlined Diagnostics. Streamlined Diagnostics achieves Faster Resolution addresses results in achieves Spark JobFailures complex,time-consumingtroubleshooting in… Medic AI Agent AI agent designedto diagnose and fixApache Spark job… Multi-AgentAdvantage leveraging multiplespecialized agentsfor comprehensive… StreamlinedDiagnostics automating theprocess ofidentifying and… Faster Resolution significantlyreducing the timeand effort needed… From startuphub.ai · The publishers behind this format
Visual TL;DR, startuphub.ai Spark Job Failures leads to Human Troubleshooting Challenges. Spark Job Failures addresses Medic AI Agent. Human Troubleshooting Challenges motivates Medic AI Agent. Medic AI Agent evolved Prototype to Multi-Agent. Prototype to Multi-Agent includes Enhanced Log/Metric Handling. Prototype to Multi-Agent enables Multi-Agent Advantage. Enhanced Log/Metric Handling powers Multi-Agent Advantage. Multi-Agent Advantage results in Streamlined Diagnostics. Streamlined Diagnostics achieves Faster Resolution leads to addresses motivates evolved includes enables powers results in achieves Spark Job Failures complex, time-consuming troubleshooting indistributed systems like Apache Spark Human Troubleshooting Challenges sifting disparate data, ambiguouspriorities, difficult for newcomers todiagnose Medic AI Agent AI agent designed to diagnose and fixApache Spark job failures Prototype to Multi-Agent evolution from initial prototype tosophisticated multi-agent systemarchitecture Enhanced Log/Metric Handling improvements in processing andinterpreting diverse log and metric datasources Multi-Agent Advantage leveraging multiple specialized agents forcomprehensive diagnostics and solutions Streamlined Diagnostics automating the process of identifying andresolving Spark job failures Faster Resolution significantly reducing the time and effortneeded to fix job failures From startuphub.ai · The publishers behind this format
Visual TL;DR, startuphub.ai Spark Job Failures leads to Human Troubleshooting Challenges. Spark Job Failures addresses Medic AI Agent. Human Troubleshooting Challenges motivates Medic AI Agent. Medic AI Agent evolved Prototype to Multi-Agent. Prototype to Multi-Agent includes Enhanced Log/Metric Handling. Prototype to Multi-Agent enables Multi-Agent Advantage. Enhanced Log/Metric Handling powers Multi-Agent Advantage. Multi-Agent Advantage results in Streamlined Diagnostics. Streamlined Diagnostics achieves Faster Resolution leads to addresses motivates evolved includes enables powers results in achieves Spark JobFailures complex,time-consumingtroubleshooting in… HumanTroubleshooting… sifting disparatedata, ambiguouspriorities,… Medic AI Agent AI agent designedto diagnose and fixApache Spark job… Prototype toMulti-Agent evolution frominitial prototypeto sophisticated… EnhancedLog/Metric… improvements inprocessing andinterpreting… Multi-AgentAdvantage leveraging multiplespecialized agentsfor comprehensive… StreamlinedDiagnostics automating theprocess ofidentifying and… Faster Resolution significantlyreducing the timeand effort needed… From startuphub.ai · The publishers behind this format

Troubleshooting failures in distributed systems like Apache Spark can be a complex and time-consuming task, often involving sifting through disparate data sources and dealing with ambiguous priorities. To address this challenge, Pinterest has developed Medic, an agentic diagnostics tool designed to streamline the process of identifying and resolving Spark job failures.

Pinterest's Medic AI Tames Spark Failures - AI Engineer
Pinterest's Medic AI Tames Spark Failures — from AI Engineer

The Motivation Behind Medic

Drasko Profirovic, a Staff Engineer at Pinterest, explained the motivation for building Medic. The data platform organization at Pinterest, like many others, faces a high bar for supporting partner teams. This often translates into a constant stream of questions and problems, particularly when dealing with distributed systems like Spark, which can be difficult to troubleshoot, especially for newcomers.

The challenge is compounded by the need to balance priorities: helping a team with a failing job versus unblocking another team with a looming deadline. Profirovic highlighted that while humans struggle with such trade-offs, Large Language Models (LLMs) offer the potential to scale capabilities on demand. The vision for Medic was to enable users to ask a simple question like, "Why did a job fail?" and receive a detailed report with evidence and context-specific suggested fixes, available across user interfaces like Slack and Airflow.

From Prototype to Multi-Agent Architecture

The development journey began by exposing Pinterest's data resources via the Model Context Protocol (MCP) to connect them with LLMs. This initial approach required careful prompting from human operators to reason about Spark jobs. To improve this, Pinterest created a single reasoning and acting agent, dubbed ReAct, which was given a comprehensive prompt covering problem-solving, response structuring, and common failure patterns.

However, early trials revealed shortcomings: prompt tuning became unsustainable as a single prompt struggled to handle all scenarios, leading to inconsistent response quality and issues with context window limitations. Large log outputs, for instance, could quickly consume tokens, halting the agent's reasoning. Moreover, the reliance on manual end-to-end testing made it difficult to ensure changes didn't introduce regressions.

To overcome these hurdles, Pinterest focused on improving observability and testability. They integrated OpenTelemetry to publish traces to LangFuse, allowing for better visualization of the agent's execution steps. A purpose-built end-to-end test harness was developed to snapshot production data, codify expectations as offline evaluations, and enable prompt tuning based on quantifiable quality metrics.

Enhancements in Log and Metric Handling

Addressing the noise in logs, especially benign exceptions, was a key area of improvement. Pinterest built an exception classifier pipeline that learns common exceptions in successful jobs, filters out red herrings, and ranks remaining exceptions by content relevance and recency. This led to an improved signal-to-noise ratio and reduced the LLM's tendency to focus on misleading exceptions.

Similarly, raw time-series metrics were found to be token-inefficient and problematic for long-running jobs. The solution involved a quarantined sub-agent that analyzed metrics, converted them into collaged graphs (similar to Grafana dashboards), and attached these images to the LLM conversation. This approach ensured a consistent input token count for any job duration, allowing the LLM to reason about patterns like executor drops or resource bottlenecks.

The Multi-Agent Advantage

The system was further refined by moving from a single ReAct agent to a multi-agent architecture, built on LangGraph's deep agent library. Each agent was assigned a dedicated prompt and a subset of MCP tools. This decomposition allowed for specialized roles, such as a supervisor agent orchestrating the workflow, a triage agent identifying failure hypotheses, research agents validating hypotheses, and a healer agent providing remediations. This modularity not only improved control over the system's behavior but also simplified the expansion of its scope, enabling the addition of new functionalities like Spark SQL optimization.

Learnings and Future Directions

Profirovic shared key learnings, emphasizing the success of the multi-agent architecture and the importance of improving signal-to-noise ratios for logs. A critical lesson was that using LangGraph workflows to represent system state could be brittle, favoring the reasoning and acting agent paradigm. Looking ahead, Pinterest plans to move from prompt tuning for domain-specific knowledge to agentic RAG (Retrieval Augmented Generation) and extend the Medic framework to other distributed systems like Flink and Trino.

© 2026 StartupHub.ai. All rights reserved. Do not enter, scrape, copy, reproduce, or republish this article in whole or in part. Use as input to AI training, fine-tuning, retrieval-augmented generation, or any machine-learning system is prohibited without written license. Substantially-similar derivative works will be pursued to the fullest extent of applicable copyright, database, and computer-misuse laws. See our terms.