Developing polyglot applications on Cloud Foundry (#oredev 2012)

  • 1,497 views
Uploaded on

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 …

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,497
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
19
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Developing polyglot applications on Cloud FoundryChris RichardsonAuthor of POJOs in ActionFounder of the original CloudFoundry.com @crichardsoncrichardson@vmware.comhttp://plainoldobjects.com/
  • 2. Presentation goal Modular, polyglot applications: what, why and how? How Cloud Foundry simplifiestheir development and deployment
  • 3. About Chris
  • 4. (About Chris)
  • 5. About Chris()
  • 6. About Chris
  • 7. About Chrishttp://www.theregister.co.uk/2009/08/19/ springsource_cloud_foundry/
  • 8. vmc push About-Chris Developer Advocate for CloudFoundry.comSignup at http://cloudfoundry.com
  • 9. Agenda• The (sometimes evil) monolith• Refactoring to a modular, polyglot architecture• Deploying modular, polyglot applications
  • 10. Let’s imagine you are building an e-commerce application
  • 11. Traditional web application architecture WAR StoreFrontUI Accounting Service MySQLBrowser Apache Database InventoryServiceSimple to Shipping Service develop test Tomcat deploy scale
  • 12. But there are problems
  • 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
  • 15. Monolithic architecture = Problems
  • 16. Intimidates developers
  • 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
  • 18. Overloads your IDE and container Slows down development
  • 19. Obstacle to scaling development But the I want to update backend is not the UI working yet! Lots of coordination and communication required
  • 20. Requires long-term commitment to a technology stack
  • 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. The scale cubeY axis -functionaldecomposition ila g sim ninScale by r ing ing tiosplitting th litt r ti sp padifferent things by data s ale - Sc is ax Z X axis - horizontal duplication
  • 23. Y-axis scaling - application level WAR StoreFrontUI Accounting Service InventoryService Shipping Service
  • 24. Y-axis scaling - application level accounting application Accounting ServiceStore front web application inventory application StoreFrontUI InventoryService shipping application Shipping Service Apply X axis cloning and/or Z axis partitioning to each service
  • 25. Drawbacks of Y-axis splits• Complexity• Partitioned databases and transaction management• Deciding when to use this approach
  • 26. 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
  • 27. Two levels of architecture System-levelServicesInter-service glue: interfaces and communication mechanismsSlow changing Service-levelInternal architecture of each serviceEach service can use a different technology stackPick the best tool for the jobRapidly evolving - regularly rewrite
  • 28. Modular, polyglot, applications
  • 29. 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
  • 30. Asynchronous message-based communication accounting application Accounting Servicestorefront web application inventory application RabbitMQ StoreFrontUI (Message InventoryService MySQL Broker) shipping application ShippingService
  • 31. Agenda• The (sometimes evil) monolith• Refactoring to a modular, polyglot architecture • Decomposing applications into services • Using NoSQL • Presentation layer design• Deploying modular, polyglot applications
  • 32. Solution: Use NoSQL Benefits Drawbacks• Higher performance • Limited transactions• Higher scalability • Limited querying• Richer data-model • Relaxed consistency• Schema-less • Unconstrained data
  • 33. Example NoSQL DatabasesDatabase Key featuresCassandra Extensible column store, very scalable, distributed Neo4j Graph database Document-oriented, fast, scalableMongoDB Redis Key-value store, very fast http://nosql-database.org/ lists 122+ NoSQL databases
  • 34. NoSQL and the scale cube nin a ing itio dr rd r t an ha pa ss s Ca DB g go on M MongoDB replica sets Cassandra replication
  • 35. The future is polyglot IEEE Software Sept/October 2010 - Debasish Ghosh / Twitter @debasishg
  • 36. Polyglot persistence architecture accounting application Accounting Service MySQLstorefront web application inventory application RabbitMQ StoreFrontUI (Message InventoryService Redis Broker) shipping application ShippingService Mongo
  • 37. Agenda• The (sometimes evil) monolith• Refactoring to a modular, polyglot architecture • Decomposing applications into services • Using NoSQL • Presentation layer design• Deploying modular, polyglot applications
  • 38. Modular applicationChoice of presentation layer technology
  • 39. NodeJS is the fashionable technology
  • 40. 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
  • 41. Why not NodeJS? a.k.a. callback hell
  • 42. A modern web application REST Node JS Service 1Browser Service 2 Events HTML 5 ServerApplication ApplicationSocket.io Socket.io client server ...
  • 43. NodeJS as a mediatorREST REST Service Node JSEvents AMQP AMQP socket.io RabbitMQ Service
  • 44. Socket.io - server-sidevar express = require(express) , http = require(http) , amqp = require(‘amqp’) ....;server.listen(8081); Handle socket.io... connectionvar 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 });});
  • 45. 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.jsvar 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 modelko.applyBindings(new ClockModel());
  • 46. Modular, polyglot architecture p, Native Mobile application HTML5 mobile application lo Desktop Browser StoreUI StoreUI StoreUI ve deAsynchronous, NodeJS ? NodeJS Javascript scalable is StoreUIcommunication th te e w RabbitMQ st oy do Spring/Scala Standaloneweb 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
  • 47. 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
  • 48. The Open Platform as a Service Deploy and scale polyglotapplications in seconds, without locking yourself into a single cloud ible, pen , Flex Sim ple, O lable Sca
  • 49. OSS community vFabricPostgres 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 …
  • 50. CloudFoundry.COM - Multi-tenant PaaS operated by VMware CloudFoundry.COM (beta) Services Runtimes & Frameworks vCenter / vSphere Infrastructure
  • 51. Micro Cloud – FoundryTMIndustry first downloadable PaaS App Instances Services Open source Platform as a Service project A cloud packaged as a VMware Virtual Machine
  • 52. CloudFoundry.ORG - Vibrant Apache 2 licensed open-source project CloudFoundry.ORG Your Infrastructure Download Setup Deploy Behind Code Environment BOSH Firewall
  • 53. Cloud Foundry: you can trade-off Less effort vs flexibility Less Public PaaS .... .COM Private PaaSEffort .... Flexibility Custom Private PaaS git clone git://github.com/cloudfoundry/vcap.git More More
  • 54. 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
  • 55. Using Cloud Foundry
  • 56. Example vmc commands$ vmc target <any cloud>$ vmc login <credentials>$ vmc push <my-app> > bind services? Yes$ vmc update <my-app>$ vmc instances <my-app> +100
  • 57. Sinatra + Redisrequire sinatrarequire redis Connect to Redisconfigure do $r = Redis.new(:host => 127.0.0.1, :port => 6379) if !$rendget / do "Hello World! " + $r.incr("hitcounter").to_send Increment hit counterhttp://sgce2012.cloudfoundry.com/
  • 58. One step deployment---applications: ./storefront: Path to application name: nodestore framework: name: node info: mem: 64M description: Node.js Application exec: url: ${name}.${target-base} mem: 64M instances: 1 services: si-redis: Required platform services type: redis si-rabbit: type: rabbitmq
  • 59. One step deploymentapplications: standalone-inventory/target/appassembler: Path to application name: standalone-shipping framework: name: standalone info: description: Standalone Application exec: runtime: java command: bin/standalone-shipping url: mem: 512M instances: 1 services: Required platform services si-rabbit: type: rabbitmq si-mongo: type: mongodb
  • 60. One step deployment$ vmc pushWould you like to deploy from the current directory? [Yn]:Pushing application inventory...Creating Application: OKCreating Service [si-rabbit]: OKBinding Service [si-rabbit]: OKCreating Service [si-mongo]: OKBinding Service [si-mongo]: OK vmc push:Creating Service [si-redis]: OK •Reads the manifest fileBinding Service [si-redis]: OK •Creates the required platform servicesUploading Application: •Deploys all the applications Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (12K): OKPush Status: OKStaging Application inventory: OKStarting Application inventory: OKPushing application store...
  • 61. Micro Cloud Foundry = your sandbox App Instances ServicesOpen source Platform as a Service project 10.04A 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
  • 62. 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
  • 63. Cloud Foundry services
  • 64. Creating a service instance$ vmc create-service mysql mysql1Creating Service: OK$ vmc services......=========== Provisioned Services ============+-------------+---------+| Name | Service |+-------------+---------+| mysql1 | mysql |+-------------+---------+$
  • 65. 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: OKWould 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]: yThe The following provisioned servicesavailable following provisioned services are are available1: mysql1 1: mysql12: mysql-135e0 2: mysql-135e0Please select one you wish to use:use: 1 Please select one you wish to 1Binding Service [mysql1]: OK OK Binding Service [mysql1]: Uploading Application: Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (12K): OK
  • 66. Bindings exposed throughVCAP_SERVICES environment variable { "mysql-5.1": [{ "name": "mysql1", "label": "mysql-5.1", "plan": "free", "tags": ["mysql", "mysql-5.1", "relational"], "credentials": { "name": "da81b57c25cca4c65929a223f0ed068a0", "host": "172.99.99.99", "port": 3306, "username": "secretusername", "password": "secretuserpassword" .... } }] }
  • 67. Accessing bound services: low-levelvar services = JSON.parse(process.env.VCAP_SERVICES);var creds = services[mysql-5.1][0].credentialsconfigure do services = JSON.parse(ENV[VCAP_SERVICES]) mysql_key = services.keys.select { |svc| svc =~ /mysql/i }.first mysql = services[mysql_key].first[credentials] mysql_conf = {:host => mysql[hostname], :port => mysql[port], :username => mysql[user], :password => mysql[password]} @@client = Mysql2::Client.new mysql_confend
  • 68. Accessing bound services: high-level, Spring/JavaCloudEnvironment environment = new CloudEnvironment();RdbmsServiceInfo mysqlSvc = environment.getServiceInfo("mysqlService", RdbmsServiceInfo.class);RdbmsServiceCreator dataSourceCreator = new RdbmsServiceCreator();DataSource dataSource = dataSourceCreator.createService(mysqlSvc); <cloud:data-source id="dataSource" service-name="mysql1"> <cloud:pool pool-size="1-5"/> <cloud:connection properties="charset=utf-8"/> </cloud:data-source> ... reconfigured automatically <bean id="dataSource" class="…"> … DataSource for MySQL instance … </bean>
  • 69. Accessing bound services: high-level, Ruby reconfigured automaticallyRedisHost = "127.0.0.1"RedisPort = 10000$r = Redis.new(:host => RedisHost, :port => RedisPort) if !$r rewritten automatically production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000
  • 70. The human body as a system
  • 71. 50 to 70 billion of your cells die each day
  • 72. Yet you (the system) remain you
  • 73. Can we build software systems with these characteristics? http://dreamsongs.com/Files/ DesignBeyondHumanAbilitiesSimp.pdf http://dreamsongs.com/Files/ WhitherSoftware.pdf
  • 74. @crichardson crichardson@vmware.comhttp://plainoldobjects.com/presentations/ Questions?www.cloudfoundry.com @cloudfoundry