Professional Documents
Culture Documents
Chris Richardson Author of POJOs in Action Founder of the original CloudFoundry.com @crichardson chris.richardson@springsource.com http://plainoldobjects.com
@crichardson
Presentation goal
How decomposing applications improves deployability and scalability and How Cloud Foundry helps
@crichardson
About Chris
@crichardson
(About Chris)
@crichardson
About Chris()
@crichardson
About Chris
@crichardson
About Chris
http://www.theregister.co.uk/2009/08/19/springsource_cloud_foundry/
@crichardson
Signup at http://cloudfoundry.com
@crichardson
Agenda
The (sometimes evil) monolith Decomposing applications into services How do services communicate? Presentation layer design How Cloud Foundry helps
@crichardson
@crichardson
Browser
Apache
MySQL Database
Simple to
develop test deploy scale
Tomcat
@crichardson
@crichardson
HTML/Javascript hit
s d l O
U e l ty
c r a I
re u t ec
od o t g n is
gh u o en
Intimidates developers
@crichardson
Fear of change
Updates will happen less often e.g. Makes A/B testing UI really difcult
@crichardson
@crichardson
E-commerce application
Shipping team
@crichardson
@crichardson
@crichardson
@crichardson
Agenda
The (sometimes evil) monolith Decomposing applications into services How do services communicate? Presentation layer design How Cloud Foundry helps
@crichardson
@crichardson
ax
@crichardson
@crichardson
Accounting Service
StoreFrontUI
Inventory Service
Shipping Service
@crichardson
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
@crichardson
...Partitioning strategies
Too few Drawbacks of the monolithic architecture Too many - a.k.a. Nano-service anti-pattern Runtime overhead Potential risk of excessive network hops Potentially difcult to understand system
Something of an art
@crichardson
Example micro-service
require 'sinatra' post '/' do phone_number = params[:From] registration_url = "#{ENV['REGISTRATION_URL']}?phoneNumber=#{URI.encode(phone_number, "+")}" <<-eof <Response> <Sms>To complete registration please go to #{registration_url}</Sms> </Response> eof end
Density/efciency
@crichardson
@crichardson
@crichardson
Complexity
See Steve Yegges Google Platforms Rant re Amazon.com
@crichardson
@crichardson
@crichardson
@crichardson
@crichardson
@crichardson
@crichardson
@crichardson
http://dreamsongs.com/Files/WhitherSoftware.pdf
@crichardson
Agenda
The (sometimes evil) monolith Decomposing applications into services How do services communicate? Presentation layer design How Cloud Foundry helps
@crichardson
Accounting Service
wgrus-store.war
wgrus-inventory.war
StoreFrontUI
InventoryService
MySQL
wgrus-shipping.war
ShippingService
@crichardson
Benets
Decouples caller from server Caller unaware of servers coordinates (URL) Message broker buffers message when server is down/ slow Supports a variety of communication patterns, e.g. pointto-point, pub-sub, ...
@crichardson
Drawbacks
@crichardson
@crichardson
Call in parallel
Service A
c = serviceC()
Service C
d = serviceD(b, c)
Service D
@crichardson
public void doSomething() throws ... { Future<Integer> result = executorService.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { return remoteServiceProxy.invokeRemoteService(); } }); /// Do other things int r = result.get(500, TimeUnit.MILLISECONDS); System.out.println(r); } }
@crichardson
Guava ListenableFutures = better Scalas composable Futures = really good Java 8 CompletableFuture = great
@crichardson
Composable Futures
val f1 = Future { val f2 = Future { ... ; 1 } ... ; 2 }
Transforms Future
http://doc.akka.io/docs/akka/2.0.1/scala/futures.html
@crichardson
http://doc.akka.io/docs/akka/2.0.1/scala/futures.html
@crichardson
Spring Integration
Provides the building blocks for a pipes and lters architecture Enables development of application components that are loosely coupled insulated from messaging infrastructure Messaging dened declaratively
@crichardson
Down? Slow?
@crichardson
About Netix
> 1B API calls/day 1 API call average 6 service calls
http://techblog.netix.com/2012/02/fault-tolerance-in-high-volume.html
@crichardson
Service A
Service B
Thread X 2
X 3 Thread
Thread X n
Execute thread pool
X
@crichardson
Tomcat
Their approach
Network timeouts and retries Invoke remote services via a bounded thread pool Use the Circuit Breaker pattern On failure: return default/cached data return error to caller https://github.com/Netix/Hystrix
Agenda
The (sometimes evil) monolith Decomposing applications into services How do services communicate? Presentation layer design How Cloud Foundry helps
@crichardson
HTML / HTTP
Browser
View
Controller Model
@crichardson
View
HTML 5 JavaScript
Events
@crichardson
@crichardson
Why NodeJS?
Familiar Javascript High-performance, scalable event-driven, non-blocking I/O model Compact runtime Over 17,000 modules developed by the community Simple event publishing using socket.io or SockJS
@crichardson
@crichardson
RESTful WS
Node JS
Server application
Events Socket.io server
@crichardson
@crichardson
Socket.io server-side
var express = require('express') , http = require('http') , amqp = require(amqp) ....; server.listen(8081); ... var amqpCon = amqp.createConnection(...); io.sockets.on('connection', function (socket) { function amqpMessageHandler(message, headers, deliveryInfo) { Republish var m = JSON.parse(message.data.toString()); socket.emit(tick, m); as socket.io }; event amqpCon.queue(, {}, function(queue) { queue.bind(myExchange, ); queue.subscribe(amqpMessageHandler); Subscribe to }); }); AMQP queue
https://github.com/cer/nodejs-clock
@crichardson
Bind to model
Connect to socket.io
clock.js var socket = io.connect(location.hostname); function ClockModel() { self.ticker = ko.observable(1); socket.on('tick', function (data) { self.ticker(data); }); }; ko.applyBindings(new ClockModel());
@crichardson
Agenda
The (sometimes evil) monolith Decomposing applications into services How do services communicate? Presentation layer design How Cloud Foundry helps
@crichardson
Original architecture
WAR
Browser
Apache
InventoryService
MySQL Database
Shipping
Tomcat
@crichardson
H ow
w e t de e d s pl t ev oy el o th p, is ?
Native Mobile application StoreUI StoreUI NodeJS StoreUI RabbitMQ Shipping Service
Modern architecture
Javascript
do
Inventory Service
an
Billing Service
@crichardson
@crichardson
vFabric Postgres
p Ap
vFabric RabbitMQTM
lica
Data Services
'o
Additional partners services
Msg Services
Other Services
@crichardson
@crichardson
Path to application
@crichardson
Path to application
@crichardson
vmc push: Reads the manifest le Creates the required platform services Deploys all the applications
@crichardson
App Instances
Services
10.04
@crichardson
@crichardson
Your computer
Cloud Foundry
@crichardson
$ vmc tunnel 1: mysql-135e0 2: mysql1 Which service to tunnel to?: 2 Password: ********
Using Caldecott
Stopping Application: OK Redeploying tunnel application 'caldecott'. Uploading Application: Checking for available resources: OK Packing application: OK Uploading (1K): OK Push Status: OK Binding Service [mysql1]: OK Staging Application: OK Starting Application: OK Getting tunnel connection info: OK Service connection info: username : uMe6Apgw00AhS password : pKcD76PcZR7GZ name : d7cb8afb52f084f3d9bdc269e7d99ab50 Starting tunnel to mysql1 on port 10000. 1: none 2: mysql Which client would you like to start?: 2
@crichardson
Launching 'mysql --protocol=TCP --host=localhost --port=10000 -user=uMe6Apgw00AhS --password=pKcD76PcZR7GZ d7cb8afb52f084f3d9bdc269e7d99ab50' Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10944342 Server version: 5.1.54-rel12.5 Percona Server with XtraDB (GPL), Release 12.5, Revision 188 Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Using Caldecott
@crichardson
@crichardson
Summary
@crichardson
Monolithic applications are simple to develop and deploy BUT have signicant drawbacks
@crichardson
@crichardson
Private Clouds
Public Clouds
Micro Clouds
@crichardson
Questions?
www.cloudfoundry.com
@crichardson