50
Evolution of The Twitter Stack Chris Aniszczyk ( @cra ) http://aniszczyk.org #linuxcon

Evolution of The Twitter Stack

Embed Size (px)

DESCRIPTION

Keynote at LinuxCon EU 2013

Citation preview

Page 1: Evolution of The Twitter Stack

Evolution of The Twitter StackChris Aniszczyk (@cra)

http://aniszczyk.org

#linuxcon

Page 2: Evolution of The Twitter Stack

Reminder: Please Tweet!@cra

#linuxcon

Page 3: Evolution of The Twitter Stack

Agenda

Twitter ScaleHistory and Evolution

Twitter Stack SamplingConcluding Thoughts

Page 4: Evolution of The Twitter Stack

What is Twitter?Twitter is a public real-time information network that

connects you to what you find interesting

The heart of Twitter: tweets

Page 5: Evolution of The Twitter Stack

sizeof(1 tweet) = 140 characters 200 bytes

doesn’t sound like much?

Page 6: Evolution of The Twitter Stack

┈┈┈┈┈◢◤┈┈┈┈┈┈┈┈┈┈◢▇▇▇▇▇◣┈┈┈┈┈┈┈┈▇▇▇▇▇◤┈┈THANK┈┈┈┈▇▇▇▇▇┈┈┈┈YOU┈┈┈┈◥▇▇▇▇◣┈┈┈STEVE┈┈┈┈◥▇◤◥▇◤┈┈┈┈┈┈ #ThankYouSteve #TwitterArt6 Oct via web Favorite Retweet Reply

@tw1tt3rartTW1TT3Rart

Page 7: Evolution of The Twitter Stack

┈┈┈┈┈◢◤┈┈┈┈┈┈┈┈┈┈◢▇▇▇▇▇◣┈┈┈┈┈┈┈┈▇▇▇▇▇◤┈┈THANK┈┈┈┈▇▇▇▇▇┈┈┈┈YOU┈┈┈┈◥▇▇▇▇◣┈┈┈STEVE┈┈┈┈◥▇◤◥▇◤┈┈┈┈┈┈ #ThankYouSteve #TwitterArt6 Oct via web Favorite Retweet Reply

@tw1tt3rartTW1TT3Rart

“Creativity comes from constraint”“Brevity is the soul of the wit”

Page 8: Evolution of The Twitter Stack

What is the scale of Twitter?

Page 9: Evolution of The Twitter Stack

500,000,000 Tweets / Day3,500,000,000 Tweets / Week

Page 10: Evolution of The Twitter Stack

3.5B Tweets / Week

6000+ Tweets / Second(steady state)

However, there are peaks!

Page 11: Evolution of The Twitter Stack

バルス! (“Death to Twitter”)

Page 12: Evolution of The Twitter Stack

Miyazaki 201125,088 TPS (NYE 2013: 33,338 TPS)

バルス! (“Death to Twitter”)

Page 13: Evolution of The Twitter Stack

バルス! (“Death to Twitter”)

Page 14: Evolution of The Twitter Stack

Miyazaki 201325,088 TPS 143,199 TPShttps://blog.twitter.com/2013/new-tweets-per-second-record-and-how

バルス! (“Death to Twitter”)

Page 15: Evolution of The Twitter Stack

TwistoryEvolving the Twitter Stack

Page 16: Evolution of The Twitter Stack

2006: A simple idea...

Page 17: Evolution of The Twitter Stack

Routing Presentation Logic Storage

Monorail (Ruby on Rails)MySQL

Page 18: Evolution of The Twitter Stack

2008: Growing Pains

Page 19: Evolution of The Twitter Stack

Routing Presentation Logic Storage

Monorail (Ruby on Rails)MySQL

Tweet Store

Flock

Redis

Memcache

Cache

Page 20: Evolution of The Twitter Stack

2009+: Crazy Growth

201320132013201320132010 20132006 2010

2006 2009 2013

250M

500M

2010

Page 21: Evolution of The Twitter Stack

2010: World Cup Woes

https://blog.twitter.com/2010/2010-world-cup-global-conversationhttp://bits.blogs.nytimes.com/2010/06/15/twitter-suffers-from-a-number-of-technical-glitches

Page 22: Evolution of The Twitter Stack

What was wrong?Fragile monolithic Rails code base: managing raw database and memcache connections to rendering the

site and presenting the public APIs

Throwing machines at the problem: instead of engineering solutions

Trapped in an optimization corner: trade off readability and flexibility for performance

Page 23: Evolution of The Twitter Stack

Whale Hunting ExpeditionsWe organized archeology digs and whale hunting

expeditions to understand large scale failures

Page 24: Evolution of The Twitter Stack

Re-envision the system?We wanted big infra wins: in performance, reliability and

efficiency (reduce machines to run Twitter by 10x)

Failure is inevitable in distributed systems: we wanted to isolate failures across our infrastructure

Cleaner boundaries with related logic in one place: desire for a loosely coupled services oriented model at the

systems level

Page 25: Evolution of The Twitter Stack

Ruby VM ReflectionStarted to evaluate our front end server tier:

CPU, RAM and network

Rails machines were being pushed to the limit: CPU and RAM maxed but not network (200-300 requests/host)

Twitter’s usage was growing: it was going to take a lot of machines to keep up with the growth curve

Page 26: Evolution of The Twitter Stack

JVM ExperimentationWe started to experiment with the JVM...

Search (Java via Lucene)http://engineering.twitter.com/2010/10/twitters-new-search-architecture.html

FlockDB: Social Graph (Scala)https://blog.twitter.com/2010/introducing-flockdb

https://github.com/twitter/flockdb

...and we liked it, enamored by JVM performance!We weren’t the only ones either: http://www.slideshare.net/pcalcado/from-a-monolithic-ruby-on-rails-app-to-the-jvm

Page 27: Evolution of The Twitter Stack

The JVM SolutionLevel of trust with the JVM with previous experience

JVM is a mature and world class platform

Huge mature ecosystem of libraries

Polyglot possibilities (Java, Scala, Clojure, etc)

Page 28: Evolution of The Twitter Stack

Decomposing the MonolithCreated services based on our core nouns:

Tweet serviceUser service

Timeline serviceDM service

Social Graph service....

Page 29: Evolution of The Twitter Stack

Routing Presentation Logic Storage

MySQL

Tweet Store

Flock

Redis

Memcached

Cache

TFE(netty)

(reverse proxy)

Monorail

Tweet Service

User Service

Timeline Service

SocialGraph Service

DM Service

User Store

API

Web

Search

Feature X

Feature Y

HTTP THRIFT THRIFT*

Page 30: Evolution of The Twitter Stack

Twitter StackA peak at some of our technology

Finagle, Zipkin, Scalding and Mesos

Page 31: Evolution of The Twitter Stack

Services: Concurrency is HardDecomposing the monolith: each team took slightly

different approaches to concurrency

Different failure semantics across teams: no consistent back pressure mechanism

Failure domains informed us of the importance of having a unified client/server library: deal with failure

strategies and load balancing

Page 33: Evolution of The Twitter Stack

Finagle Programming ModelTakes care of: service discovery, load balancing, retrying,

connection pooling, stats collection, distributed tracing

Future[T]: modular, composable, async, non-blocking I/O

http://twitter.github.io/effectivescala/#Concurrency

Page 34: Evolution of The Twitter Stack

Tracing with ZipkinZipkin hooks into the transmission logic of Finagle

and times each service operation; gives you a visual representation where most of the time to fulfill a

request went.

https://github.com/twitter/zipkin

Page 36: Evolution of The Twitter Stack

Data Center EvilsThe evils of single tenancy and static partitioning

Different jobs... different utilization profiles... Can we do better?

STATIC PARTITIONINGDATACENTER

0%

33%

0%

33%

0%

33%

Page 38: Evolution of The Twitter Stack

Mesos, Linux and cgroupsApache Mesos: kernel of the data centerobviates the need for virtual machines*

isolation via Linux cgroups (CPU, RAM, network, FS)reshape clusters dynamically based on resources

multiple frameworks; scalability to 10,000s of nodes

Page 39: Evolution of The Twitter Stack

Data Center ComputingReduce CapEx/OpEx via efficient utilization of HW

http://mesos.apache.org

0%

33%

0%

33%

0%

33%

reduces latency!

reduces CapEx and OpEx!

Page 40: Evolution of The Twitter Stack

Data Center ComputingReduce CapEx/OpEx via efficient utilization of HW

http://mesos.apache.org

0%

33%

0%

33%

0%

33% 0%

25%

50%

75%

100%

reduces latency!

reduces CapEx and OpEx!

Page 41: Evolution of The Twitter Stack

How did it all turn out?Not bad... not bad at all...

Where did the fail whale go?

Page 42: Evolution of The Twitter Stack

Site Success Rate Today :)

2006 2010 2013

World Cup

not a lot of traffic

Off the monorail

99._%

100%

Page 43: Evolution of The Twitter Stack

Performance Today :)

Page 44: Evolution of The Twitter Stack

Growth Continues Today...

2000+ Employees Worldwide50% Employees are Engineers230M+ Active Users500M+ Tweets per Day35+ Languages Supported75% Active Users are on Mobile100+ Open Source Projects

Page 45: Evolution of The Twitter Stack

Concluding ThoughtsLessons Learned

Page 46: Evolution of The Twitter Stack

Lesson #1Embrace open source

best of breed solutions are open these dayslearn from your peers code and university research

don’t only consume, give back to enrich ecosystem:http://twitter.github.io

Page 47: Evolution of The Twitter Stack

Lesson #2Incremental change always wins

increase chance of success by making small changessmall changes add up with minimized risk

loosely coupled micro services work

Page 48: Evolution of The Twitter Stack

Lesson #3Data center as a computer is the future direction of infrastructure

Efficient use of hardware saves moneyBetter programming model (large cluster as single resource)

Check out Apache Mesos: http://mesos.apache.org

Page 49: Evolution of The Twitter Stack

Thanks for listening!(hope you learned something new)

remember, feel free to tweet me #linuxcon

@cra / @[email protected]