Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cloud Best Practices

Eric Bottard
February 04, 2013

Cloud Best Practices

10 Patterns and anti-patterns that become more and more important when going in the cloud. With examples in Java, Spring and Cloud Foundry.

Eric Bottard

February 04, 2013
Tweet

More Decks by Eric Bottard

Other Decks in Technology

Transcript

  1. FIX ! Unique (e.g. hash) Paths Far Future Expires Header

    Minification CSS Sprites CDN Spring ResourceHandler Abstraction WRO4J / RoR Asset Pipeline
  2. vmc tunnel (caldecott) $ vmc tunnel 1: foobar-mq 2: foobar-pg

    3: postgresql-handson-cf Which service instance?> 3 1: none 2: psql Which client would you like to start?> 2 Opening tunnel on port 10000...
  3. 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
  4. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"...> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongoDbFactory"

    /> </bean> <beans profile="default"> <mongo:db-factory id="mongoDbFactory" dbname="test" host="127.0.0.1" port="27017" username="foo" password="bar" /> </beans> <beans profile="cloud"> <cloud:mongo-db-factory id="mongoDbFactory" service-name="myBoundServiceName" /> </beans> </beans> Don’t Code to (any) Cloud! § Auto-Reconfiguration § For the Last 5% • Insulate your Code • Leverage Frameworks, e.g. Spring Profiles
  5. Traditional Cloud Machines Dev ≠ Staging ≠ Prod Identical Process

    Manual, inconsistent Automated People Dev ≠ Ops Devops
  6. “ The Twelve Factor App, http://www.12factor.net Environment Variables [...] unlike

    custom config files, or other config mechanisms such as Java System Properties, are a language- and OS- agnostic standard
  7. “SOA is like Adam Sandler’s career: Do one thing, and

    do it well. Rob Spectre, Developer Evangelism, Twilio
  8. Another way to look at it cut -d" " -f1

    < access.log | sort | uniq -c | sort -rn | less
  9. Chances are they will soon look like this.. MySQL Desktop

    Browser Tomcat users. war Tomcat search. war Tomcat orders. war Mongo Native Mobile App HTML5 Mobile App Node.js Front End Message Bus e.g. RabbitMQ
  10. Spring Integration § Pipes & Filters Architecture § Promotes Loose

    Coupling • Handles the Plumbing for you § Declarative Model § Internal & External Messaging
  11. 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>http://api.cloudfoundry.com</target>

    <appname>spring-integration-rocks</appname> <url>spring-int-rocks.cloudfoundry.com</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> ⊕
  12. Write your own logic Use system-level metrics as well as

    business-related info $vmc stats myapp instance #0 cpu 0.0% of 2 cores memory 191.6M of 512M disk 15.0M of 2G http://www.sxc.hu/photo/1128191
  13. Write your own logic Use Inter-process scaling $vmc scale myapp

    \ --instances 3 --memory 1G as well as intra-process (thread pools)
  14. Blue/Green Deployment $vmc app awesome awesome: running platform: spring on

    java usage: 512M × 1 instance urls: awesome.cloudfoundry.com services: postgresql-db Users LB / Proxy Version N Version N
  15. TRANSITION Code @ Version N & N+1 firstname id Person

    lastname address person_id id Address city zipcode street country
  16. Limit your Http Traffic There is no File System Strive

    for Statelessness Automate your DB Migrations Avoid Vendor Lock-in Treat all envs as Identical It’s all about Loose Coupling Use Frequent Deployments Targeted and Custom Scaling Upgrade with Zero Downtime