Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cloud Best Practices


Published on

  • Be the first to comment

Cloud Best Practices

  1. 1. Cloud Best PracticesEric BOTTARDDeveloper Advocate@ebottard /
  2. 2. Eric Bottard Developer Advocate • VMware t@ebottard Äericbottard
  3. 3. Agenda10 DOs & DON’Ts in the CLOUD
  5. 5. Http Traffic Latency Matters
  6. 6. Where’s the Data Center?
  7. 7. LEARNLots of Literature
  8. 8. DIAGNOSEChrome Dev Tools YSlowGoogle PageSpeed
  9. 9. FIX ! Unique (e.g. hash) Paths Far Future Expires Header Minification CSS Sprites CDNSpring ResourceHandler Abstraction WRO4J / RoR Asset Pipeline
  10. 10. FileSystem Just pretend it’s not there
  11. 11. Is your File there? Is it Not?
  12. 12. IT IS THEREBut...
  13. 13. IT’S EPHEMERAL(disappears on restarts)
  14. 14. IT’S NOT SHARED Either
  15. 15. Use Some Persistent STORAGE• Mongo GridFS• Database Blob• External Blob Service
  16. 16. StateIt’s Better Not To Have It
  17. 17. Try to beSTATELESS• Horizontal Scaling• High Availability• Zero Downtime Deploy
  18. 18. The Usual Suspects6’6”6’0”5’6”5’0”4’6”4’0”
  19. 19. IF there is statePUSH TO CLIENT(e.g. Cookie, HTML5 apps)
  20. 20. IF there is state USE CENTRAL SERVICE (e.g. Redis)
  21. 21. IF there is state MAKE IT PER USER + Sticky Sessions
  22. 22. Databases They Have A Right To Evolve Too
  23. 23. vmc tunnel (caldecott)$ vmc tunnel1: foobar-mq2: foobar-pg3: postgresql-handson-cfWhich service instance?> 31: none2: psqlWhich client would you like to start?> 2Opening tunnel on port 10000...
  24. 24. HUMAN.EQUALS(ERROR)(when they simply don’t forget)
  25. 25. YOUR CODE IS VERSIONED* Why isn’t your DB? * It is, right?
  26. 26. DON’T ROLL YOUR OWN! (and beware of clusters)
  27. 27. Don’t Roll your Own! MIGRATIONS
  28. 28. Hotel California Better Stay Out of It
  29. 29. Main Risk: Lock In Welcome to the hotel california Such a lovely place Such a lovely face Plenty of room at the hotel california Any time of year, you can find it here Last thing I remember, I was Running for the door I had to find the passage back To the place I was before ’relax,’ said the night man, We are programmed to receive. You can checkout any time you like, But you can never leave! -the Eagles
  30. 30. Don’t Code to (any) Cloud!§ Auto-Reconfiguration§ For the Last 5% • Insulate your Code • Leverage Frameworks, e.g. Spring Profiles <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=""...> <bean id="mongoTemplate" class=""> <constructor-arg ref="mongoDbFactory" /> </bean> <beans profile="default"> <mongo:db-factory id="mongoDbFactory" dbname="test" host="" port="27017" username="foo" password="bar" /> </beans> <beans profile="cloud"> <cloud:mongo-db-factory id="mongoDbFactory" service-name="myBoundServiceName" /> </beans> </beans>
  31. 31. Beware of Data!
  32. 32. Segregation All Environments Were Created Equal
  33. 33. Dev vs. Test vs. Staging vs. Prod
  34. 34. Traditional Cloud Dev ≠ StagingMachines Identical ≠ Prod Manual,Process Automated inconsistent People Dev ≠ Ops Devops
  35. 35. One app, Many deploys of ONE set les deliverab Code Build Deployment Config ploys MANY de
  36. 36. “ Environment Variables [...] unlike custom config files, or other config mechanisms such as Java System Properties, are a language- and OS- agnostic standard The Twelve Factor App,
  37. 37. SOAThis time, it’s for real
  38. 38. Do your current apps look like this? Tomcat .war Browser Apache MySQL
  39. 39. “ SOA is like Adam Sandler’s career: Do one thing, and do it well. Rob Spectre, Developer Evangelism, Twilio
  40. 40. Another way to look at itcut -d" " -f1 < access.log | sort | uniq -c | sort -rn | less
  41. 41. Chances are they will soon look like this.. Tomcat search. warDesktopBrowser TomcatNative users. Node.js Message Bus war MongoMobile Front End e.g. RabbitMQ AppHTML5Mobile App Tomcat orders. war MySQL
  42. 42. Communication
  43. 43. SYNCH vs. ASYNCHe.g. HTTP vs. AMQP
  44. 44. FORMATXML, JSON, PBuffers, Thrift
  45. 45. LOW TECHDatabase + cron
  46. 46. When To Do It?
  47. 47. EARLY ONYAGNI?Slows Progress
  48. 48. NOWWould be a Good Time
  49. 49. LATER ONNow You Need ItHard To Refactor
  50. 50. Spring Integration§ Pipes & Filters Architecture§ Promotes Loose Coupling • Handles the Plumbing for you§ Declarative Model§ Internal & External Messaging
  51. 51. Deploy Do It Early & Do It Often
  52. 52. CONTINUOUS INTEGRATIONAutomatic builds, tests
  53. 53. CONTINUOUS DELIVERY CI + automatic deploy
  54. 54. IT’S OKIf it’s not PROD
  55. 55. Automate!<build> <plugins> <plugin> <groupId>org.cloudfoundry</groupId> <artifactId>maven-cf-plugin</artifactId> <version>1.0.0.M4-SNAPSHOT</version> <configuration> <server>mycloudfoundry-instance</server> <target></target> <appname>spring-integration-rocks</appname> <url></url> ⊕ <memory>1024</memory> <services> <service> <name>mysql-test</name> <vendor>mysql</vendor> </service> <service> <name>mongodb-test</name> <vendor>mongodb</vendor> </service> </services> </configuration> </plugin> </plugins></build>
  56. 56. Scale Your own Way
  57. 57. Every app isDIFFERENT• CPU• RAM• DISK• Bugs
  58. 58. Write your own logicUse system-level metrics$vmc stats myappinstance #0 cpu 0.0% of 2 cores memory 191.6M of 512M disk 15.0M of 2G as well as business-related info
  59. 59. Write your own logicUse Inter-process scaling$vmc scale myapp --instances 3 --memory 1G as well as intra-process (thread pools)
  60. 60. Upgrade With Zero Downtime
  61. 61. Blue/Green Deployment$vmc app awesome awesome: running platform: spring on java usage: 512M × 1 instance urls: services: postgresql-db Version N Version N Users LB / Proxy
  62. 62. Blue/Green Deployment$vmc push --name awesome_v2 --url Version N Version N Users LB / Proxy Version N+1 Version N+1
  63. 63. Blue/Green Deployment$vmc unmpap awesome$vmc map awesome_v2 Version N Version N Users LB / Proxy Version N+1 Version N+1
  64. 64. Variations1.Have some (privileged) population Canary use N+1 Release 2.then roll out
  65. 65. Variations1.Have some share of the population try A|B a different version Testing2.then decide
  66. 66. What about db changes?
  67. 67. BEFORECode @ Version NPersonidfirstnamelastnameaddress
  68. 68. TRANSITIONCode @ Version N & N+1Person Addressid idfirstname person_idlastname streetaddress zipcode city country
  69. 69. AFTER Code @ Version N+2Person Addressid idfirstname person_idlastname street zipcode city country
  70. 70. MIGRATIONS
  71. 71. Limit your Http Traffic There is no File System Strive for StatelessnessAutomate your DB Migrations Avoid Vendor Lock-in Treat all envs as IdenticalIt’s all about Loose Coupling Use Frequent Deployments Targeted and Custom ScalingUpgrade with Zero Downtime
  72. 72. Thank You Eric Bottard Developer Advocate • VMware t@ebottard Äericbottard