Pinterest Flink Deployment Framework

1,687
Pinterest
Pinterest is a social bookmarking site where users collect and share photos of their favorite events, interests and hobbies. One of the fastest growing social networks online, Pinterest is the third-largest such network behind only Facebook and Twitter.

By Rainie Li | Software Engineer, Stream Processing Platform Team


Background

At Pinterest, stream processing allows us to unlock value from real time data for pinners and partners. The Stream Processing Platform team is working on building a reliable and scalable platform to support many critical streaming applications including real-time experiment analytics and real time machine learning signals.

Apache Flink is a framework and distributed processing engine for stateful computations over unbounded and bounded data streams. It provides features including exactly-once guarantees, low latency, high throughput, and powerful computation model. At Pinterest, we adopt Flink as the unified streaming processing engine.

Requirements

Standardize Flink Build

At Pinterest, we use Bazel as a build system. We need a standardized Bazel rule to build all Flink jobs without changing Makefiles. Once build is done, instead of asking users to copy Flink jars to YARN clusters, jars should be automatically uploaded to remote storage.

Deployment and Operations History

Users used to copy Flink jars to YARN clusters and manually run commands. It was hard to track previous execution histories if we needed to recover failed jobs. We need to provide standard Flink operations such as launching, killing, triggering savepoint, and resuming jobs from the most recent savepoint.

Job Deduplication

Flink applications are deployed as services, therefore one instance should be running at a time for each Flink application. We need to prevent cases when users accidentally deploy twice for the same job, meaning both instances might write to the same Kafka topic. This would mean double writes to Kafka and could affect downstream jobs.

Deployment Framework

We built our Flink deployment framework on top of Bazel, Hermez (internal continuous deployment platform), Job Submission Service (internal service), and YARN clusters.

Figure 1. Deployment high level architecture

Create Bazel BUILD file

The BUILD file needs to contain load(“flink_release”). Users also need to insert a Bazel rule like this:

Define Hermez Deployment File

Hermez is the Pinterest Continuous Deployment System. In order to launch a Flink job with Hermez, users need to create a Hermez.yml file. This file contains information including which YARN cluster Flink jobs to run in, what YARN parameters to use, what resources to use, etc. For each instance of Flink job, users should set up a separate YAML file. For example, if users run their jobs in dev, staging, and prod environments, they will need to have three different YAML files (one for each environment).

Here’s an example of yml file:

Automatically Flink Job Building

The following numbers are referring to steps in Figure 1: Deployment high level architecture

Whenever a user lands a change to Git repo, Jenkins job will be triggered to build Flink job JARs (1). Jenkins job will follow flink_relase rules that are described in the BUILD file to build Flink JAR and upload it to the S3 bucket (3). Meanwhile, it will upload deployment related Hermez YAML files to Artifactory (2). Hermez monitors Artifactory; when it sees a new yml file, it will display it on UI to allow users to launch a job using that yml (5).

Flink Job Launching

When users launch a Flink job, Hermez converts the yml file into a JSON and submits it to Job Submission Service (JSS) (6). JSS is a service maintained by Pinterest that has the ability to schedule and launch Flink jobs to YARN clusters.

JSS examines the request and ensures that Flink JARs and Flink job state exist in S3 (7). If everything is alright, JSS will first launch a shell-runner job which will execute a command on a YARN cluster cluster (8). The shell-runner job downloads the Flink job’s JAR from S3 and then kicks off the actual Flink job using the configuration provided by JSS (9). The reason we add a shell-runner job is to keep JSS as a thin layer without dealing with different compute engine clients (Flink, Spark, MapReduce, etc.) and different configurations for each cluster.

JSS Deduplication

When resuming a Flink job, we provide several options including resume from most recent savepoint or checkpoint, fresh state, and specify a savepoint or checkpoint path. Job deduplication features ensure that there is only one instance of your Flink job running at a time.

The way job deduplication works is that each job has a unique name when a job is submitted. If there is already an instance of the job running, JSS will trigger a safepoint and stop it first, then submit the new job. If the stop request fails because savepoint fails, then the submitted request will fail and the running instance remains running. If there is one deployment in progress, the new job submission would be rejected

Flink Job Configuration Hotfix

Due to Flink configuration being packaged together with Flink job binary, users used to check in config changes to Repo and rebuild the package. This whole process could take more than 10 minutes. This can be a problem if we would like to quickly adjust parameters during incidents. For example, when Flink jobs failed in production due to lack of resources, we used to go through the entire build process to rollout resource config changes. After the incidents got resolved, we needed to check in another change to roll back these configs. To speed up this process, we provide a hotfix feature on Hermez to overwrite Flink job configuration without code change. Users can adjust Flink configuration values during deployment. Behind the scenes, Hermez will directly overwrite these values in ymls which Hermez read from Artifactory.

What’s Next

Reducing Deployment Latency

The current approach launches shell-runner first. Then, shell-runner launches Flink jobs to YARN clusters which could increase latency. We plan to improve this process to reduce end-to-end Flink job launch time.

Automatically Job Failover

To further improve platform and Flink application availability, we built YARN clusters in multiple AWS Availability Zones (AZ) to provide backup when one cluster or one AZ become unavailable. We are also building a service that could automatically detect any cluster failure and failover failed jobs to backup clusters in different AZs or detect application failures and restart the application automatically.

Stay tuned!

Acknowledgments

Thanks to Steven Bairos-Novak and Yu Yang for their countless contributions. Thanks Ang Zhang for updating this blog. This project is a joint effort across multiple teams at Pinterest. Thanks to the Engineering Productivity Team for Hermez support.

Pinterest
Pinterest is a social bookmarking site where users collect and share photos of their favorite events, interests and hobbies. One of the fastest growing social networks online, Pinterest is the third-largest such network behind only Facebook and Twitter.
Tools mentioned in article
Open jobs at Pinterest
Software Engineer, Continuous Delivery
San Francisco, CA, US

About Pinterest:  

Millions of people across the world come to Pinterest to find new ideas every day. It’s where they get inspiration, dream about new possibilities and plan for what matters most. Our mission is to help those people find their inspiration and create a life they love. In your role, you’ll be challenged to take on work that upholds this mission and pushes Pinterest forward. You’ll grow as a person and leader in your field, all the while helping Pinners make their lives better in the positive corner of the internet.

The Engineering Productivity team is a small and diverse group of experienced engineers who build products, tools and systems enabling thousands of Pinterest engineers to be productive across the development lifecycle (code, build, deploy). Our vision is to build a platform that inspires developers to do their best work, and our mission is to provide a fast and safe path from prototype to production without worrying about the underlying infrastructure. We believe in contributing to open source work and collaboration as much as possible. 

What you’ll do:

  • Work on our next-generation, continuous delivery platform for multiple compute backends (VM, K8S, Yarn)
  • Build partnerships with various teams (our customers) by learning their use-cases and pain points; champion key efforts across teams.
  • Have an opportunity to impact key open source systems such as Teletraan (Deploy/Compute Engine), Kubernetes (Compute Engine), Spinnaker (Workflow Orchestration).

What we’re looking for:

  • 4+ years experience as a software engineer and have a penchant to build and scale critical distributed systems.
  • Proficient in coding and scripting languages such as Go, Java, NodeJS or Python.
  • You enjoy articulating technical details on key problem areas by writing RFCs and design documents.

#LI-SG1

Engineering Manager, Creator Platform
San Francisco, CA, US

About Pinterest:  

Millions of people across the world come to Pinterest to find new ideas every day. It’s where they get inspiration, dream about new possibilities and plan for what matters most. Our mission is to help those people find their inspiration and create a life they love. In your role, you’ll be challenged to take on work that upholds this mission and pushes Pinterest forward. You’ll grow as a person and leader in your field, all the while helping Pinners make their lives better in the positive corner of the internet.

The Core Eng - Create Team’s mission is to empower people to create content and build communities that inspire others to create a life they love.

Our focus is to:

  • Grow our quality native content corpus, so we can enable more immersive and engaging experiences on Pinterest.
  • Build delightful tools for anyone who wants to create inspiring content, then build sustained value in our publishing ecosystem - whether through a positive, growing community for the creator or monetization.
  • Protect our pinners and creators by maintaining a positive community and the trust and safety of our pinners.

What you'll do:

  • Partner closely with Design, Product Management, and other Engineering leaders within Core Eng and across Pinterest to identify the highest-impact opportunities to accelerate the product and user experience.
  • Take ownership of critical outcomes. Manage a cross-platform (Android/iOS/Web/Backend) engineering team through the process of planning and executing against those outcomes, delivering software experiences and solutions of the highest quality.
  • Grow the team's capabilities through career development of the current engineers and strategic hiring.

What we're looking for:

  • Passion for developing software solutions for the people using Pinterest.
  • Ability to deliver on immediate goals and form long-term strategies around technology, processes, and people.
  • Strong people development skills and software project management skills.
  • Proven success launching complex software development projects that deliver high-impact outcomes.

#LI-AG1

Design Technologist - Figma Plugin De...
, US

About Pinterest:  

Millions of people across the world come to Pinterest to find new ideas every day. It’s where they get inspiration, dream about new possibilities and plan for what matters most. Our mission is to help those people find their inspiration and create a life they love. In your role, you’ll be challenged to take on work that upholds this mission and pushes Pinterest forward. You’ll grow as a person and leader in your field, all the while helping Pinners make their lives better in the positive corner of the internet.

Pinterest is looking for a Javascript developer to help build out our Figma tooling solutions to better support the company’s design team. You will be creating the tools which help our designers improve Pinterest so it can live up to its mission to bring inspiration and a positive impact to people’s lives.
 
What you’ll do:
  • Talk with product designers to gain a direct understanding of how they work and how our plugins can better support their workflow.
  • Work directly with the product design team to craft and ship tools that will help our team work better and with greater velocity.
  • Develop a strong baseline/framework for all future Figma plugin solutions within Pinterest.
What we’re looking for:
  • 5+ years of experience building on the web platform.
  • Strong background in current web app development practices as well as a strong familiarity with Javascript, Typescript and Webpack.
  • Solid experience with HTML and CSS fundamentals.
  • Background and familiarity with modern design processes and tools is a big plus.
  • Experience with React and using Figma’s plugin/REST APIs a big plus.

More about contract roles at Pinterest: 

  • This is a contract position at Pinterest. As such, the contractor who fills this role will be employed either by our staffing partner (ProUnlimited) or by an agency partner, and not an employee of Pinterest
  • All interviews will be scheduled and/or conducted by the Pinterest assignment manager. When a finalist has been selected, ProUnlimited or the agency partner will extend the offer and provide assignment details including duration, benefits options and onboarding details

#LI-AZ415

#LI-REMOTE

Engineering Manager, Stream Processin...
San Francisco, CA, US

About Pinterest:  

Millions of people across the world come to Pinterest to find new ideas every day. It’s where they get inspiration, dream about new possibilities and plan for what matters most. Our mission is to help those people find their inspiration and create a life they love. In your role, you’ll be challenged to take on work that upholds this mission and pushes Pinterest forward. You’ll grow as a person and leader in your field, all the while helping Pinners make their lives better in the positive corner of the internet.

As the manager for the Stream Processing Platform team at Pinterest, you will lead a team of talented engineers to work on the large scale platform that powers real-time stream processing applications that process trillions of messages every day. You will have the opportunity to work with the team on the latest cutting edge real-time stream processing challenges, defining the future strategy and taking the platform to the next level. You will also have the opportunity to work closely with product teams that develop exciting new applications on our platform every day, from machine learning, analytics, trust safety to shopping. 

What you’ll do:

  • Lead the team that owns the entire stack of stream processing platform
  • Drive Pinterest’s stream processing strategy and vision
  • Collaborate with customers to understand requirements and incorporate them in the roadmap and work closely with partners to align on strategic directions
  • Hire and further build up the team to support more use cases

What we’re looking for:

  • 7+ years of experience, including 2+ years of management experience
  • Solid expertise in big data or other types of large scale distributed systems
  • Platform development and operational experience
  • Enjoying working in an agile environment

#LI-MJ1

Verified by
Security Software Engineer
Tech Lead, Big Data Platform
Software Engineer
Talent Brand Manager
Sourcer
Software Engineer
You may also like