raffi krikorian, twitter timelines at scale

42
timelines at scale @ra qcon sf 2012

Upload: mariano-amartino

Post on 10-May-2015

8.646 views

Category:

Technology


5 download

DESCRIPTION

Charla de Raffi Krikorian, el VP de Ingeniería de Twitter, sobre la infraestructura de los Timelines de twitter

TRANSCRIPT

Page 1: Raffi Krikorian, Twitter Timelines at Scale

timelines at scale

@ra!qcon sf 2012

Page 2: Raffi Krikorian, Twitter Timelines at Scale
Page 3: Raffi Krikorian, Twitter Timelines at Scale
Page 4: Raffi Krikorian, Twitter Timelines at Scale

Pull Push

Targeted twitter.comhome_timeline API

User / Site StreamsMobile Push (SMS, etc.)

Queried Search API Track / Follow Streams

Page 5: Raffi Krikorian, Twitter Timelines at Scale

the challenge⇢> 150M world wide active users

⇢> 300K QPS for timelines

⇢naïve timeline “materialization” can be slow

Page 6: Raffi Krikorian, Twitter Timelines at Scale

Timeline Service

Ingester

Sear

ch C

ache

RedisRedisEarlybird

Blender

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

Hadoop

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

Redis

Page 7: Raffi Krikorian, Twitter Timelines at Scale

Timeline Service

Ingester

Sear

ch C

ache

RedisRedisEarlybird

Blender

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

Hadoop

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

Redis

Social Graph Service

Page 8: Raffi Krikorian, Twitter Timelines at Scale

Timeline Service

Ingester

Sear

ch C

ache

RedisRedisEarlybird

Blender

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

Hadoop

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

Redis

Social Graph Service

insert⇢keyed o"

“recipient”

⇢pipelined 4k “destinations” at a time

⇢replicated

Page 9: Raffi Krikorian, Twitter Timelines at Scale

Timeline Service

Ingester

Sear

ch C

ache

RedisRedisEarlybird

Blender

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

Hadoop

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

Redis

using redis⇢native list

structure

Tweet ID BitsUser ID

8 bytes 4 bytes8 bytes

Page 10: Raffi Krikorian, Twitter Timelines at Scale

Timeline Service

Ingester

Sear

ch C

ache

RedisRedisEarlybird

Blender

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

Hadoop

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

Redis

using redis⇢native list

structure

⇢RPUSHX to only add to cached timelines

Tweet ID BitsUser ID

Tweet ID BitsUser ID

Tweet ID BitsUser ID

Tweet ID BitsUser ID

Tweet ID BitsUser ID

Tweet ID BitsUser ID

Tweet ID BitsUser ID

Tweet ID BitsUser ID

Tweet ID BitsUser ID

Tweet ID BitsUser ID Tweet ID

Tweet ID

Tweet ID

Page 11: Raffi Krikorian, Twitter Timelines at Scale

Ingester

Sear

ch C

ache

RedisRedisEarlybird

Blender

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

Hadoop

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

Timeline Service

Redis

Page 12: Raffi Krikorian, Twitter Timelines at Scale

Timeline Service

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

Redis

TweetyPieGizmoduck

Page 13: Raffi Krikorian, Twitter Timelines at Scale

Pull Push

Targeted twitter.comhome_timeline API

User / Site StreamsMobile Push (SMS, etc.)

Queried Search API Track / Follow Streams

Page 14: Raffi Krikorian, Twitter Timelines at Scale

Ingester

Sear

ch C

ache

RedisRedisEarlybird

Blender

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

Hadoop

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

Timeline Service

Redis

Page 15: Raffi Krikorian, Twitter Timelines at Scale

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

HadoopSe

arch

Inde

x

Blender

Redis

Timeline Service

Ingester

Earlybird

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

RedisEarlybird

blender⇢queries one

replica of all indexes

⇢merges & ranks results

Page 16: Raffi Krikorian, Twitter Timelines at Scale

Push

Com

pute

HTTP Push

Mobile Push B

atch

Com

pute

HadoopSe

arch

Inde

x

Blender

Redis

Timeline Service

Ingester

Earlybird

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

RedisEarlybird

Page 17: Raffi Krikorian, Twitter Timelines at Scale

Write API Redis

Redis

Redis

Write API Earlybird

Earlybird

Earlybird

API

Cach

e

Read API Redis

Redis

Redis

Read API Earlybird

Earlybird

EarlybirdAPI

Cach

e⇢O(n) write

⇢O(1) write

⇢O(1) read

⇢O(n) read

Page 18: Raffi Krikorian, Twitter Timelines at Scale

the challenge (part #2)⇢fanout can be really slow!

⇢ ...especially for high follower counts

Page 19: Raffi Krikorian, Twitter Timelines at Scale
Page 20: Raffi Krikorian, Twitter Timelines at Scale

@barackobama23 million followers

31 million followers

@katyperry28 million followers

@justinbieber28 million followers

@ra!0.019 million followers

@ladygaga

Page 21: Raffi Krikorian, Twitter Timelines at Scale

there are over400 million tweetsa day

Page 22: Raffi Krikorian, Twitter Timelines at Scale

a second4600 tweets

0.2 msa tweet≈

Page 23: Raffi Krikorian, Twitter Timelines at Scale
Page 24: Raffi Krikorian, Twitter Timelines at Scale

Write API

Ingester Fanout

Sear

ch In

dex

RedisEarlybird

EarlybirdRedis

RedisRedis

Tim

elin

e C

ache

search index ⇢[‘hello’,‘world’]

fanout index ⇢[@danadanger, ...]

Page 25: Raffi Krikorian, Twitter Timelines at Scale

User Intent Query Expansion

“Hello, world” “Hello” AND “world”

@ra!’s home timeline home_timeline:ra!

Page 26: Raffi Krikorian, Twitter Timelines at Scale

User Intent Query Expansion

“Hello, world” “Hello” AND “world”

@ra!’s home timelineuser_timeline:nelson

ORuser_timeline:danadanger

Page 27: Raffi Krikorian, Twitter Timelines at Scale

User Intent Query Expansion

“Hello, world” “Hello” AND “world”

@ra!’s home timeline home_timeline:ra!

Page 28: Raffi Krikorian, Twitter Timelines at Scale

User Intent Query Expansion

“Hello, world” “Hello” AND “world”

@ra!’s home timelinehome_timeline:ra!

ORuser_timeline:taylorswift13

Page 29: Raffi Krikorian, Twitter Timelines at Scale

Bat

ch C

ompu

te

Hadoop

Push

Com

pute

HTTP Push

Sear

ch In

dex

Blender

Redis

Timeline Service

Ingester

Earlybird

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

RedisEarlybirdMobile Push

Page 30: Raffi Krikorian, Twitter Timelines at Scale

Asynchronous Path

Query Path

Bat

ch C

ompu

te

Hadoop

Synchronous Path

Push

Com

pute

HTTP Push

Sear

ch In

dex

Blender

Redis

Timeline Service

Ingester

Earlybird

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

RedisEarlybirdMobile Push

Page 31: Raffi Krikorian, Twitter Timelines at Scale

Synchronous Path

Query Path

Bat

ch C

ompu

te

Hadoop

Asynchronous Path

Push

Com

pute

HTTP Push

Sear

ch In

dex

Blender

Redis

Timeline Service

Ingester

Earlybird

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

RedisEarlybirdMobile Push

Page 32: Raffi Krikorian, Twitter Timelines at Scale

Asynchronous Path

Synchronous Path

Bat

ch C

ompu

te

Hadoop

Query Path

Push

Com

pute

HTTP Push

Sear

ch In

dex

Blender

Redis

Timeline Service

Ingester

Earlybird

Write API

Fanout

RedisRedis

Tim

elin

e C

ache

RedisEarlybirdMobile Push

Page 33: Raffi Krikorian, Twitter Timelines at Scale

timeline query statistics⇢>150m active users worldwide

⇢>300k qps poll-based timelines @ 1ms p50 / 4ms p99

⇢>30k qps search-based timelines

Page 34: Raffi Krikorian, Twitter Timelines at Scale

tweet input⇢~400m tweets per day

⇢~5K/sec daily average

⇢~7K/sec daily peak

⇢>12K/sec during large events

Page 35: Raffi Krikorian, Twitter Timelines at Scale

timeline delivery statistics⇢30b deliveries / day (~21m / min)

⇢3.5 seconds @ p50 to deliver to 1m

⇢~300k deliveries / sec

Page 36: Raffi Krikorian, Twitter Timelines at Scale
Page 37: Raffi Krikorian, Twitter Timelines at Scale
Page 38: Raffi Krikorian, Twitter Timelines at Scale
Page 39: Raffi Krikorian, Twitter Timelines at Scale
Page 40: Raffi Krikorian, Twitter Timelines at Scale
Page 41: Raffi Krikorian, Twitter Timelines at Scale
Page 42: Raffi Krikorian, Twitter Timelines at Scale

thanks!