Developing web applications used to be simple. Your single war-file web application served up HTML to a desktop browser and used a relational database. Today however, web applications are much more complex: the front-end uses HTML5 and NodeJS, the middle tier is decomposed into multiple services, and the back-end uses a mix of SQL and NoSQL databases. Developing these kind of applications can be challenging since there are so many moving parts that need to be correctly installed and configured. Deployment is even more difficult.
In this talk, you will learn why we need to build applications with this architectural style and how Cloud Foundry, which is modern, multi-lingual, multi-service, extensible open-source PaaS, can help. We will talk about how to develop modern applications that run on Cloud Foundry and cover what’s new and different about the cloud environment. You will learn how your application can consume the various services that are provided by Cloud Foundry. We will discuss the various ways of using Cloud Foundry including the Micro Cloud that runs on a laptop as well as the hosted CloudFoundry.com.
Boost PC performance: How more available memory can improve productivity
Developing polyglot applications on Cloud Foundry (#oredev 2012)
1. Developing polyglot applications
on Cloud Foundry
Chris Richardson
Author of POJOs in Action
Founder of the original CloudFoundry.com
@crichardson
crichardson@vmware.com
http://plainoldobjects.com/
2. Presentation goal
Modular, polyglot applications:
what, why and how?
How Cloud Foundry simplifies
their development and deployment
11. Traditional web application
architecture
WAR
StoreFrontUI
Accounting
Service
MySQL
Browser Apache Database
InventoryService
Simple to Shipping
Service
develop
test Tomcat
deploy
scale
13. Users expect a rich, dynamic and
interactive experience
h
oug
d en
HTTP Request
oo
’t g
Browser
e isn Java Web Application
HTML/Javascript
ec tur
it
ar ch
e UI
s tyl
Old
Real-time web ≅ NodeJS
14. Limitations of relational
databases
• Scalability
• Distribution
• Schema updates
• O/R impedance mismatch
• Handling semi-structured data
17. Obstacle to frequent
deployments
• Need to redeploy everything to change one component
• Increases risk of failure, e.g. interrupts background jobs
Fear of change
• Extensive test cycle
• Updates will happen less often, e.g. Makes A/B testing UI really difficult
21. Agenda
• The (sometimes evil) monolith
• Refactoring to a modular, polyglot architecture
• Decomposing applications into services
• Using NoSQL
• Presentation layer design
• Deploying modular, polyglot applications
22.
23. The scale cube
Y axis -
functional
decomposition
ila g
sim nin
Scale by
r
ing ing tio
splitting
th litt r ti
sp pa
different things
by data
s
ale -
Sc is
ax
Z
X axis - horizontal
duplication
24. Y-axis scaling - application level
WAR
StoreFrontUI
Accounting
Service
InventoryService
Shipping
Service
25. Y-axis scaling - application level
accounting application
Accounting
Service
Store front web application inventory application
StoreFrontUI InventoryService
shipping application
Shipping
Service
Apply X axis cloning and/or Z axis partitioning to each service
26. Drawbacks of Y-axis splits
• Complexity
• Partitioned databases and transaction management
• Deciding when to use this approach
27. But there are many benefits
• Scales
development: develop, deploy and scale each service
independently
• Less for each developer to learn
• Doesn’t overload IDE or container
• Improves fault isolation
• Eliminates long-term commitment to a single technology stack
28. Two levels of architecture
System-level
Services
Inter-service glue: interfaces and communication mechanisms
Slow changing
Service-level
Internal architecture of each service
Each service can use a different technology stack
Pick the best tool for the job
Rapidly evolving - regularly rewrite
30. Inter-service communication
options
• Transports: Synchronous HTTP asynchronous AMQP
• Formats: JSON, XML, Protocol Buffers, Thrift, ...
Asynchronous is preferred but REST
is fine
JSON is fashionable but binary format
is more efficient
31. Asynchronous message-based communication
accounting application
Accounting
Service
storefront web application inventory application
RabbitMQ
StoreFrontUI (Message InventoryService
MySQL
Broker)
shipping application
ShippingService
32. Agenda
• The (sometimes evil) monolith
• Refactoring to a modular, polyglot architecture
• Decomposing applications into services
• Using NoSQL
• Presentation layer design
• Deploying modular, polyglot applications
41. Why NodeJS?
• Familiar JavaScript
• High-performance, scalable event-driven, non-blocking I/O
model
• Over 13,000 17,000 modules developed by the community
• ManyJavaScript client frameworks have a NodeJS
counterpart, e.g. socket.io and SockJS
43. A modern web application
REST Node JS Service 1
Browser
Service 2
Events
HTML 5 Server
Application Application
Socket.io Socket.io
client server ...
44. NodeJS as a mediator
REST REST
Service
Node JS
Events AMQP AMQP
socket.io RabbitMQ Service
45. Socket.io - server-side
var express = require('express')
, http = require('http')
, amqp = require(‘amqp’)
....;
server.listen(8081); Handle socket.io
... connection
var amqpCon = amqp.createConnection(...);
io.sockets.on('connection', function (socket) {
Republish as
function amqpMessageHandler(message, headers, deliveryInfo) { socket.io event
var m = JSON.parse(message.data.toString());
socket.emit(‘tick’, m);
};
amqpCon.queue(“myQueue”, {},
function(queue) { Subscribe to AMQP
queue.bind(“myExchange”, “myBindingKey”);
queue.subscribe(amqpMessageHandler);
queue
});
});
46. Socket.io - client-side
<html>
<body>
The event is <span data-bind="text: ticker"></span>
<script src="/socket.io/socket.io.js"></script>
<script src="/knockout-2.0.0.js"></script>
<script src="/clock.js"></script>
</body> Bind to model Connect to
</html>
socket.io server
clock.js
var socket = io.connect(location.hostname);
function ClockModel() {
self.ticker = ko.observable(1); Subscribe to tick
socket.on('tick', function (data) { event
self.ticker(data);
});
};
Update model
ko.applyBindings(new ClockModel());
47. Modular, polyglot architecture
p,
Native Mobile application HTML5 mobile application
lo
Desktop Browser
StoreUI StoreUI StoreUI
ve
de
Asynchronous, NodeJS
?
NodeJS Javascript
scalable
is
StoreUI
communication
th
te e
w RabbitMQ
st
oy
do
Spring/Scala Standalone
web application Inventory
Inventory Shipping Service “headless”
pl
Service Shipping
Service Spring/Java
ow
applications
de
Billing Service Redis Inventory Mongo Order
H
Database Database
d
an
MySQL
Customer
Database
48. Agenda
• The (sometimes evil) monolith
• Refactoring to a modular, polyglot architecture
• Deploying modular, polyglot applications
• Overview of Cloud Foundry
• Using Cloud Foundry
• Consuming Cloud Foundry services
49. The Open
Platform as a Service
Deploy and scale polyglot
applications in seconds, without
locking yourself into a single
cloud ible,
pen , Flex
Sim ple, O lable
Sca
50. OSS community
vFabric
Postgres Ap
Private
Clouds
p
Data Services
lica
'o
n
S
vFabric
Public
erv
RabbitMQTM
ice
Msg Services
Clouds
In
ter
fac
Micro
e
Other Services
Clouds
Additional partners services …
52. Micro Cloud – FoundryTM
Industry first downloadable PaaS
App Instances Services
Open source Platform as a Service project
A cloud packaged as a VMware Virtual Machine
53. CloudFoundry.ORG - Vibrant Apache
2 licensed open-source project
CloudFoundry.ORG
Your Infrastructure
Download Setup Deploy Behind
Code Environment BOSH Firewall
54. Cloud Foundry: you can trade-off
Less
effort vs flexibility Less
Public PaaS
....
.COM
Private PaaS
Effort .... Flexibility
Custom Private PaaS
git clone git://github.com/cloudfoundry/vcap.git
More More
55. Agenda
• The (sometimes evil) monolith
• Refactoring to a modular, polyglot architecture
• Deploying modular, polyglot applications
• Overview of Cloud Foundry
• Using Cloud Foundry
• Consuming Cloud Foundry services
58. Sinatra + Redis
require 'sinatra'
require 'redis' Connect to Redis
configure do
$r = Redis.new(:host => '127.0.0.1', :port => '6379') if !$r
end
get '/' do
"Hello World! " + $r.incr("hitcounter").to_s
end
Increment hit
counter
http://sgce2012.cloudfoundry.com/
62. One step deployment
$ vmc push
Would you like to deploy from the current directory? [Yn]:
Pushing application 'inventory'...
Creating Application: OK
Creating Service [si-rabbit]: OK
Binding Service [si-rabbit]: OK
Creating Service [si-mongo]: OK
Binding Service [si-mongo]: OK
vmc push:
Creating Service [si-redis]: OK •Reads the manifest file
Binding Service [si-redis]: OK •Creates the required platform services
Uploading Application:
•Deploys all the applications
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (12K): OK
Push Status: OK
Staging Application 'inventory': OK
Starting Application 'inventory': OK
Pushing application 'store'...
63. Micro Cloud Foundry =
your sandbox
App Instances Services
Open source Platform as a Service project
10.04
A PaaS packaged as a VMware Virtual Machine
Use as a developer sandbox
• Use the services from Junit integration tests
• Deploy your application for functional testing
• Remote debugging from STS
64. Agenda
• The (sometimes evil) monolith
• Refactoring to a modular, polyglot architecture
• Deploying modular, polyglot applications
• Overview of Cloud Foundry
• Using Cloud Foundry
• Consuming Cloud Foundry services
66. Creating a service instance
$ vmc create-service mysql mysql1
Creating Service: OK
$ vmc services
......
=========== Provisioned Services ============
+-------------+---------+
| Name | Service |
+-------------+---------+
| mysql1 | mysql |
+-------------+---------+
$
67. Binding a service to an
application
$ vmc push cer-spring --path web/target/
Application Deployed URL [cer-spring.cloudfoundry.com]:
Detected a Java SpringSource Spring Application, is this correct? [Yn]:
Memory Reservation (64M, 128M, 256M, 512M, 1G) [512M]:
Creating Application: OK
Would you like to bind any services to 'cer-spring'? [yN]: y [yN]: y
Would you like
to bind any services to 'cer-spring'?
Would you like to use anan existing provisioned service? [yN]: y
Would you like
to use existing provisioned service? [yN]: y
The The following provisioned servicesavailable
following provisioned services are are available
1: mysql1
1: mysql1
2: mysql-135e0
2: mysql-135e0
Please select one you wish to use:use: 1
Please select one you wish to 1
Binding Service [mysql1]: OK OK
Binding Service [mysql1]:
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (12K): OK
75. Can we build software systems
with these characteristics?
http://dreamsongs.com/Files/
DesignBeyondHumanAbilitiesSimp.pdf
http://dreamsongs.com/Files/
WhitherSoftware.pdf