F8 tech talk_pinterest_v4

100
Discover Pinterest Engineering

description

In April 2014, Pinterest engineers presented to members of the engineering community at a series of Tech Talks held at the Pinterest offices in San Francisco. Topics included: - Mobile & Growth: Scaling user education on mobile, and a deep dive into the new user experience (with engineers Dannie Chu and Wendy Lu) - Monetization & Data: The open sourcing of Pinterest Secor and a look at zero data loss log persistence services (with engineer Pawel Garbacki) - Developing & Shipping Code at Pinterest: The tools and technologies Pinterest uses to build quickly and deploy confidently. You can find more at: engineering.pinterest.com and facebook.com/pinterestengineering

Transcript of F8 tech talk_pinterest_v4

Page 1: F8 tech talk_pinterest_v4

Discover Pinterest Engineering

Page 2: F8 tech talk_pinterest_v4

Agenda

!

Mobile & Growth: Monetization & Data:

Deploying & Shipping Code:

Wendy & Dannie

Pawel

Chris & Jeremy

Page 3: F8 tech talk_pinterest_v4

Wendy LuMobile

Scaling User Education on MobileThe Experience Framework

Dannie ChuGrowth

Page 4: F8 tech talk_pinterest_v4

User Education

Page 5: F8 tech talk_pinterest_v4

Motivation?

Page 6: F8 tech talk_pinterest_v4

User Education leads to Engagement

Page 7: F8 tech talk_pinterest_v4

First Pin Education

Page 8: F8 tech talk_pinterest_v4
Page 9: F8 tech talk_pinterest_v4

Challenges

Page 10: F8 tech talk_pinterest_v4

1. Preserve a great user experience

Page 11: F8 tech talk_pinterest_v4

Conflicting Education

Page 12: F8 tech talk_pinterest_v4

Never-ending Stream of Nags

Page 13: F8 tech talk_pinterest_v4

Nag that never goes away

Page 14: F8 tech talk_pinterest_v4

2. Targeting

Page 15: F8 tech talk_pinterest_v4

Are you a new user? Invite some friends!

Page 16: F8 tech talk_pinterest_v4

Do you have an empty homefeed? Make it better!

Page 17: F8 tech talk_pinterest_v4

3. Rapid Experimentation

Page 18: F8 tech talk_pinterest_v4

Experiment with messaging w/o requiring a release

Page 19: F8 tech talk_pinterest_v4

4. Keep the client code clean

Page 20: F8 tech talk_pinterest_v4

Solution?

Page 21: F8 tech talk_pinterest_v4

The Experience Framework

Page 22: F8 tech talk_pinterest_v4

Conflicting Experiences

Page 23: F8 tech talk_pinterest_v4

Experiences and PlacementsNag Placement Home view Placement

Pin Tutorial Card Placement

Page 24: F8 tech talk_pinterest_v4

AB Experimentation, Simple Client Code

Page 25: F8 tech talk_pinterest_v4

Experiences are delivered to the client at runtime

Page 26: F8 tech talk_pinterest_v4

Experience Framework

Decision Engine

Configuration

Handlers

Admin DashboardAPI

Servers

AB Experiments Framework Kafka

(logging)HBase

(User States, Experience States)

API ServersAPI ServersCascading/ MapRed

User State

Batch Loader

Clients

SDK

SDK

What experience should the user see?

Experience Framework

Page 27: F8 tech talk_pinterest_v4

Deep Dive: Nags

Page 28: F8 tech talk_pinterest_v4

What are nags?

• Important information which we occasionally display at the top of a user’s feed•Can be a Call to Action “Confirm

your email” or an announcement “You can now add a map to any board!”

Page 29: F8 tech talk_pinterest_v4

Enter: The Experience Framework

Page 30: F8 tech talk_pinterest_v4

Enter: The Experience Framework

•Each time we reload the home feed, ask the experience framework: What should I show in this nag?

Page 31: F8 tech talk_pinterest_v4

Single Nag Manager that relies on the experience framework to give it the contents to render

Nag Manager

•Experiment with nag messaging, call to actions, images•Add any new nag dynamically, controlled from the backend.•Cool-down management - should not see more than one nag in a set

period of time

Page 32: F8 tech talk_pinterest_v4

What does that nag data look like?Handling actions

"bg_img_url_2x" = "http://mobile-assets.pinterest.com/iphone/nags/[email protected]"

"title_text" = "Pinspire your friends!"

"detailed_text" = "Know someone who'd like Pinterest? Invite them along."

"button1_text" = "No, Thanks”!"button1_uri" = ""!

"button2_text" = "Invite Friends"!"button2_uri" = "pinterest://invite_friends"

Page 33: F8 tech talk_pinterest_v4

Handling Actions

•All initialization and presentation of view controllers is handled through a central “Navigation Manager.”• Centralizes code to create and present view controllers• Consistency to other platforms for deep links

•Allows dynamic insertion of nags from the backend without having to write new client code and submit a new release

Page 34: F8 tech talk_pinterest_v4

[[NavigationManager sharedManager] handleURL:[NSURL URLWithString:@“pinterest://invite_friends]];

Navigation Manager

self.presentationDelegate

presentInviteFriends

Page 35: F8 tech talk_pinterest_v4

Deep Dive: New User Experience

Page 36: F8 tech talk_pinterest_v4

New User ExperienceWhat is NUX?

!

•The set of initial tutorials and education presented to a user after they register

Page 37: F8 tech talk_pinterest_v4

Personalize a user’s content immediately after signupConnect with Friends Choose Interests

Page 38: F8 tech talk_pinterest_v4

Next, teach users how to Pin

Page 39: F8 tech talk_pinterest_v4

Experiment between classic user ed and NUX

Page 40: F8 tech talk_pinterest_v4

Experiment between classic user ed and NUX

•When doing experiments where we need to call the network to get the user’s treatment group, need to make sure we’re not adding perceived latency• Structure view controllers in a way that you can asynchronously load in the modules

dependent on the treatment group• If need to transition to different view controllers, set a time out in which we transition

to the control treatment• “Be Fast or Fail Fast”

Page 41: F8 tech talk_pinterest_v4

1 step vs. 2 steps vs. 3 stepsExperiment with different versions of NUX

Page 42: F8 tech talk_pinterest_v4

Experiment with different versions of NUX

•Backend controls all strings, allowing us to dynamically experiment with different text (Messaging, titles, calls-to-action)

Page 43: F8 tech talk_pinterest_v4

steps = ( { "continue_button_text" = Continue; "detailed_text" = "Tap a network to find people who share your interests."; "follow_button_text" = "Follow selected people"; step = 1; "title_text" = "First things first"; "total_steps" = 2; }, { "completion_message" = "Finding Pins for you..."; "continue_button_text" = "Tap at least {0} more to continue"; "detailed_text" = "Tap whatever you're interested in these days."; "finish_text" = Finish; "num_interests" = 5; "skip_text" = "Pinterest is much more interesting when you tell us what you like."; step = 2; "title_text" = "Pick 5 interests"; "total_steps" = 2; } );

After signup, request all data for NUXEnter: Experience Framework

Page 44: F8 tech talk_pinterest_v4

Supports dynamic number and order of stepsNUXViewController : UINavigationController

•Maps an array of display data to an array of view controllers

•Protocol method advanceToNextStep called by each child view controller• Checks the array it keeps for the next view controller to push

JSON dict for Intro

JSON dict for Friend Selector

JSON dict for Interests Selector

NUXIntroViewController

NUXConnectViewController

NUXInterestsViewController

Page 45: F8 tech talk_pinterest_v4

Wins from Experience Framework

•Single place in the backend that manages all experiences for all platforms•Dynamically trigger display of content•Conflict resolution for educations that touch the same views•Experiment with flows, messaging, and images

Page 46: F8 tech talk_pinterest_v4

engineering.pinterest.com

Page 47: F8 tech talk_pinterest_v4

Pawel GarbackiSoftware Engineer, Monetization

Pinterest SecorZero-data-loss log persistence service

Page 48: F8 tech talk_pinterest_v4

Pinterest is a data driven company

•Data matters• 100+ experiments active at a given point in time• 1500+ tracked metrics• 200+ log types

Page 49: F8 tech talk_pinterest_v4

We produce a lot of data

•We produce a lot of data• PBs of data in S3, growing by Tens of TB a day• Hundreds of production hadoop jobs, processing about half a PB of data each day

Page 50: F8 tech talk_pinterest_v4

Singer (logging agent)

App

Data pipeline

Local Disk

S3Kafka (log collector)

Secor (log saver)

Storm (realtime

stats)

Hive (hadoop analytics)

Redshift (ad hoc queries)

Page 51: F8 tech talk_pinterest_v4

Singer (logging agent)

App

Local Disk

S3Kafka (log collector)

Secor (log saver)

Storm (realtime

stats)

Hive (hadoop analytics)

Redshift (ad hoc queries)

Data pipeline20B messages/day

Page 52: F8 tech talk_pinterest_v4

Kafka 101

•Distributed pub-sub service•Designed for high throughput Producer Producer Producer

Consumer Consumer Consumer

Kafka cluster

Page 53: F8 tech talk_pinterest_v4

Anatomy of a topic

•Topic is a category to which messages are published•Partition is a ‘shard’ of a topic controlling the level of consumption parallelism•Messages are assigned unique identifiers called offsets

1 2 3 4 5 6 7 8 9 10 11 12

1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9 10 11 12

Writes

Partition 0

Partition 1

Partition 2

Page 54: F8 tech talk_pinterest_v4

Save the day

•Kafka is optimized for local writes•Local disk capacity is good for a few

days worth of data•Data needs to be saved (at least) daily

to long term storage - Amazon S3

Page 55: F8 tech talk_pinterest_v4

How soon is “eventually”

•Amazon S3 is a cloud file system•Eventual consistency model• No guarantees on when uploaded data will become visible to the readers• No monotonicity - data available in the past may magically disappear

Page 56: F8 tech talk_pinterest_v4

Secor design guidelines

•Objectives:• Persist Kafka logs to S3• Cause no data loss• Work properly with eventual consistency model

•Properties:• Horizontal scalability• Fault tolerance• Customizability

Page 57: F8 tech talk_pinterest_v4

No-S3-reads principle

•Secor never reads data from S3• Lightweight metadata is stored in strongly

consistent state repository

•Strategic choice of file names• s3n://logs/<topic>/

<generation>_<partition>_<start_offset>• <generation> represents software compatibility

version• Inconsistencies introduced by consumer failures

get fixed automatically by file overwrites

Page 58: F8 tech talk_pinterest_v4

Date clustering

•Data processing tools rely on date-partitioned directory structure• s3n://logs/event/dt=2014-04-04/

•Timestamps extracted from messages on the fly•Support for pluggable parsers for thrift,

json, etc.

Page 59: F8 tech talk_pinterest_v4

https://github.com/pinterest/secor

Page 60: F8 tech talk_pinterest_v4

Chris Danford (@chrisdanford) Jeremy Stanley (@rouxbot)Web Team

From Development to ProductionThe life of web features

Page 61: F8 tech talk_pinterest_v4

Develop Review Deploy Measure

Page 62: F8 tech talk_pinterest_v4

Develop Review Deploy Measure

Page 63: F8 tech talk_pinterest_v4

Developing - Ideal state

• able to iterate quickly• easy errors caught automatically• easy-to-understand and powerful abstractions

Page 64: F8 tech talk_pinterest_v4

Fast iterationDeveloping

•Build tasks and dependencies modeled as a graph• “cumberbatch” watches for changes of file contents• “orchestrator” knows tasks and dependencies•build the minimum tasks to heal damage in the graph•maximize parallelization of tasks•built on Grunt - access to large library of build tasks

Page 65: F8 tech talk_pinterest_v4

Self-healing build graphsprite/*.png

sprite task

sprite.png sprite.scss

Sass task

component/*.scss

components.css

imagemin task Autoprefixer task CSSlint task

Page 66: F8 tech talk_pinterest_v4

Self-healing build graphsprite/*.png

sprite task

sprite.png sprite.scss

Sass task

component/*.scss

components.css

imagemin task Autoprefixer task CSSlint task

Page 67: F8 tech talk_pinterest_v4

Self-healing build graphsprite/*.png

sprite task

sprite.png sprite.scss

Sass task

component/*.scss

components.css

imagemin task Autoprefixer task CSSlint task

Page 68: F8 tech talk_pinterest_v4

Self-healing build graph, example 2sprite/*.png

sprite task

sprite.png sprite.scss

Sass task

component/*.scss

components.css

imagemin task Autoprefixer task CSSlint task

Page 69: F8 tech talk_pinterest_v4

Self-healing build graph, example 2sprite/*.png

sprite task

sprite.png sprite.scss

Sass task

component/*.scss

components.css

imagemin task Autoprefixer task CSSlint task

Page 70: F8 tech talk_pinterest_v4

LintingDeveloping

• catches easy bugs• enforces consistent style•pyflakes•pep8• jshint•CSSLint• custom RegEx linting

Page 71: F8 tech talk_pinterest_v4

RegEx-based linter

$(‘.item’).addClass(‘selected’);

BoardPicker.js

this.$(‘.item’).addClass(‘selected’);

Page 72: F8 tech talk_pinterest_v4

Static analysis / type safetyDeveloping

•Google Closure Compiler• template static analysis• validation of template inheritance• extract used option variable names

•Thrift clients for service calls (Python) and shared constants (JavaScript)

Page 73: F8 tech talk_pinterest_v4

Closure Compiler - type safety

Page 74: F8 tech talk_pinterest_v4

Generated constants from Thrift

Page 75: F8 tech talk_pinterest_v4

AbstractionsDeveloping

• component framework• styles are scoped to the component• DOM access is scoped to the component’s DOM• “events up, methods down” • scaffolding script

• live component catalog - discovery of existing components• autoprefixer, spriting - remove boilerplate

Page 76: F8 tech talk_pinterest_v4

component catalog

Page 77: F8 tech talk_pinterest_v4

spriting

.thumbsUpButton {! @include inline-image(‘sprites/main/thumbUp');!}

Usage

Page 78: F8 tech talk_pinterest_v4

Develop Review Deploy Measure

Page 79: F8 tech talk_pinterest_v4

Reviewing - Ideal state

• the most-relevant person is reviewing changes• integration-type issues are caught

Page 80: F8 tech talk_pinterest_v4

Code ReviewsReviewing

• local test runner script runs Jasmine and Node tests parallelized• “PR watcher” tool - visibility of relevant PRs• code review process - R+, E+

Page 81: F8 tech talk_pinterest_v4

Parallelized Jasmine tests in PhantomJS

Page 82: F8 tech talk_pinterest_v4

Github Watcher tool

Page 83: F8 tech talk_pinterest_v4

Integration problems are caughtReviewing

•PRs trigger a build and tests - 3 minutes• latest.pinterest.com is continuously deployed from “head”•Selenium integration tests run against every deploy

Page 84: F8 tech talk_pinterest_v4

Pull request builds

Page 85: F8 tech talk_pinterest_v4

Selenium

Page 86: F8 tech talk_pinterest_v4

Develop Review Deploy Measure

Page 87: F8 tech talk_pinterest_v4

Deploying - Ideal state

• code deploys are invisible to users• frequent and non-disruptive to developers• immediate rollback when there’s a problem

Page 88: F8 tech talk_pinterest_v4

User experienceDeploying

• stickiness to a version• flip nearly instantaneously between builds• reduce version thrashing• worry less about (style mismatches, JS errors due to data format mismatch with

server)

• asset versioning

Page 89: F8 tech talk_pinterest_v4

Serving multiple application versions

new!sessions

old!sticky!sessions

A B

all!sessions

B

1 2

Page 90: F8 tech talk_pinterest_v4

Serving multiple application versions, cont’d

3 4

new!canary!sessions

all!non-canary!sessions

B C

new!sessions

old!sticky!sessions

B C

Page 91: F8 tech talk_pinterest_v4

Asset versioninglogo.png

rename

hash file!contents

logo.59aa9183.png

bundle.css

background-image: logo.png

background-image: logo.59aa9183.png

update references

bundle.css

bundle.907389d8.css

rename

hash file!contents

Page 92: F8 tech talk_pinterest_v4

When things go wrongDeploying

• experiments dashboard - turn off experiments instantaneously• version rollback is nearly instantaneous

Page 93: F8 tech talk_pinterest_v4

Develop Review Deploy Measure

Page 94: F8 tech talk_pinterest_v4

Monitoring healthA/B Dashboard

•A/B dashboard key metrics•Sentry •Stats dashboard•Alarms - Monit, PagerDuty

Page 95: F8 tech talk_pinterest_v4

A/B Dashboard

Page 96: F8 tech talk_pinterest_v4

Sentry

Page 97: F8 tech talk_pinterest_v4

Sentry error emails

Page 98: F8 tech talk_pinterest_v4

Results

Page 99: F8 tech talk_pinterest_v4

Results

•5 engineers on web team• all teams at Pinterest developing their own web features on our platform• components re-used across teams•2 scheduled deploys a day• anomalies in key metrics surfaced immediately•100s of simultaneous experiments

Page 100: F8 tech talk_pinterest_v4