Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Raffi krikorian twitter timelines at scale

Raffi krikorian twitter timelines at scale

Estuve casi todo el día mirando la presentación de Raffi Krikorian, VP de Ingeniería de Twitter, sobre la infraestructura de los Timelines de Twitter y su escala para no caer como era costumbre de ellos. Para tener una idea de la escala de datos que estamos hablando: cuando Lady Gaga manda un tweet, en menos de 1 minuto tiene que estar en el timeline de sus 31 millones de seguidores y si no aparece, van a existir quejas y llantos… pero al mismo tiempo esa infraestructura es la que mantuvo a mucha gente cubriendo constantemente las marchas en Egipto y el fallido aterrizaje de Asana en San Francisco.

Algunos números que me llamaron la atención: con más de 150 millones de usuarios activos, hay unos 300.000 QPS (con apenas la 20ma parte siendo para publicar, consumo vs creación), esto se convierte en unos 400 millones de tweets al día que es el famoso “firehose”…

El promedio de tweets diario, unos 5.000 por segundo, se convierten en unos 7.000/s en horas picos pero se pasan los 12.000/s en eventos grandes (es facil de decir, pero es casi triplicar lo que se maneja como “promedio”) y cuando hay grafos desproporcionados como @ladygaga y 31 millones de seguidores o @barackobama con 23 millones lo que se da es una inexistente bidireccionalidad o un asincronismo; la gente quiere leerlos y consumir sus contenidos pero no generar el suyo y repito es muy interesante verlo… teras de RAM haciendo inserts ;)

Tal vez lo más interesante de la presentación y el genial análisis que hace Todd Hoff está en el desafió que plantea una frase:

“Twitter no quiere ser una app. Twitter quiere ser un set de APIs que empujen clientes móviles en todo el mundo, sirviendo como un medio para eventos en tiempo real en el planeta”

Y si vemos lo que generan los “Outliers” que nombramos arriba.. se genera un “asincronismo” literal entre las interacciones de Twitter y eso es lo que NO puede pasar a nivel negocio; en este punto es donde la infraestructura y la escalabilidad se convierten en un punto clave del negocio.

Angel Celis Botto

July 09, 2013
Tweet

More Decks by Angel Celis Botto

Other Decks in Programming

Transcript

  1. Pull Push Targeted twitter.com home_timeline API User / Site Streams

    Mobile Push (SMS, etc.) Queried Search API Track / Follow Streams
  2. the challenge ⇢> 150M world wide active users ⇢> 300K

    QPS for timelines ⇢naïve timeline “materialization” can be slow
  3. Timeline Service Ingester Search Cache Redis Redis Earlybird Blender Push

    Compute HTTP Push Mobile Push Batch Compute Hadoop Write API Fanout Redis Redis Timeline Cache Redis
  4. Timeline Service Ingester Search Cache Redis Redis Earlybird Blender Push

    Compute HTTP Push Mobile Push Batch Compute Hadoop Write API Fanout Redis Redis Timeline Cache Redis Social Graph Service
  5. Timeline Service Ingester Search Cache Redis Redis Earlybird Blender Push

    Compute HTTP Push Mobile Push Batch Compute Hadoop Write API Fanout Redis Redis Timeline Cache Redis Social Graph Service insert ⇢keyed o “recipient” ⇢pipelined 4k “destinations” at a time ⇢replicated
  6. Timeline Service Ingester Search Cache Redis Redis Earlybird Blender Push

    Compute HTTP Push Mobile Push Batch Compute Hadoop Write API Fanout Redis Redis Timeline Cache Redis using redis ⇢native list structure Tweet ID Bits User ID 8 bytes 4 bytes 8 bytes
  7. Timeline Service Ingester Search Cache Redis Redis Earlybird Blender Push

    Compute HTTP Push Mobile Push Batch Compute Hadoop Write API Fanout Redis Redis Timeline Cache Redis using redis ⇢native list structure ⇢RPUSHX to only add to cached timelines Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Bits User ID Tweet ID Tweet ID Tweet ID
  8. Ingester Search Cache Redis Redis Earlybird Blender Push Compute HTTP

    Push Mobile Push Batch Compute Hadoop Write API Fanout Redis Redis Timeline Cache Timeline Service Redis
  9. Pull Push Targeted twitter.com home_timeline API User / Site Streams

    Mobile Push (SMS, etc.) Queried Search API Track / Follow Streams
  10. Ingester Search Cache Redis Redis Earlybird Blender Push Compute HTTP

    Push Mobile Push Batch Compute Hadoop Write API Fanout Redis Redis Timeline Cache Timeline Service Redis
  11. Push Compute HTTP Push Mobile Push Batch Compute Hadoop Search

    Index Blender Redis Timeline Service Ingester Earlybird Write API Fanout Redis Redis Timeline Cache Redis Earlybird blender ⇢queries one replica of all indexes ⇢merges & ranks results
  12. Push Compute HTTP Push Mobile Push Batch Compute Hadoop Search

    Index Blender Redis Timeline Service Ingester Earlybird Write API Fanout Redis Redis Timeline Cache Redis Earlybird
  13. Write API Redis Redis Redis Write API Earlybird Earlybird Earlybird

    API Cache Read API Redis Redis Redis Read API Earlybird Earlybird Earlybird API Cache ⇢O(n) write ⇢O(1) write ⇢O(1) read ⇢O(n) read
  14. @barackobama 23 million followers 31 million followers @katyperry 28 million

    followers @justinbieber 28 million followers @ra 0.019 million followers @ladygaga
  15. Write API Ingester Fanout Search Index Redis Earlybird Earlybird Redis

    Redis Redis Timeline Cache search index ⇢[‘hello’,‘world’] fanout index ⇢[@danadanger, ...]
  16. User Intent Query Expansion “Hello, world” “Hello” AND “world” @ra

    ’s home timeline user_timeline:nelson OR user_timeline:danadanger
  17. User Intent Query Expansion “Hello, world” “Hello” AND “world” @ra

    ’s home timeline home_timeline:ra OR user_timeline:taylorswift13
  18. Batch Compute Hadoop Push Compute HTTP Push Search Index Blender

    Redis Timeline Service Ingester Earlybird Write API Fanout Redis Redis Timeline Cache Redis Earlybird Mobile Push
  19. Asynchronous Path Query Path Batch Compute Hadoop Synchronous Path Push

    Compute HTTP Push Search Index Blender Redis Timeline Service Ingester Earlybird Write API Fanout Redis Redis Timeline Cache Redis Earlybird Mobile Push
  20. Synchronous Path Query Path Batch Compute Hadoop Asynchronous Path Push

    Compute HTTP Push Search Index Blender Redis Timeline Service Ingester Earlybird Write API Fanout Redis Redis Timeline Cache Redis Earlybird Mobile Push
  21. Asynchronous Path Synchronous Path Batch Compute Hadoop Query Path Push

    Compute HTTP Push Search Index Blender Redis Timeline Service Ingester Earlybird Write API Fanout Redis Redis Timeline Cache Redis Earlybird Mobile Push
  22. timeline query statistics ⇢>150m active users worldwide ⇢>300k qps poll-based

    timelines @ 1ms p50 / 4ms p99 ⇢>30k qps search-based timelines
  23. timeline delivery statistics ⇢30b deliveries / day (~21m / min)

    ⇢3.5 seconds @ p50 to deliver to 1m ⇢~300k deliveries / sec