Jeremy Edberg Why am I here? Why should we learn from other peoples - - PowerPoint PPT Presentation

jeremy edberg why am i here why should we learn from
SMART_READER_LITE
LIVE PREVIEW

Jeremy Edberg Why am I here? Why should we learn from other peoples - - PowerPoint PPT Presentation

Jeremy Edberg Why am I here? Why should we learn from other peoples mistakes? Mistakes weve made What is reddit? reddit is an online community Way back in 2005... Two UVA students applied for this thing called YCombinator They


slide-1
SLIDE 1

Jeremy Edberg

slide-2
SLIDE 2
slide-3
SLIDE 3

Why am I here?

slide-4
SLIDE 4

Why should we learn from other people’s mistakes?

slide-5
SLIDE 5
slide-6
SLIDE 6

Mistakes we’ve made

slide-7
SLIDE 7

What is reddit?

reddit is an online community

slide-8
SLIDE 8

Way back in 2005...

  • Two UVA students applied for this thing

called YCombinator

  • They were rejected
  • They were called back
slide-9
SLIDE 9

June 23rd, 2005

slide-10
SLIDE 10

0M 375M 750M 1,125M 1,500M

slide-11
SLIDE 11

0M 0M 0M 0M 0M 0M 1M 10M 100M 1,000M 10,000M

slide-12
SLIDE 12 Text

http://xkcd.com/833/

slide-13
SLIDE 13

Monthly Page Views and Costs

200M 420M 640M 860M 1,080M 1,300M Mar May Jul Sep Nov Jan Mar $20,000.00 $42,000.00 $64,000.00 $86,000.00 $108,000.00 $130,000.00

slide-14
SLIDE 14

Monthly Page Views and Costs

200M 420M 640M 860M 1,080M 1,300M Mar May Jul Sep Nov Jan Mar $20,000.00 $42,000.00 $64,000.00 $86,000.00 $108,000.00 $130,000.00 reddit gold is launched

slide-15
SLIDE 15

If it won’t scale, it'll fail.

  • - paradrox
slide-16
SLIDE 16

The key to scaling is finding the bottlenecks before your users do

  • - jedberg
slide-17
SLIDE 17

Infrastructure

slide-18
SLIDE 18

reddit Timeline

April 2006 -- S3 for logos September 2007 -- S3 for thumbnails November 2008 -- EC2 for batch processing May 2009 -- EC2 for entire site

slide-19
SLIDE 19
slide-20
SLIDE 20

reddit moved from self hosting to EC2

slide-21
SLIDE 21

EC2 for Overflow

Used openvpn to create a secure link to our datacenter for batch processing

slide-22
SLIDE 22

Moving to EC2

  • Started by migrating all data
  • Got a complete stack running on EC2
  • Long Friday night finishing the migration

and “forklifting” the last bits of data

slide-23
SLIDE 23

Takeaways

  • EC2 makes things easier, but isn’t a magic

bullet.

  • The higher network latency and noisy

neighbors will be problematic -- expect to work around it.

  • Scaling on EC2 is a lot like anywhere else,

but you need to be more disciplined.

slide-24
SLIDE 24

Webserver or Proxy?

slide-25
SLIDE 25

What about event driven and non-blocking web servers?

  • Good for long connections
  • More complicated to start, but scales better
slide-26
SLIDE 26

Mistake

  • Not accounting for increased latency in a

virtualized environment

  • Workaround: Fewer network calls, ask for

more data at a time.

slide-27
SLIDE 27

Pain Points

Instances (or machines) go away sometimes

  • r become so slow that you want to make

them go away. Workaround: Avoid single points of failure and make sure your servers have automated configuration.

slide-28
SLIDE 28

Protip

Security was not the first thought when a lot

  • f the cloud systems were designed

Make it your first thought though. A little planning goes a long way. Use security groups judiciously and keep those keys safe!

slide-29
SLIDE 29

Protip

Keep track of those limits! To prevent someone from consuming too much, all resources have per account limits. Keep track of them and get them raised ahead of when you need them. Make sure to catch the exceptions too.

slide-30
SLIDE 30

Mistake

  • Relying on a single cloud product and

expecting it to work as advertised

slide-31
SLIDE 31

Bleeding edge in production

  • Cassandra wasn’t always perfect
  • No data loss, but it was a pain sometimes
slide-32
SLIDE 32

Automate all the things!

http://hyperboleandahalf.blogspot.com/2010/06/this-is-why-ill-never-be-adult.html

(Including Your Infrastructure)

slide-33
SLIDE 33

Architecture

slide-34
SLIDE 34

Is it necessary to build a scalable architecture from the beginning?

slide-35
SLIDE 35

Example 1 -- reddit

slide-36
SLIDE 36

Example 2 -- Netflix

slide-37
SLIDE 37

Personaliz aECon# Engine

User# Info

Movie# Metadat

Movie# RaCngs

Similar# Movies API Reviews A/B#Test# Engine

2B#requests# per#day# into#the# Ne3lix#API 12B#outbound# requests#per# day#to#API# dependencies

slide-38
SLIDE 38

Customer)Device) (PC,)PS3,)TV…)) Web)Site)or) Discovery)API) User)Data) PersonalizaAon) Streaming)API) DRM) QoS)Logging) OpenConnect) CDN)Boxes) CDN) Management)and) Steering) Content)Encoding) Consumer) Electronics) AWS)Cloud) Services) CDN)Edge) LocaAons)

Browse) Play) Watch)

slide-39
SLIDE 39

Advantages to a Service Oriented Architecture

  • Easier auto-scaling
  • Easier capacity planning
  • Identify problematic code-paths more easily
  • Narrow in the effects of a change
  • More efficient local caching
slide-40
SLIDE 40

Disadvantages to a Service Oriented Architecture

  • Need multiple dev teams, or need people

to work on multiple services.

  • Need to come up with a common

platform, otherwise work will be duplicated.

  • Too much overhead for a small team just

starting out.

slide-41
SLIDE 41

Netflix built a global PaaS

  • Service Oriented Architecture
  • HTTP/Rest interfaces between services
slide-42
SLIDE 42

Netflix PaaS features

  • Supports all regions and zones
  • Multiple accounts
  • Cross region/account replication
  • Internationalized, localized and GeoIP routed
  • Advanced key management
  • Autoscaling with 1000s of instances
  • Monitoring and alerting on millions of metrics
slide-43
SLIDE 43

What AWS Provides

  • Instances
  • Machine Images
  • Elastic IPs
  • Load Balancers
  • Security groups / Autoscaling groups
  • Availability zones and regions
slide-44
SLIDE 44

What Netflix provides

  • Applications
  • Clusters
  • Discovery services
  • Application routing
  • Monitoring
slide-45
SLIDE 45

Instance Architecture

Linux Base AMI (CentOS or Ubuntu) Java (JDK 6 or 7) Tomcat

Optional Apache Monitoring Log Rotation to S3 Appdynamics Machine Agent Appdynamics App Agent monitoring Application war file, base servlet, platform, interface jars for dependent services GC and thread dump logging Healthcheck, status servelets, JMX interface, Servo autoscale

slide-46
SLIDE 46

Instance Architecture

Linux Base AMI (CentOS or Ubuntu) Python 2.7 Django

Optional Apache Monitoring Log Rotation to S3 Appdynamics Machine Agent monitoring Application file, base server, platform, interface libs for dependent services Exception logging

slide-47
SLIDE 47

Freedom and Responsibility

  • Developers deploy when they want to
  • They also manage their own capacity and

autoscaling

  • And fix anything that breaks at 4am!
slide-48
SLIDE 48

“Build for three”

We hold a boot camp every 5-8 weeks for new engineers to teach them how to build for a highly distributed environment.

slide-49
SLIDE 49

All systems choices assume some part will fail at some point.

slide-50
SLIDE 50

Don’t follow fads

slide-51
SLIDE 51

Postgres is still a good database

slide-52
SLIDE 52

Offload to the client with Javascript

slide-53
SLIDE 53

What else do you need to worry about?

  • Queues
  • Locking service (can you avoid the locks?)
  • Email (outsource it: deliverability is a pain)
  • ???
slide-54
SLIDE 54

Limits everywhere!

  • Put a limit on everything.
  • Make it really really high.
  • Lower it or raise it as needed
slide-55
SLIDE 55

1 > 2 > 3

Going from two to three is hard

slide-56
SLIDE 56

1 > 2 > 3

Going from one to two is harder

slide-57
SLIDE 57

1 > 2 > 3

If possible, plan for 3 or more from the beginning.

slide-58
SLIDE 58

Monitoring

  • We used Ganglia at reddit
  • Backed by RRD
  • Makes good rollup graphs
  • Gives a great way to visually detect errors
  • Wasn’t friendly to rapidly changing

infrastructure.

slide-59
SLIDE 59

Mistake

  • Not having enough monitoring and using a

system that isn’t “virtualization friendly”.

slide-60
SLIDE 60

Reliability and $$

slide-61
SLIDE 61

The Monkey Theory

  • Simulate things that go wrong
  • Find things that are different
slide-62
SLIDE 62

The simian army

  • Chaos -- Kills random instances
  • Latency -- Slows the network down
  • Conformity -- Looks for outliers
  • Doctor -- Looks for passing health checks
  • Janitor -- Cleans up unused resources
  • Howler --

Yells about bad things

slide-63
SLIDE 63

Netflix autoscaling

Traffic Peak Text

1 2

slide-64
SLIDE 64

Automate all the things!

slide-65
SLIDE 65

Automate all the things!

  • Application startup
  • Configuration
  • Code deployment
  • System deployment
slide-66
SLIDE 66

Netflix has moved the granularity from the instance to the cluster

slide-67
SLIDE 67

Why Bake?

Generic AMI Instance

Traditional:

  • launch OS
  • install

packages

  • install app

Netflix:

  • launch OS+app

App AMI Instance

slide-68
SLIDE 68

Getting Baked

Perforce / Git

libraries source Ant targets Ivy Groovy all over snapshot / release libraries / apps

app bundles

Jenkins

sync resolve build compile report publish test

Artifactory

slide-69
SLIDE 69

Base Image Baking

Yum / Apt

Linux: CentOS, Fedora, Ubuntu RPMs: Apache, Java... ec2 slave instances S3 / EBS

foundation AMI base Bakery

mount install Ready for app bake snapshot AWS

slide-70
SLIDE 70

App Image Baking

Jenkins / Yum / Artifactory

Linux, Apache, Java, Tomcat AWS app bundle ec2 slave instances S3 / EBS

base AMI app Bakery

mount install Ready to launch! snapshot

slide-71
SLIDE 71

Code

slide-72
SLIDE 72

Picking a framework

slide-73
SLIDE 73

You must construct additional Pylons

slide-74
SLIDE 74

Scaling Pylons

  • pylons scaling == python scaling
  • run lots of appservers and make them

independent of each other

  • We built our own caching
  • We built our own database layer
slide-75
SLIDE 75

Would I use Pylons again?

Yes (although it’s called Pyramid now)

slide-76
SLIDE 76

C is faster than Python (sorry)

filters discount (markdown) memcache

slide-77
SLIDE 77

Open Source is Good

slide-78
SLIDE 78

Data

slide-79
SLIDE 79

Data is the most important asset your business will have.

slide-80
SLIDE 80
slide-81
SLIDE 81

Data Gravity

  • Coined by Dave McCrory
  • First described here:

http://blog.mccrory.me/2010/12/07/data- gravity-in-the-clouds/

slide-82
SLIDE 82

What is Data Gravity?

Source: nationalgeographic.com

slide-83
SLIDE 83

Data Gravity and you

  • The bigger your dataset, the harder it is to

move from anywhere to anywhere

  • Also, how do you move that data without

affecting your running application?

slide-84
SLIDE 84

reddit’s data gravity problem

  • We had a lot of data that was ever-growing
  • We were so resource constrained we

couldn’t move it without hurting our application

slide-85
SLIDE 85

Sql or “nosql”?

slide-86
SLIDE 86

Relational vs. Non-relational

slide-87
SLIDE 87

Mysql, Postgres or something else?

slide-88
SLIDE 88

Data schemas

  • Unless you are really really sure of your

business model...

  • The less schema the better
  • reddit’s database is literally just keys and

values

slide-89
SLIDE 89

Expire your data

  • It’s a lot easier to manage if your data is

either gone or in static form

  • Users will almost never notice
slide-90
SLIDE 90

More Transactions Would Be Good

  • Since reddit’s data is spread across two

tables for each thing, we didn’t use sql transactions

  • We should probably have made more

transactions in Python

slide-91
SLIDE 91

Think of SSDs as cheap RAM, not expensive disk

slide-92
SLIDE 92

Database Scaling with Sharding

slide-93
SLIDE 93

Sharding

  • We split our writes across four master

databases

  • Links/Accounts/Subreddits, Comments,

Votes and Misc

  • Each has at least one slave
  • We avoid reading from the master if possible
  • Wrote our own database access layer, called the

“thing” layer

slide-94
SLIDE 94

Cassandra

slide-95
SLIDE 95

Cassandra Architecture

slide-96
SLIDE 96

How it works

  • Replication factor
  • Quorum reads / writes
  • Bloom Filter for fast negative lookups
  • Immutable files for fast writes
  • Seed nodes
slide-97
SLIDE 97

Why Cassandra?

  • Fast writes
  • Fast negative lookups
  • Easy incremental scalability
  • Distributed -- No SPoF
slide-98
SLIDE 98

Second class users

  • Logged out users always get cached

content.

  • Akamai bears the brunt of reddit’s traffic
  • Logged out users are about 80% of the

traffic

slide-99
SLIDE 99

Queues are your friend

  • Votes
  • Comments
  • Thumbnail scraper
  • Precomputed queries
  • Spam
  • processing
  • corrections
slide-100
SLIDE 100

Sometimes users notice your data inconstancy

slide-101
SLIDE 101

Mistake

  • Not using a consistent key hashing

algorithm at first.

slide-102
SLIDE 102

Memcachedb

  • Using md5’d keys made it difficult to

rebalance.

  • It didn’t really have a way to rebalance
  • Turns out it was pretty slow under high

workloads

slide-103
SLIDE 103

Solutions

  • We moved to using a consistent key

hashing for memcache

  • We moved to Cassandra, which follows the

Dynamo model, which uses a type of consistent hashing

slide-104
SLIDE 104

A B C 3 2

slide-105
SLIDE 105

A B C 3 2 D

slide-106
SLIDE 106

Protip

The environment in a public cloud is inherently more variant (co-tenants, abusive

  • r heavy users, etc)

Make sure your code is written to handle this -- state should be kept somewhere shared and redundant, not on the instance.

slide-107
SLIDE 107

Best Practices

  • Keep data in multiple Availability Zones
  • Avoid keeping state on a single instance
  • Take frequent snapshots of EBS disks
  • No secret keys on the instance
  • Different functions in different Security Groups
slide-108
SLIDE 108

Social aspects of Growth

slide-109
SLIDE 109
slide-110
SLIDE 110

The Worm

Or, why you should never have your entire team on one airplane.

slide-111
SLIDE 111

Provide an API

slide-112
SLIDE 112

The business side of things

  • Running a site that requires user input?
  • Be one of the most active users
  • People like to see the founders participate
slide-113
SLIDE 113

Moderation, cheating, spam and fraud

  • If you take user input, and get popular, people

will cheat and spam.

  • If you take money, they will scam people.
  • Limits will help a lot, as will pattern detection.
  • Hard coded rules only go so far -- you need

learning algorithms.

  • Let your users do the work for you.
slide-114
SLIDE 114

What made reddit successful?

  • Empowered users
  • Better software
  • Community interaction
slide-115
SLIDE 115
slide-116
SLIDE 116

How does reddit make money?

  • Sidebox ads
  • Self-serve ads
  • Merchandise
  • reddit gold
  • marketplace
slide-117
SLIDE 117

reddit Gold

slide-118
SLIDE 118

Ask Me Anything

  • Not only did I run technology for reddit

but I also was deeply involved in the business.

  • Ask me anything about running a profitable

social media company.

slide-119
SLIDE 119

Getting in touch

Email: jedberg@{gmail,netflix}.com Twitter: @jedberg Web: www.jedberg.net Facebook: facebook.com/jedberg Linkedin: www.linkedin.com/in/jedberg