SlideShare a Scribd company logo
1 of 74
Download to read offline
Cloud Best Practices
Eric BOTTARD
Developer Advocate
@ebottard / ebottard@vmware.com
Eric Bottard
  Developer Advocate • VMware


                t@ebottard
                Äericbottard
Agenda




10
         DOs &
         DON’Ts
          in the
         CLOUD
DISCLAIMER
Http Traffic
        Latency Matters
Where’s the Data Center?
LEARN
Lots of Literature
DIAGNOSE
Chrome Dev Tools
      YSlow
Google PageSpeed
FIX !
           Unique (e.g. hash) Paths
       Far Future Expires Header
                         Minification
                        CSS Sprites
                                CDN
Spring ResourceHandler Abstraction
       WRO4J / RoR Asset Pipeline
FileSystem
     Just pretend it’s not there
Is your File there? Is it Not?
IT IS THERE
But...
IT’S EPHEMERAL
(disappears on restarts)
IT’S NOT SHARED
           Either
Use Some Persistent


    STORAGE
• Mongo GridFS
• Database Blob
• External Blob Service
State
It’s Better Not To Have It
Try to be


STATELESS
• Horizontal Scaling
• High Availability
• Zero Downtime Deploy
The Usual Suspects

6’6”

6’0”

5’6”

5’0”

4’6”

4’0”
IF there is state




PUSH TO CLIENT
(e.g. Cookie, HTML5 apps)
IF there is state




         USE CENTRAL SERVICE
              (e.g. Redis)
IF there is state




                    MAKE IT PER USER
                      + Sticky Sessions
Databases
   They Have A Right To Evolve Too
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...
HUMAN.EQUALS(ERROR)
(when they simply don’t forget)
YOUR CODE IS VERSIONED*
    Why isn’t your DB?




                     * It is, right?
DON’T ROLL YOUR OWN!
  (and beware of clusters)
Don’t Roll your Own!




   MIGRATIONS
Hotel California
           Better Stay Out of It
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
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="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>
Beware of Data!
Segregation
    All Environments Were Created Equal
Dev vs. Test vs. Staging vs. Prod
Traditional      Cloud
         Dev ≠ Staging
Machines                   Identical
            ≠ Prod
             Manual,
Process                   Automated
           inconsistent

 People    Dev ≠ Ops       Devops
One app, Many deploys


                                   of
                        ONE set
                                  les
                        deliverab
      Code      Build



                                        Deployment



                Config

                                ploys
                        MANY de
“   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, http://www.12factor.net
SOA
This time, it’s for real
Do your current apps look like this?




                       Tomcat



                        .war
 Browser   Apache                      MySQL
“   SOA is like Adam Sandler’s career:
    Do one thing, and do it well.
           Rob Spectre, Developer Evangelism,
                                       Twilio
Another way to look at it
cut -d" " -f1 < access.log | sort | uniq -c | sort -rn | less
Chances are they will soon look like this..
                                      Tomcat



                                      search.
                                        war




Desktop
Browser


                                       Tomcat



Native                                 users.
           Node.js    Message Bus       war       Mongo
Mobile
          Front End   e.g. RabbitMQ
 App




HTML5
Mobile
 App
                                        Tomcat



                                        orders.
                                          war     MySQL
Communication
SYNCH vs. ASYNCH
e.g. HTTP vs. AMQP
FORMAT
XML, JSON, PBuffers, Thrift
LOW TECH
Database + cron
When To Do It?
EARLY ON
YAGNI?
Slows Progress
NOW
Would be a Good Time
LATER ON
Now You Need It
Hard To Refactor
Spring Integration
§ Pipes & Filters Architecture
§ Promotes Loose Coupling
 • Handles the Plumbing for you
§ Declarative Model
§ Internal & External Messaging
Deploy
  Do It Early & Do It Often
CONTINUOUS INTEGRATION
Automatic builds, tests
CONTINUOUS DELIVERY
  CI + automatic deploy
IT’S OK
If it’s not PROD
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>
Scale
  Your own Way
Every app is


DIFFERENT
• CPU
• RAM
• DISK
• Bugs
Write your own logic
Use   system-level metrics
$vmc stats myapp
instance   #0
  cpu         0.0%   of 2 cores
  memory      191.6M of 512M
  disk        15.0M of 2G




                                                 as well as

                                  business-related
                                                              info
                                           http://www.sxc.hu/photo/1128191
Write your own logic
Use   Inter-process scaling
$vmc scale myapp 
  --instances   3
  --memory      1G




                                       as well as

                              intra-process
                                   (thread pools)
Upgrade
   With Zero Downtime
Blue/Green Deployment
$vmc app awesome
  awesome: running
  platform: spring on java
  usage: 512M × 1 instance
  urls: awesome.cloudfoundry.com
  services: postgresql-db




                                   Version N   Version N




   Users     LB / Proxy
Blue/Green Deployment
$vmc push --name awesome_v2 
          --url awesome_secret.cloudfoundry.com




                                Version N          Version N




   Users     LB / Proxy


                                Version N+1       Version N+1
Blue/Green Deployment
$vmc unmpap awesome awesome.cloudfoundry.com
$vmc map awesome_v2 awesome.cloudfoundry.com




                                Version N       Version N




   Users     LB / Proxy


                                Version N+1    Version N+1
Variations

1.Have some

 (privileged) population             Canary
 use N+1                             Release



                           2.then   roll out
Variations

1.Have some share of

 the population try      A|B
 a different version   Testing

2.then   decide
What about db
 changes?
BEFORE
Code @ Version N
Person
id
firstname
lastname
address
TRANSITION
Code @ Version N & N+1
Person        Address
id            id
firstname      person_id
lastname      street
address       zipcode
              city
              country
AFTER
     Code @ Version N+2
Person          Address
id              id
firstname        person_id
lastname        street
                zipcode
                city
                country
MIGRATIONS
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
Thank You
  Eric Bottard
    Developer Advocate • VMware


                  t@ebottard
                  Äericbottard
          ebottard@vmware.com

More Related Content

What's hot

What's new in CQ 5.3? Top 10 features.
What's new in CQ 5.3? Top 10 features.What's new in CQ 5.3? Top 10 features.
What's new in CQ 5.3? Top 10 features.David Nuescheler
 
Webapp acceptance testing a case study
Webapp acceptance testing   a case studyWebapp acceptance testing   a case study
Webapp acceptance testing a case studyekantola
 
JSR-299 (CDI), Weld & the Future of Seam (JavaOne 2010)
JSR-299 (CDI), Weld & the Future of Seam (JavaOne 2010)JSR-299 (CDI), Weld & the Future of Seam (JavaOne 2010)
JSR-299 (CDI), Weld & the Future of Seam (JavaOne 2010)Dan Allen
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityDanHeidinga
 
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)Stefan Koopmanschap
 
The Power Of Refactoring (PHPCon Italia)
The Power Of Refactoring (PHPCon Italia)The Power Of Refactoring (PHPCon Italia)
The Power Of Refactoring (PHPCon Italia)Stefan Koopmanschap
 
CDI and Weld
CDI and WeldCDI and Weld
CDI and Weldjensaug
 
How We Build Features
How We Build FeaturesHow We Build Features
How We Build FeaturesAsh Maurya
 
Curso de JBPM5
Curso de JBPM5Curso de JBPM5
Curso de JBPM5Oscar V
 
Continuous Delivery Overview
Continuous Delivery OverviewContinuous Delivery Overview
Continuous Delivery OverviewWill Iverson
 
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVMJavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVMDanHeidinga
 
J9: Under the hood of the next open source JVM
J9: Under the hood of the next open source JVMJ9: Under the hood of the next open source JVM
J9: Under the hood of the next open source JVMDanHeidinga
 
Microsoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMicrosoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMark Ginnebaugh
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbSenthilKumar Selvaraj
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016Gavin Pickin
 
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...railsconf
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvmdeimos
 

What's hot (20)

What's new in CQ 5.3? Top 10 features.
What's new in CQ 5.3? Top 10 features.What's new in CQ 5.3? Top 10 features.
What's new in CQ 5.3? Top 10 features.
 
Webapp acceptance testing a case study
Webapp acceptance testing   a case studyWebapp acceptance testing   a case study
Webapp acceptance testing a case study
 
JSR-299 (CDI), Weld & the Future of Seam (JavaOne 2010)
JSR-299 (CDI), Weld & the Future of Seam (JavaOne 2010)JSR-299 (CDI), Weld & the Future of Seam (JavaOne 2010)
JSR-299 (CDI), Weld & the Future of Seam (JavaOne 2010)
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after Modularity
 
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)
 
The Power Of Refactoring (PHPCon Italia)
The Power Of Refactoring (PHPCon Italia)The Power Of Refactoring (PHPCon Italia)
The Power Of Refactoring (PHPCon Italia)
 
CDI and Weld
CDI and WeldCDI and Weld
CDI and Weld
 
Ash sxsw
Ash sxswAsh sxsw
Ash sxsw
 
How We Build Features
How We Build FeaturesHow We Build Features
How We Build Features
 
Curso de JBPM5
Curso de JBPM5Curso de JBPM5
Curso de JBPM5
 
Continuous Delivery Overview
Continuous Delivery OverviewContinuous Delivery Overview
Continuous Delivery Overview
 
Zehr dv club_12052006
Zehr dv club_12052006Zehr dv club_12052006
Zehr dv club_12052006
 
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVMJavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
 
J9: Under the hood of the next open source JVM
J9: Under the hood of the next open source JVMJ9: Under the hood of the next open source JVM
J9: Under the hood of the next open source JVM
 
03 - Continuous Integration
03 - Continuous Integration03 - Continuous Integration
03 - Continuous Integration
 
Microsoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMicrosoft SQL Server Testing Frameworks
Microsoft SQL Server Testing Frameworks
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
 
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
 

Similar to Cloud Best Practices

Devoxx France 2013 Cloud Best Practices
Devoxx France 2013 Cloud Best PracticesDevoxx France 2013 Cloud Best Practices
Devoxx France 2013 Cloud Best PracticesEric Bottard
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaAmazon Web Services
 
Gaming across multiple devices
Gaming across multiple devicesGaming across multiple devices
Gaming across multiple devicesPatric Boscolo
 
[RHFSeoul2017]6 Steps to Transform Enterprise Applications
[RHFSeoul2017]6 Steps to Transform Enterprise Applications[RHFSeoul2017]6 Steps to Transform Enterprise Applications
[RHFSeoul2017]6 Steps to Transform Enterprise ApplicationsDaniel Oh
 
Running your Java EE 6 applications in the Cloud (FISL 12)
Running your Java EE 6 applications in the Cloud (FISL 12)Running your Java EE 6 applications in the Cloud (FISL 12)
Running your Java EE 6 applications in the Cloud (FISL 12)Arun Gupta
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011bobmcwhirter
 
Running your Java EE 6 Apps in the Cloud - JavaOne India 2011
Running your Java EE 6 Apps in the Cloud - JavaOne India 2011Running your Java EE 6 Apps in the Cloud - JavaOne India 2011
Running your Java EE 6 Apps in the Cloud - JavaOne India 2011Arun Gupta
 
JavaOne India 2011 - Running your Java EE 6 Apps in the Cloud
JavaOne India 2011 - Running your Java EE 6 Apps in the CloudJavaOne India 2011 - Running your Java EE 6 Apps in the Cloud
JavaOne India 2011 - Running your Java EE 6 Apps in the CloudArun Gupta
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...Amazon Web Services
 
.NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time....NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time...Michele Leroux Bustamante
 
Threads Needles Stacks Heaps - Java edition
Threads Needles Stacks Heaps - Java editionThreads Needles Stacks Heaps - Java edition
Threads Needles Stacks Heaps - Java editionOvidiu Dimulescu
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
AWS Webcast - Build Agile Applications in AWS Cloud for Government
AWS Webcast - Build Agile Applications in AWS Cloud for GovernmentAWS Webcast - Build Agile Applications in AWS Cloud for Government
AWS Webcast - Build Agile Applications in AWS Cloud for GovernmentAmazon Web Services
 
JFokus 2011 - Running your Java EE 6 apps in the Cloud
JFokus 2011 - Running your Java EE 6 apps in the CloudJFokus 2011 - Running your Java EE 6 apps in the Cloud
JFokus 2011 - Running your Java EE 6 apps in the CloudArun Gupta
 
Continuous Deployment: The Dirty Details
Continuous Deployment: The Dirty DetailsContinuous Deployment: The Dirty Details
Continuous Deployment: The Dirty DetailsMike Brittain
 
Running your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudRunning your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudArun Gupta
 
BP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesAlfresco Software
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAkshaya Mahapatra
 

Similar to Cloud Best Practices (20)

Devoxx France 2013 Cloud Best Practices
Devoxx France 2013 Cloud Best PracticesDevoxx France 2013 Cloud Best Practices
Devoxx France 2013 Cloud Best Practices
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
 
Gaming across multiple devices
Gaming across multiple devicesGaming across multiple devices
Gaming across multiple devices
 
[RHFSeoul2017]6 Steps to Transform Enterprise Applications
[RHFSeoul2017]6 Steps to Transform Enterprise Applications[RHFSeoul2017]6 Steps to Transform Enterprise Applications
[RHFSeoul2017]6 Steps to Transform Enterprise Applications
 
Running your Java EE 6 applications in the Cloud (FISL 12)
Running your Java EE 6 applications in the Cloud (FISL 12)Running your Java EE 6 applications in the Cloud (FISL 12)
Running your Java EE 6 applications in the Cloud (FISL 12)
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
 
Running your Java EE 6 Apps in the Cloud - JavaOne India 2011
Running your Java EE 6 Apps in the Cloud - JavaOne India 2011Running your Java EE 6 Apps in the Cloud - JavaOne India 2011
Running your Java EE 6 Apps in the Cloud - JavaOne India 2011
 
JavaOne India 2011 - Running your Java EE 6 Apps in the Cloud
JavaOne India 2011 - Running your Java EE 6 Apps in the CloudJavaOne India 2011 - Running your Java EE 6 Apps in the Cloud
JavaOne India 2011 - Running your Java EE 6 Apps in the Cloud
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
 
.NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time....NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time...
 
Nodejs web,db,hosting
Nodejs web,db,hostingNodejs web,db,hosting
Nodejs web,db,hosting
 
Threads Needles Stacks Heaps - Java edition
Threads Needles Stacks Heaps - Java editionThreads Needles Stacks Heaps - Java edition
Threads Needles Stacks Heaps - Java edition
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
AWS Webcast - Build Agile Applications in AWS Cloud for Government
AWS Webcast - Build Agile Applications in AWS Cloud for GovernmentAWS Webcast - Build Agile Applications in AWS Cloud for Government
AWS Webcast - Build Agile Applications in AWS Cloud for Government
 
JFokus 2011 - Running your Java EE 6 apps in the Cloud
JFokus 2011 - Running your Java EE 6 apps in the CloudJFokus 2011 - Running your Java EE 6 apps in the Cloud
JFokus 2011 - Running your Java EE 6 apps in the Cloud
 
Continuous Deployment: The Dirty Details
Continuous Deployment: The Dirty DetailsContinuous Deployment: The Dirty Details
Continuous Deployment: The Dirty Details
 
Running your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudRunning your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the Cloud
 
BP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best Practices
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps Approach
 

Cloud Best Practices

  • 1. Cloud Best Practices Eric BOTTARD Developer Advocate @ebottard / ebottard@vmware.com
  • 2. Eric Bottard Developer Advocate • VMware t@ebottard Äericbottard
  • 3. Agenda 10 DOs & DON’Ts in the CLOUD
  • 5. Http Traffic Latency Matters
  • 8. DIAGNOSE Chrome Dev Tools YSlow Google PageSpeed
  • 9. FIX ! Unique (e.g. hash) Paths Far Future Expires Header Minification CSS Sprites CDN Spring ResourceHandler Abstraction WRO4J / RoR Asset Pipeline
  • 10. FileSystem Just pretend it’s not there
  • 11. Is your File there? Is it Not?
  • 15. Use Some Persistent STORAGE • Mongo GridFS • Database Blob • External Blob Service
  • 17. Try to be STATELESS • Horizontal Scaling • High Availability • Zero Downtime Deploy
  • 19. IF there is state PUSH TO CLIENT (e.g. Cookie, HTML5 apps)
  • 20. IF there is state USE CENTRAL SERVICE (e.g. Redis)
  • 21. IF there is state MAKE IT PER USER + Sticky Sessions
  • 22. Databases They Have A Right To Evolve Too
  • 23. 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...
  • 25. YOUR CODE IS VERSIONED* Why isn’t your DB? * It is, right?
  • 26. DON’T ROLL YOUR OWN! (and beware of clusters)
  • 27. Don’t Roll your Own! MIGRATIONS
  • 28. Hotel California Better Stay Out of It
  • 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. 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="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>
  • 32. Segregation All Environments Were Created Equal
  • 33. Dev vs. Test vs. Staging vs. Prod
  • 34. Traditional Cloud Dev ≠ Staging Machines Identical ≠ Prod Manual, Process Automated inconsistent People Dev ≠ Ops Devops
  • 35. One app, Many deploys of ONE set les deliverab Code Build Deployment Config ploys MANY de
  • 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, http://www.12factor.net
  • 38. Do your current apps look like this? Tomcat .war Browser Apache MySQL
  • 39.
  • 40. SOA is like Adam Sandler’s career: Do one thing, and do it well. Rob Spectre, Developer Evangelism, Twilio
  • 41. Another way to look at it cut -d" " -f1 < access.log | sort | uniq -c | sort -rn | less
  • 42. Chances are they will soon look like this.. Tomcat search. war Desktop Browser Tomcat Native users. Node.js Message Bus war Mongo Mobile Front End e.g. RabbitMQ App HTML5 Mobile App Tomcat orders. war MySQL
  • 44. SYNCH vs. ASYNCH e.g. HTTP vs. AMQP
  • 47. When To Do It?
  • 49. NOW Would be a Good Time
  • 50. LATER ON Now You Need It Hard To Refactor
  • 51. Spring Integration § Pipes & Filters Architecture § Promotes Loose Coupling • Handles the Plumbing for you § Declarative Model § Internal & External Messaging
  • 52. Deploy Do It Early & Do It Often
  • 53.
  • 55. CONTINUOUS DELIVERY CI + automatic deploy
  • 57. 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>
  • 58. Scale Your own Way
  • 59. Every app is DIFFERENT • CPU • RAM • DISK • Bugs
  • 60. Write your own logic Use system-level metrics $vmc stats myapp instance #0 cpu 0.0% of 2 cores memory 191.6M of 512M disk 15.0M of 2G as well as business-related info http://www.sxc.hu/photo/1128191
  • 61. Write your own logic Use Inter-process scaling $vmc scale myapp --instances 3 --memory 1G as well as intra-process (thread pools)
  • 62. Upgrade With Zero Downtime
  • 63. Blue/Green Deployment $vmc app awesome awesome: running platform: spring on java usage: 512M × 1 instance urls: awesome.cloudfoundry.com services: postgresql-db Version N Version N Users LB / Proxy
  • 64. Blue/Green Deployment $vmc push --name awesome_v2 --url awesome_secret.cloudfoundry.com Version N Version N Users LB / Proxy Version N+1 Version N+1
  • 65. Blue/Green Deployment $vmc unmpap awesome awesome.cloudfoundry.com $vmc map awesome_v2 awesome.cloudfoundry.com Version N Version N Users LB / Proxy Version N+1 Version N+1
  • 66. Variations 1.Have some (privileged) population Canary use N+1 Release 2.then roll out
  • 67. Variations 1.Have some share of the population try A|B a different version Testing 2.then decide
  • 68. What about db changes?
  • 69. BEFORE Code @ Version N Person id firstname lastname address
  • 70. TRANSITION Code @ Version N & N+1 Person Address id id firstname person_id lastname street address zipcode city country
  • 71. AFTER Code @ Version N+2 Person Address id id firstname person_id lastname street zipcode city country
  • 73. 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
  • 74. Thank You Eric Bottard Developer Advocate • VMware t@ebottard Äericbottard ebottard@vmware.com