Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't...

83
Realtime & Personalized Notifications @Twitter @pathak_s @lamgary March 8 2017

Transcript of Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't...

Page 1: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Realtime & Personalized Notifications @Twitter@pathak_s @lamgary March 8 2017

Page 2: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

“I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were

tweeting and then I realised that Pune had got me.”

Ben Stokes, Cricketer

Page 3: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Stay Informed about the world

Page 4: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notify users about what’s happening in their world in realtime

Page 5: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notify users about what’s happening in their world in realtime

Page 6: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Saurabh PathakEngineering Manager

@pathak_s

Gary LamStaff Engineer

@LamGary

Page 7: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

● Notifications Overview● Notifications Infrastructure ● Triggered Notifications● Personalized Fanout● Recommendations

Agenda

Page 8: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

NotificationsOverview

Page 9: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notification Timeline

Page 10: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Push

Page 11: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

SMS

Page 12: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Email

Page 13: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notification Challenges

Page 14: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications are bimodal

Number of Notifications

Percentile Rank

Page 15: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications are bimodal

Number of Notifications

Percentile Rank

Typical users

Page 16: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications are bimodal

Number of Notifications

Percentile Rank

Heavy users

Typical users

Page 17: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notification are spikyCastle in the Sky

Tweets Per Second spike from Aug 2013

14:21:00 14:21:50 14:22:59

150,000

0

Page 18: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications Fanout

7.49M Followers

Page 19: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications Fanout

Page 20: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications Fanout

FollowerA FollowerB FollowerC FollowerD FollowerE

Page 21: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Latency1

Notification Spikes/Fanout2

Heterogeneous Calls3

Multi DC 4

Main Challenges

Page 22: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications Infrastructure

Page 23: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Push/SMS/EmailMain Challenges

● Latency

● Spikes

● Heterogeneity

Notifications

Send

Device Fanout

Page 24: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Latency & Spikes● Scaling

● Short lived caches

Notifications

Send

Device Fanout

Page 25: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Heterogeneity

● Priority Queues

● Decouple Send

Notifications

Send

Device Fanout

Page 26: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notification Timeline Notifications

Write Path

Read Path

Datastore

Cache

Main Challenges

● Latency

● Multi DC

Page 27: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Latency● Redis*

● Manhattan

Notifications

Write Path

Read Path

Datastore

Cache

Page 28: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Multi DC ● Cross DC Replication

● Immutable Operations

● Maintenance / Cleanup

Notifications

Write Path

Read Path

Datastore

Cache

Page 29: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications Notifications

Device Fanout

Write Path

Read Path Send

Pull Push

Cache

Infrastructure

● Self Serve

● Server side driven

Page 30: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Key Takeaways Notifications

Device Fanout

Write Path

Read Path

● Sync vs Async

● Write v Read

● Multi-DC Send

Pull Push

Cache

Page 31: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Triggered Notifications

Page 32: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Likes, Mentions, Follows, Retweets...

1

High Volume2

Bimodal3

4

5

Triggered

Page 33: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Thanks @qconlondon for all the awesome talks... @pathak_s

Device Fanout

Datastore

Read Path Send

@qconlondon

Triggered Write Path

Page 34: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

WhyPersonalization?

Page 35: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notify users about what’s happening in their world in realtime

Page 36: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notify you about your interests

Page 37: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Personalized Fanout

Page 38: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Personalized Fanout

Recent EngagementsOn Entities

UserIdEntity1

Entity2

Page 39: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

@LamGary

Personalized Fanout

#London

#QCon

Recent EngagementsOn Entities

UserIdEntity1

Entity2

Page 40: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recent Engagements on Entities

1. Engagements => Interests

2. ‘Recent’ Engagements

a. Twitter is live

b. Your interests are changing

Page 41: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Personalized Fanout

UserIdFollowing1

Following2

Top N FollowingsA user's followings are people the user follows

Page 42: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Personalized Fanout

UserIdFollowing1

Following2

Top N Followings

@LamGary@Twitter

@qconlondon

Page 43: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

UserIdFollowing1

Following2

UserIdEntity1

Entity2

Page 44: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

@LamGary

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

#London

#QCon

@LamGary@Twitter

@qconlondon

Page 45: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

@LamGary

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

#London

#QCon

@LamGary@Twitter

@qconlondon

Page 46: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

@LamGary

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

#London

#QCon

@LamGary@Twitter

@qconlondon

Page 47: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

@LamGary

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

#London

#QCon

@LamGary@Twitter

@qconlondon

Page 48: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Personalized Fanout Asymmetry

Millions of Katy Perry Fans

Page 49: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Personalized Fanout Asymmetry

My momMillions of Katy Perry Fans

Page 50: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Co-location: no network lookups

Page 51: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

● Shard by user

● For a given user

○ Engagements and Top

Followings co-located

● No network lookups!

Co-location & Sharding

Top N Followings

Recent Engagements

Top N Followings

Recent Engagements

Top N Followings

Recent EngagementsOn Entities

Firehose

Page 52: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Top N FollowingsTop N FollowingsTop N Followings

Recent EngagementsOn Entities

Recent EngagementsOn Entities

Shard 1 Shard 2

FollowerA FollowerB

Page 53: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Top N Followings

FollowerA FollowerB

Engagements: La La Land

Shard 1 Shard 2

Top N Followings

Recent EngagementsOn Entities

Top Following: @katyperry

Page 54: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Top N FollowingsTop Following: @katyperry

FollowerA FollowerB

Engagements: La La Land Engagements: Moonlight

Top Following: @katyperry

Shard 1 Shard 2

Page 55: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Top N Followings

Engagements: MoonlightEngagements: La La Land

Shard 1 Shard 2

FollowerA FollowerB

Top Following: @katyperry Top Following: @katyperry

Page 56: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Top N Followings

Engagements: MoonlightEngagements: La La Land

Shard 1 Shard 2

FollowerA FollowerB

Top Following: @katyperry Top Following: @katyperry

Page 57: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Top N Followings

Engagements: MoonlightEngagements: La La Land

Shard 1 Shard 2

FollowerA FollowerB

Top Following: @katyperry Top Following: @katyperry

Page 58: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Data preprocessing

Page 59: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recent Engagements

Top N FollowingsTop N Followings

Recent EngagementsOn Entities

Slim Engagements

Firehose BatchedSlim

Firehose

Page 60: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recent Engagements

Top N FollowingsTop N Followings

Recent EngagementsOn Entities

Slim Engagements

FirehoseBatched

Slim Firehose

Entity Extractor

Page 61: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Top N Followings

Partitioned Top Followings on HDFS

1 2 3 N

Partition by userId

Find Top N followings for every user

....

Page 62: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Top N Followings

Partitioned Top Followings on HDFS

1 2 3 N

Partition by userId

....Top N Followings

Top N Followings

Recent Engagements

Shard 3

Find Top N followings for every user

Page 63: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Personalized Fanout Key Takeaways

● Co-location of data

● Data pre-processing

● Realtime Personalization is expensive

Page 64: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting
Page 65: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recommendations

Page 66: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recommendations

● Find content you love

● Find Interesting people Gary Lam and 4 others followed The Academy

Saurabh Pathak and 2 others liked a Tweet from Jimmy Kimmel

Joe and 2 others are tweeting about the #Oscars

Page 67: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Relax realtime constraint control your load

Page 68: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recommendationsfor each user {

}

● O(Users) vs. O(Events )

● Latency in minutes vs.

seconds

Loop

Page 69: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recommendations

Send at the right time

● History Store

Loop

Fatigue

Page 70: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recommendations

Candidate Sources

Loop

Fatigue

Fetch

Loop

Fatigue

FetchFind content for user through

‘Candidate Sources’:

● GraphJet

● Scalding

Page 71: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recommendations

Pick the best candidate

● e.g. Most social proof

● Historical EngagementML

Model

Loop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Page 72: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Recommendations

● Send through notification

infrastructurePush Notification

Timeline

Loop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Page 73: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

RecommendationsLoop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Infrastructure

HDFS

Page 74: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

RecommendationsLoop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Infrastructure

HDFS

MLFeatures Labels

Page 75: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

RecommendationsLoop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Infrastructure

HDFS

MLFeatures Labels

NewML

Model

Page 76: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

● Relax realtime constraint

● Diverse set of content sources

● Data is key for personalization Gary Lam and 4 others followed The Academy

Saurabh Pathak and 2 others liked a Tweet from Jimmy Kimmel

Joe and 2 others are tweeting about the #Oscars

Recommendations Key Takeaways

Page 77: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Putting it all together

Page 78: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications Infrastructure

Page 79: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Notifications Infrastructure

PersonalizedRealtime

Page 80: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Triggered Notifications

Notifications Infrastructure

PersonalizedRealtime

Page 81: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Triggered Notifications

Notifications Infrastructure

Personalized Fanout

PersonalizedRealtime

Page 82: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Triggered Notifications

Notifications Infrastructure

Personalized Fanout Recommendations

PersonalizedRealtime

Page 83: Realtime & Personalized Notifications @Twitter · “I was following it on Twitter, I didn't actually see it live. I kept on refreshing my notifications, I saw people were tweeting

Thank you!@pathak_s

@LamGary

Saurabh Pathak

Gary Lam