decomposing applications for deployability and scalability (cfopentour india)

53
Decomposing applications for deployability and scalability Chris Richardson Author of POJOs in Action Founder of the original CloudFoundry.com @crichardson [email protected] http://plainoldobjects.com/ 1

Upload: chris-richardson

Post on 10-May-2015

761 views

Category:

Technology


4 download

DESCRIPTION

30 minute version of the talk given in Bangalore and India in Sept 2012

TRANSCRIPT

Page 1: Decomposing applications for deployability and scalability (cfopentour india)

Decomposing applications for deployability and scalability

Chris Richardson

Author of POJOs in ActionFounder of the original CloudFoundry.com

@[email protected]://plainoldobjects.com/

1

Page 2: Decomposing applications for deployability and scalability (cfopentour india)

Presentation goal

2

How decomposing applications improves

deployability and scalability

Page 3: Decomposing applications for deployability and scalability (cfopentour india)

vmc push About-Chris

3

Developer Advocate for CloudFoundry.com

Signup at http://cloudfoundry.com cfopentour2012

Page 4: Decomposing applications for deployability and scalability (cfopentour india)

4

Agenda§The (sometimes evil) monolith§Decomposing applications into services§How do services communicate?

Page 5: Decomposing applications for deployability and scalability (cfopentour india)

Let’s imagine you are building an e-commerce application

5

Page 6: Decomposing applications for deployability and scalability (cfopentour india)

Tomcat

Traditional web application architecture

6

Browser

WAR

MySQL Database

ShippingService

AccountingService

InventoryService

StoreFrontUI

developtestdeploy

Simple to

Apache

scale

Page 7: Decomposing applications for deployability and scalability (cfopentour india)

But there are problems with a monolithic architecture

7

Page 8: Decomposing applications for deployability and scalability (cfopentour india)

Users expect a rich, dynamic and interactive experience

8

Java Web Application

Browser

HTTP Request

HTML/Javascript

Old style UI architecture isn’t good enough

Real-time web ≅ NodeJS

Page 9: Decomposing applications for deployability and scalability (cfopentour india)

Obstacle to frequent deployments§Need to redeploy everything to change one component§Interrupts long running background (e.g. Quartz) jobs§Increases risk of failure

Fear of change

§Updates will happen less often§e.g. Makes A/B testing UI really difficult

9

Page 10: Decomposing applications for deployability and scalability (cfopentour india)

Overloads your IDE and container

10Slows down development

Page 11: Decomposing applications for deployability and scalability (cfopentour india)

11

Shipping team

Accounting team

Engineering

Obstacle to scaling development

E-commerce application

Page 12: Decomposing applications for deployability and scalability (cfopentour india)

12

WAR

Shipping

Accounting

InventoryService

StoreFrontUI

Shipping team

Accounting team

Inventory team

UI team

Obstacle to scaling development

Page 13: Decomposing applications for deployability and scalability (cfopentour india)

13

Lots of coordination and communication required

Obstacle to scaling development

Page 14: Decomposing applications for deployability and scalability (cfopentour india)

14

Requires long-term commitment to a technology

stack

Page 15: Decomposing applications for deployability and scalability (cfopentour india)

15

Agenda§The (sometimes evil) monolith§Decomposing applications into services§How do services communicate?

Page 16: Decomposing applications for deployability and scalability (cfopentour india)

16

Page 17: Decomposing applications for deployability and scalability (cfopentour india)

The scale cube

17

X axis - horizontal duplication

Z axis

- data

parti

tionin

g

Y axis - functionaldecomposition

Scale

by sp

litting

simila

r

thing

s

Scale by splitting different things

Page 18: Decomposing applications for deployability and scalability (cfopentour india)

Y-axis scaling - application level

18

WAR

ShippingService

AccountingService

InventoryService

StoreFrontUI

Page 19: Decomposing applications for deployability and scalability (cfopentour india)

Y-axis scaling - application level

19

Store front web application

shipping web application

inventory web application

Apply X axis cloning and/or Z axis partitioning to each service

ShippingService

AccountingService

InventoryServiceStoreFrontUI

accounting web application

Page 20: Decomposing applications for deployability and scalability (cfopentour india)

Partitioning strategies§Partition by verb, e.g. shipping service§Partition by noun, e.g. inventory service§Single Responsibility Principle§Unix utilities - do one focussed thing well

20

Something of an art

Page 21: Decomposing applications for deployability and scalability (cfopentour india)

Real world examples

21

http://highscalability.com/amazon-architecture

Between 100-150 services are accessed to build a page.

http://techblog.netflix.com/

http://www.addsimplicity.com/downloads/eBaySDForum2006-11-29.pdf

http://queue.acm.org/detail.cfm?id=1394128

Page 22: Decomposing applications for deployability and scalability (cfopentour india)

There are drawbacks

22

Page 23: Decomposing applications for deployability and scalability (cfopentour india)

Complexity

23

See Steve Yegge’s Google Platforms Rant re Amazon.com

Page 24: Decomposing applications for deployability and scalability (cfopentour india)

Multiple databases =

Transaction management challenges

24

Page 25: Decomposing applications for deployability and scalability (cfopentour india)

When to use it?

25

In the beginning: •You don’t need it •It will slow you down

Later on:•You need it•Refactoring is painful

Page 26: Decomposing applications for deployability and scalability (cfopentour india)

But there are many benefits§Scales development: develop, deploy and scale each service independently§Update UI independently§Improves fault isolation§Eliminates long-term commitment to a single technology stack

26

Modular, polyglot, multi-framework applications

Page 27: Decomposing applications for deployability and scalability (cfopentour india)

Two levels of architecture

27

System-level

ServicesInter-service glue: interfaces and communication mechanismsSlow changing

Service-level

Internal architecture of each serviceEach service could use a different technology stackPick the best tool for the jobRapidly evolving

Page 28: Decomposing applications for deployability and scalability (cfopentour india)

If services are small...§Regularly rewrite using a better technology stack§Adapt system to changing requirements and better technology without a total rewrite§Pick the best developers rather than best <pick a language> developers ⇒ polyglot culture

28

Fred George “Developer Anarchy”

Page 29: Decomposing applications for deployability and scalability (cfopentour india)

The human body as a system

29

Page 30: Decomposing applications for deployability and scalability (cfopentour india)

50 to 70 billion of your cells die each day

30

Page 31: Decomposing applications for deployability and scalability (cfopentour india)

Yet you (the system) remain you

31

Page 32: Decomposing applications for deployability and scalability (cfopentour india)

Can we build software systems with these characteristics?

32

http://dreamsongs.com/Files/WhitherSoftware.pdf

http://dreamsongs.com/Files/DesignBeyondHumanAbilitiesSimp.pdf

Page 33: Decomposing applications for deployability and scalability (cfopentour india)

33

Agenda§The (sometimes evil) monolith§Decomposing applications into services§How do services communicate?

Page 34: Decomposing applications for deployability and scalability (cfopentour india)

Inter-service communication options§Synchronous HTTP ⇔ asynchronous AMQP

§Formats: JSON, XML, Protocol Buffers, Thrift, ...

§Even via the database

34

Asynchronous is preferred

JSON is fashionable but binary format is more efficient

Page 35: Decomposing applications for deployability and scalability (cfopentour india)

StoreFrontUI

wgrus-store.war

AccountingService

wgrus-billing.war

InventoryService

wgrus-inventory.war

ShippingService

wgrus-shipping.war

MySQL

35

RabbitMQ(Message Broker)

Asynchronous message-based communication

Page 36: Decomposing applications for deployability and scalability (cfopentour india)

Benefits§Decouples caller from server§Caller unaware of server’s coordinates (URL)§Message broker buffers message when server is down/slow

36

Page 37: Decomposing applications for deployability and scalability (cfopentour india)

Drawbacks§Additional complexity of message broker §RPC using messaging is more complex

37

Page 38: Decomposing applications for deployability and scalability (cfopentour india)

Writing code that calls services

38

Page 39: Decomposing applications for deployability and scalability (cfopentour india)

The need for parallelism

39

Service A

Service B

Service C

Service D

b = serviceB()

c = serviceC()

d = serviceD(b, c)

Call in parallel

Page 40: Decomposing applications for deployability and scalability (cfopentour india)

Java Futures are a great concurrency abstraction

40

http://en.wikipedia.org/wiki/Futures_and_promises

Page 41: Decomposing applications for deployability and scalability (cfopentour india)

Akka’s composable futures are even better

41

Page 42: Decomposing applications for deployability and scalability (cfopentour india)

Using Akka futures

42

def callB() : Future[...] = ...def callC() : Future[...] = ...def callD() : Future[...] = ...

val future = for { (b, c) <- callB() zip callC(); d <- callD(b, c) } yield d

val result = Await.result(future, 1 second)

http://doc.akka.io/docs/akka/2.0.1/scala/futures.html

Two calls execute in parallel

And then invokes D

Get the result of D

Page 43: Decomposing applications for deployability and scalability (cfopentour india)

Spring Integration§Implements EAI patterns§Provides the building blocks for a pipes and filters architecture§Enables development of application components that are•loosely coupled•insulated from messaging infrastructure

§Messaging defined declaratively

43

Page 44: Decomposing applications for deployability and scalability (cfopentour india)

Handling failure

44

Service A Service B

Errors happen in distributed systems

Page 45: Decomposing applications for deployability and scalability (cfopentour india)

About Netflix

45

> 1B API calls/day1 API call ⇒ average 6 service calls

Fault tolerance is essential

http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html

Page 46: Decomposing applications for deployability and scalability (cfopentour india)

Use timeouts and retries

46

Never wait forever

Errors can be transient ⇒ retry

http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html

Page 47: Decomposing applications for deployability and scalability (cfopentour india)

Service A

Service B

Use per-dependency bounded thread pool

47http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html

Runnable 1

Runnable 2

Runnable ...

bounded queue

Task 1

Task 2

Task ...

bounded thread pool

Limits number of outstanding requests

Fails fast if service is slow or down

Page 48: Decomposing applications for deployability and scalability (cfopentour india)

Use a circuit breakerHigh error rate ⇒ stop calling temporarily

Down ⇒ wait for it to come back up

Slow ⇒ gives it a chance to recover

48http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html

Page 49: Decomposing applications for deployability and scalability (cfopentour india)

On failureReturn cached data

Return default data

Fail fast

49http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html

AvoidFailing

Page 50: Decomposing applications for deployability and scalability (cfopentour india)

Summary

50

Page 51: Decomposing applications for deployability and scalability (cfopentour india)

Monolithic applications are simple to develop and deploy

BUT have significant drawbacks

51

Page 52: Decomposing applications for deployability and scalability (cfopentour india)

Apply the scale cube

52

X axis - horizontal duplicationZ ax

is - d

ata pa

rtitio

ning

Y axis - functionaldecomposition

§Modular, polyglot, and scalable applications§Services developed, deployed and scaled independently

Page 53: Decomposing applications for deployability and scalability (cfopentour india)

Questions?

@crichardson [email protected]://slideshare.net/chris.e.richardson/

www.cloudfoundry.com promo code: cfopentour2012