Scalable and Available, Patterns for Success

117
Scalable & Available Patterns for Success

description

 

Transcript of Scalable and Available, Patterns for Success

Page 1: Scalable and Available, Patterns for Success

Scalable &AvailablePatterns for Success

Page 4: Scalable and Available, Patterns for Success

Background

•Scalable Apps maintain performance under load

• More requests, More users, More data

•Available Apps maintain the experience during failures

• Hardware failures, Network splits/partitioning

•Simple Designs tend to scale better

Page 5: Scalable and Available, Patterns for Success

Background

Good Performance is good

Page 6: Scalable and Available, Patterns for Success

Background

Predictable Performance is king!

Page 7: Scalable and Available, Patterns for Success

Background

Understand your data!

Page 8: Scalable and Available, Patterns for Success

Background

Understand the user experience!

Page 9: Scalable and Available, Patterns for Success

Background

Measure everything(can’t fix what you don’t know)

Page 10: Scalable and Available, Patterns for Success

Background

Don’t be a failure of your own success

Page 11: Scalable and Available, Patterns for Success

Background

• Good Performance is good

•Predictably Good Performance is king!

•Measure everything (can’t fix what you don’t know)

•Understand your data

•Understand your user experience

• Don’t be a failure of your own success

Master the Tradeoffs

(For your app and your data!)

Page 12: Scalable and Available, Patterns for Success

Performance vs Scalability

Master the Tradeoffs

Page 13: Scalable and Available, Patterns for Success

Latency vs Throughput

Master the Tradeoffs

Page 14: Scalable and Available, Patterns for Success

Availability vs Consistency

Master the Tradeoffs

Page 15: Scalable and Available, Patterns for Success

Lots of ways to skin a cat!

Page 16: Scalable and Available, Patterns for Success

Scalability Patterns

Page 17: Scalable and Available, Patterns for Success

Performancevs

Scalability

Page 18: Scalable and Available, Patterns for Success

How do I know if I have a performance problem?

If your system is slow for a single request/user

Page 19: Scalable and Available, Patterns for Success

How do I know if I have a scalability problem?

If your system is fast for a single request/user but slow for

many users

Page 20: Scalable and Available, Patterns for Success

Latencyvs

Throughput

Page 21: Scalable and Available, Patterns for Success

You should strive for

maximal throughputwith

acceptable latency

Page 22: Scalable and Available, Patterns for Success

Res

pons

e Ti

me

Concurrent Requests

Performance vs Scalability

Page 23: Scalable and Available, Patterns for Success

Know what to scale!

•CPU or IO Bound?

•Scale up or Scale out?

•Waiting on IO? What? Disk/Net/Other System?

•How many components are used per request?

•Know who and what the slowest will be!

Page 24: Scalable and Available, Patterns for Success

Scalability PatternsBehavior

Page 25: Scalable and Available, Patterns for Success

Scalability Patterns: Behavior

✓Event-Driven Architectures

✓Load-Balancing

✓Parallel Computing

Page 26: Scalable and Available, Patterns for Success

Event-Driven Architecture

✓Events

✓Messaging

✓Asynchronous

✓Non-blocking

Page 27: Scalable and Available, Patterns for Success

Messaging

✓Publish-Subscribe

✓Queuing

✓Request-Reply

✓Store and Forward

Page 28: Scalable and Available, Patterns for Success

Messaging - Publish Subscribe1 : N

Publisher Subject

Subscriber

Subscriber

Subscriber

Page 29: Scalable and Available, Patterns for Success

Messaging - Queuing1 : 1

Publisher Queue

Subscriber

Subscriber

Subscriber

Message #1

Page 30: Scalable and Available, Patterns for Success

Messaging - Queuing1 : 1

Publisher Queue

Subscriber

Subscriber

Subscriber

Message #2

Page 31: Scalable and Available, Patterns for Success

Messaging - Queuing1 : 1

Publisher Queue

Subscriber

Subscriber

Subscriber

Message #3

Page 32: Scalable and Available, Patterns for Success

Messaging - Request Reply1 : 1

Publisher Subject

Subscriber

Subscriber

Subscriber

Reply

Page 33: Scalable and Available, Patterns for Success

Messaging Patterns

✓Addressing, discovery

✓Command and control

✓Load-balancing

✓N-way scalability

Page 34: Scalable and Available, Patterns for Success

Messaging

✓Standards✓ AMQP (wire)

✓ JMS (api)

✓Products✓ RabbitMQ

✓ ZeroMQ

✓ ActiveMQ

✓ TIBCO

✓ MQSeries

Page 35: Scalable and Available, Patterns for Success

Asynchronous andNon-Blocking

✓Don’t wait, go doing something else

✓Never block

✓All callbacks all the time can get messy!

✓Good language/framework support

✓functional closures

✓co-routines

Page 36: Scalable and Available, Patterns for Success

Load Balancing

✓Multiple endpoints to perform work

✓Can be semantically aware

✓Chainable: DNS, hardware, software

✓Endpoints can be Hardware, VM, process, thread, co-routine, fiber, etc.

Page 37: Scalable and Available, Patterns for Success

Load BalancingSelection

✓Random

✓Round Robin

✓Weighted

✓Dynamically “aware”

✓Least connections

✓Least loaded

Page 38: Scalable and Available, Patterns for Success

Load BalancingTechnologies

✓DNS Round Robin

✓Anycast

✓Reverse Proxies

✓Clustering

✓Hardware Load Balancers

Page 39: Scalable and Available, Patterns for Success

Load BalancingReverse Proxies

✓Nginx

✓HAProxy

✓Apache (mod_proxy)

✓Squid

Page 40: Scalable and Available, Patterns for Success

Parallel Computing

✓Divide and Conquer

✓Worker queues

✓Map Reduce

✓UE = Unit of Execution

✓VM, process, thread, co-routine, fiber, callback

Page 41: Scalable and Available, Patterns for Success

Parallel ComputingWorker Queues

✓Good for offloading tasks

✓Need bounded time check in master

✓Async result processing

✓Fork/Join pattern

Page 42: Scalable and Available, Patterns for Success

Parallel ComputingMapReduce

✓Used internally at Google

✓Variation of Fork and Join

✓Distributed

✓Originally used for logs processing

Page 43: Scalable and Available, Patterns for Success

Parallel ComputingMapReduce

✓Google’s MapReduce

✓Hadoop

✓Amazon’s Elastic MapReduce

✓RIAK uses it internally for queries

Page 44: Scalable and Available, Patterns for Success

Scalability PatternsState

Page 45: Scalable and Available, Patterns for Success

Scalability Patterns: State

Harder than scaling behavior

Page 46: Scalable and Available, Patterns for Success

Scalability Patterns: State

✓Master Record

✓Replication

✓Sharding

✓Caching

✓NoSQL

✓Concurrency

Page 47: Scalable and Available, Patterns for Success

Master Record

✓Normally Relational Databases (RDBMS)

✓NoSQL Databases emerging

✓Can’t lose this data

✓Scaling can be a challenge

Page 48: Scalable and Available, Patterns for Success

Master Record: Scaling

✓Traditonally Scale Up

✓Technology will help here

✓SSD (50k-100k IOPs)

✓More memory/cores per box

✓Faster network connectivity

✓Clustering Appliances

Page 49: Scalable and Available, Patterns for Success

Clustering Appliances

64 bit

SSDInfiniband

Page 50: Scalable and Available, Patterns for Success

Master Record: Scaling

✓Scaling Reads vs Writes?

✓Scaling Reads with Slaves

✓Synchronous (Speed of Light)

✓Asynchronous

Page 51: Scalable and Available, Patterns for Success

Master Record: Scaling

How do we scale OUT?

Page 52: Scalable and Available, Patterns for Success

Master Record: Replication

✓Synchronous vs Asynchronous

✓Master / Slave Replication

✓Master / Master Replication

✓Tree Replication

✓Buddy Replication

Page 53: Scalable and Available, Patterns for Success

Replication: Master / Slave

Page 54: Scalable and Available, Patterns for Success

Replication: Master / Master

Page 55: Scalable and Available, Patterns for Success

Replication: Tree

Page 56: Scalable and Available, Patterns for Success

Replication: Buddy

Page 57: Scalable and Available, Patterns for Success

Sharding

✓Partitioning state

✓Requests need to know where to go

✓Distributed Hash

✓Load Balancer

✓Messaging

Page 58: Scalable and Available, Patterns for Success

Sharding: Paritioning

Page 59: Scalable and Available, Patterns for Success

Sharding: Replication

Page 60: Scalable and Available, Patterns for Success

Sharding: Over-provision

✓Use N partitions

✓Use Y replicas

✓Use message based requests

✓First back wins

✓Therefore user wins (Google Search)

Page 61: Scalable and Available, Patterns for Success

Master Record: RDBMS

Do we really need an RDBMS?

Page 62: Scalable and Available, Patterns for Success

Master Record: RDBMS

Don’t underestimate RDBMSor

the ability of a single machine

Page 63: Scalable and Available, Patterns for Success

Master Record: RDBMS

What about alternatives?

Page 64: Scalable and Available, Patterns for Success

NoSQL

✓Key-Value

✓Column Databases

✓Document Databases

✓Graph Databases

✓Datastructure Databases

Page 65: Scalable and Available, Patterns for Success

NoSQL

✓Key-Value: (Memcache, Redis, Riak)

✓Column Databases: (Cassandra, Vertica)

✓Document Databases: (MongoDB, CouchDB)

✓Graph Databases: (Neo4J, AllegroGraph)

✓Datastructure Databases: (Redis, Hazelcast)

Page 66: Scalable and Available, Patterns for Success

NoSQL in the wild

✓Google: Bigtable, Colossus

✓Twitter: Redis

✓Amazon: Dynamo, SimpleDB

✓Yahoo: HBase (Hadoop)

✓Facebook: Cassandra, HBase

Page 67: Scalable and Available, Patterns for Success

Caching

✓Cache early and often

✓Usually biggest bang for the buck

✓Referential Transparency

✓Polyglot APIs coming

✓NoSQL stores

✓Cache invalidation is still hard!

Page 68: Scalable and Available, Patterns for Success

Caching

✓HTTP (HTML, JS, CSS, Images, Media)

✓Key/Value Data

✓Semantic Data structures

Page 69: Scalable and Available, Patterns for Success

HTTP Caching

✓Varnish

✓Squid

✓Pound

✓Nginx

✓Rack-cache

Page 70: Scalable and Available, Patterns for Success

HTTP CachingCDN

✓Akamai

✓Limelight

✓Level3

✓Digital Fountain (Qualcomm)

✓aiCache

Page 71: Scalable and Available, Patterns for Success

HTTP CachingCDN

Page 72: Scalable and Available, Patterns for Success

HTTP Caching

✓Lives in browsers, proxies, CDNs, apps

✓Hard to control, so do it right!

✓Master page controls other resources

✓master page not cached (at least too far)

✓read-only resources

✓change link in master page

Page 73: Scalable and Available, Patterns for Success

Key/Value Caching

✓Memcache

✓Redis

✓Riak

✓Voldemort

Page 74: Scalable and Available, Patterns for Success

Data Structure Caching

Page 75: Scalable and Available, Patterns for Success

Data Structure Caching

✓Standalone

✓Augment RDBMS

✓In Memory or on Disk

Page 76: Scalable and Available, Patterns for Success

Data Structure Caching

✓Data Types

✓Strings, Hashes, Lists, Sets, Sorted Sets

✓Atomic Operations

✓Push, pop, ranges, set operations (intersect, union)

Page 77: Scalable and Available, Patterns for Success

Caching Patterns

✓Write Through

✓Write Behind

✓Replicated

✓P2P

Page 78: Scalable and Available, Patterns for Success

Cache Invalidation

✓TTL (Time to Live)

✓Bounded FIFO or LIFO

✓Explicit cache invalidation

✓Explicit non-use of read-only resource

✓Harder problem the more master items used

Page 79: Scalable and Available, Patterns for Success

Scalability Key Points

✓The problem is not where you think ;)

✓Autoscaling is a myth

✓Can’t fix what you can’t measure

✓Scaling master record writes is hard

✓Scaling reads is more tractable

✓What is the opex cost of your choices?

Page 80: Scalable and Available, Patterns for Success

Availability Patterns

Page 81: Scalable and Available, Patterns for Success

What do you do when things go

bad?

Page 82: Scalable and Available, Patterns for Success

Availability PatternsAvailable vs Consistent

Page 83: Scalable and Available, Patterns for Success

Availability PatternsAvailable

Page 84: Scalable and Available, Patterns for Success

We have been here before, right?

Page 85: Scalable and Available, Patterns for Success

Yes, we have been here before!?

Page 86: Scalable and Available, Patterns for Success

Scalability PatternsBehavior

Page 87: Scalable and Available, Patterns for Success

Scalability Patterns: Behavior

✓Event-Driven Architectures

✓Load-Balancing

✓Parallel Computing

Page 88: Scalable and Available, Patterns for Success

Scalability PatternsState

Page 89: Scalable and Available, Patterns for Success

Scalability Patterns: State

✓Master Record

✓Replication

✓Sharding

✓Caching

✓NoSQL

✓Concurrency

Page 90: Scalable and Available, Patterns for Success

But let’s talk more about your data

Page 91: Scalable and Available, Patterns for Success

Availability PatternsAvailable vs Consistent

Page 92: Scalable and Available, Patterns for Success

Brewer’s CAP Theorem

Page 93: Scalable and Available, Patterns for Success

Brewer’s CAP Theorem

Page 94: Scalable and Available, Patterns for Success

You can only pick 2

Consistency

Availability

Partition Tolerance

Page 95: Scalable and Available, Patterns for Success

Centralized Systems

✓If the system is centralized

✓no P (network partitions)

✓So you get both:

✓Availability

✓Consistency

Page 96: Scalable and Available, Patterns for Success

Distributed Systems

✓If the system is distributed

✓you will have P! (network partitions)

✓So you get pick one:

✓Availability

✓Consistency

Page 97: Scalable and Available, Patterns for Success

CAP in reality

✓There is only once choice to make:

✓When there is a network partition, which do you sacrifice?

✓Availability

✓Consistency

Page 98: Scalable and Available, Patterns for Success

BASE

Page 99: Scalable and Available, Patterns for Success

What is BASE?

Page 100: Scalable and Available, Patterns for Success

BASE

Basically

Available

Soft State

Eventually Consistent

Page 101: Scalable and Available, Patterns for Success

Eventually Consistent

✓Great tradeoff for the right kind of data

✓Can’t be used everywhere

✓Works in more places than you think

✓Solved speed of light problem

Page 102: Scalable and Available, Patterns for Success

Availability PatternsFailover

Page 103: Scalable and Available, Patterns for Success

Availability Patterns: Failover

✓Failover is complex

✓Switch time is critical

✓Failback is equally as complex

Page 104: Scalable and Available, Patterns for Success

Availability Patterns: Failover

Copyright Michael Nygaard

Page 105: Scalable and Available, Patterns for Success

Availability Patterns: Failback

Copyright Michael Nygaard

Page 106: Scalable and Available, Patterns for Success

✓Synchronous vs Asynchronous

✓Master / Slave Replication

✓Master / Master Replication

Availability Patterns: Replication

Page 107: Scalable and Available, Patterns for Success

✓DNS

✓Load Balancers

✓Secondary Sites

Availability Patterns: Redirection

Page 108: Scalable and Available, Patterns for Success

Availability Key Points

✓Always have a dial tone

✓Syntactically correct is good

✓Semantically correct is better

✓Be transparent

Page 109: Scalable and Available, Patterns for Success

Background

• Good Performance is good

•Predictably Good Performance is king!

•Measure everything (can’t fix what you don’t know)

•Understand your data

•Understand your user experience

• Don’t be a failure of your own success

Beating the dead horse

Page 110: Scalable and Available, Patterns for Success

Background

• Good Performance is good

•Predictably Good Performance is king!

•Measure everything (can’t fix what you don’t know)

•Understand your data

•Understand your user experience

• Don’t be a failure of your own success

Understand your data!

Page 111: Scalable and Available, Patterns for Success

Background

• Good Performance is good

•Predictably Good Performance is king!

•Measure everything (can’t fix what you don’t know)

•Understand your data

•Understand your user experience

• Don’t be a failure of your own success

Understand your user!

Page 112: Scalable and Available, Patterns for Success

Background

• Good Performance is good

•Predictably Good Performance is king!

•Measure everything (can’t fix what you don’t know)

•Understand your data

•Understand your user experience

• Don’t be a failure of your own success

Understand the

experience!

Page 113: Scalable and Available, Patterns for Success

Background

• Good Performance is good

•Predictably Good Performance is king!

•Measure everything (can’t fix what you don’t know)

•Understand your data

•Understand your user experience

• Don’t be a failure of your own success

Master the Tradeoffs

(For your app and your data!)

Page 114: Scalable and Available, Patterns for Success

Thank You

Page 115: Scalable and Available, Patterns for Success

Thank You

Page 116: Scalable and Available, Patterns for Success

Questions?