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

Post on 06-Oct-2020

1 views 0 download

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

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

“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

Stay Informed about the world

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

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

Saurabh PathakEngineering Manager

@pathak_s

Gary LamStaff Engineer

@LamGary

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

Agenda

NotificationsOverview

Notification Timeline

Push

SMS

Email

Notification Challenges

Notifications are bimodal

Number of Notifications

Percentile Rank

Notifications are bimodal

Number of Notifications

Percentile Rank

Typical users

Notifications are bimodal

Number of Notifications

Percentile Rank

Heavy users

Typical users

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

Notifications Fanout

7.49M Followers

Notifications Fanout

Notifications Fanout

FollowerA FollowerB FollowerC FollowerD FollowerE

Latency1

Notification Spikes/Fanout2

Heterogeneous Calls3

Multi DC 4

Main Challenges

Notifications Infrastructure

Push/SMS/EmailMain Challenges

● Latency

● Spikes

● Heterogeneity

Notifications

Send

Device Fanout

Latency & Spikes● Scaling

● Short lived caches

Notifications

Send

Device Fanout

Heterogeneity

● Priority Queues

● Decouple Send

Notifications

Send

Device Fanout

Notification Timeline Notifications

Write Path

Read Path

Datastore

Cache

Main Challenges

● Latency

● Multi DC

Latency● Redis*

● Manhattan

Notifications

Write Path

Read Path

Datastore

Cache

Multi DC ● Cross DC Replication

● Immutable Operations

● Maintenance / Cleanup

Notifications

Write Path

Read Path

Datastore

Cache

Notifications Notifications

Device Fanout

Write Path

Read Path Send

Pull Push

Cache

Infrastructure

● Self Serve

● Server side driven

Key Takeaways Notifications

Device Fanout

Write Path

Read Path

● Sync vs Async

● Write v Read

● Multi-DC Send

Pull Push

Cache

Triggered Notifications

Likes, Mentions, Follows, Retweets...

1

High Volume2

Bimodal3

4

5

Triggered

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

Device Fanout

Datastore

Read Path Send

@qconlondon

Triggered Write Path

WhyPersonalization?

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

Notify you about your interests

Personalized Fanout

Personalized Fanout

Recent EngagementsOn Entities

UserIdEntity1

Entity2

@LamGary

Personalized Fanout

#London

#QCon

Recent EngagementsOn Entities

UserIdEntity1

Entity2

Recent Engagements on Entities

1. Engagements => Interests

2. ‘Recent’ Engagements

a. Twitter is live

b. Your interests are changing

Personalized Fanout

UserIdFollowing1

Following2

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

Personalized Fanout

UserIdFollowing1

Following2

Top N Followings

@LamGary@Twitter

@qconlondon

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

UserIdFollowing1

Following2

UserIdEntity1

Entity2

@LamGary

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

#London

#QCon

@LamGary@Twitter

@qconlondon

@LamGary

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

#London

#QCon

@LamGary@Twitter

@qconlondon

@LamGary

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

#London

#QCon

@LamGary@Twitter

@qconlondon

@LamGary

Personalized Fanout

Top N Followings

Recent EngagementsOn Entities

#London

#QCon

@LamGary@Twitter

@qconlondon

Personalized Fanout Asymmetry

Millions of Katy Perry Fans

Personalized Fanout Asymmetry

My momMillions of Katy Perry Fans

Co-location: no network lookups

● 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

Top N FollowingsTop N FollowingsTop N Followings

Recent EngagementsOn Entities

Recent EngagementsOn Entities

Shard 1 Shard 2

FollowerA FollowerB

Top N Followings

FollowerA FollowerB

Engagements: La La Land

Shard 1 Shard 2

Top N Followings

Recent EngagementsOn Entities

Top Following: @katyperry

Top N FollowingsTop Following: @katyperry

FollowerA FollowerB

Engagements: La La Land Engagements: Moonlight

Top Following: @katyperry

Shard 1 Shard 2

Top N Followings

Engagements: MoonlightEngagements: La La Land

Shard 1 Shard 2

FollowerA FollowerB

Top Following: @katyperry Top Following: @katyperry

Top N Followings

Engagements: MoonlightEngagements: La La Land

Shard 1 Shard 2

FollowerA FollowerB

Top Following: @katyperry Top Following: @katyperry

Top N Followings

Engagements: MoonlightEngagements: La La Land

Shard 1 Shard 2

FollowerA FollowerB

Top Following: @katyperry Top Following: @katyperry

Data preprocessing

Recent Engagements

Top N FollowingsTop N Followings

Recent EngagementsOn Entities

Slim Engagements

Firehose BatchedSlim

Firehose

Recent Engagements

Top N FollowingsTop N Followings

Recent EngagementsOn Entities

Slim Engagements

FirehoseBatched

Slim Firehose

Entity Extractor

Top N Followings

Partitioned Top Followings on HDFS

1 2 3 N

Partition by userId

Find Top N followings for every user

....

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

Personalized Fanout Key Takeaways

● Co-location of data

● Data pre-processing

● Realtime Personalization is expensive

Recommendations

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

Relax realtime constraint control your load

Recommendationsfor each user {

}

● O(Users) vs. O(Events )

● Latency in minutes vs.

seconds

Loop

Recommendations

Send at the right time

● History Store

Loop

Fatigue

Recommendations

Candidate Sources

Loop

Fatigue

Fetch

Loop

Fatigue

FetchFind content for user through

‘Candidate Sources’:

● GraphJet

● Scalding

Recommendations

Pick the best candidate

● e.g. Most social proof

● Historical EngagementML

Model

Loop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Recommendations

● Send through notification

infrastructurePush Notification

Timeline

Loop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

RecommendationsLoop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Infrastructure

HDFS

RecommendationsLoop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Infrastructure

HDFS

MLFeatures Labels

RecommendationsLoop

Fatigue

Fetch

Rank

Loop

Fatigue

Fetch

Rank

Infrastructure

HDFS

MLFeatures Labels

NewML

Model

● 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

Putting it all together

Notifications Infrastructure

Notifications Infrastructure

PersonalizedRealtime

Triggered Notifications

Notifications Infrastructure

PersonalizedRealtime

Triggered Notifications

Notifications Infrastructure

Personalized Fanout

PersonalizedRealtime

Triggered Notifications

Notifications Infrastructure

Personalized Fanout Recommendations

PersonalizedRealtime

Thank you!@pathak_s

@LamGary

Saurabh Pathak

Gary Lam