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.

JavaOne 2015: 12 Factor App

2,493 views

Published on

Twelve Factor App

Published in: Internet
  • Hello there! Get Your Professional Job-Winning Resume Here! http://bit.ly/topresum
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

JavaOne 2015: 12 Factor App

  1. 1. 12 Factor App Best Practices for Java Deployment
  2. 2. You might not like what I have to say
  3. 3. Modern Java Deployment
  4. 4. .war Traditional Java Deployment
  5. 5. .jar Modern Java Deployment
  6. 6. Make JAR Not WAR
  7. 7. 2005 2015 WAR files JAR files App Servers Microservices Hot Deploy Continuous Deploy Server in a closet Heroku/AWS/etc
  8. 8. Joe Kutner @codefinger JVM Platform Owner
  9. 9. 12 Factor App a methodology Scalability Maintainability Portability
  10. 10. Immutable Ephemeral Declarative Automated
  11. 11. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  12. 12. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  13. 13. Use version control
  14. 14. BAD
  15. 15. BAD App #1 App #2
  16. 16. pom.xml <project> ... <modules> <module>my-app</module> <module>my-other-app</module> </modules> <project>
  17. 17. Submodules
  18. 18. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  19. 19. Never rely on implicit existence of system-wide packages Explicitly declare and isolate dependencies
  20. 20. Don’t check JAR files into Git
  21. 21. https://bintray.com/
  22. 22. Agent JARs
  23. 23. pom.xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-new-relic</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <includeGroupIds>com.newrelic.agent.java</includeGroupIds> <includeArtifactIds>newrelic-agent</includeArtifactIds> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin>
  24. 24. build.gradle task copyToLib(type: Copy) { into "$buildDir/server" from(configurations.compile) { include "jetty-runner*" } }
  25. 25. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  26. 26. • Resource handles to the database, memcached, and other backing services • Credentials to external services such as Amazon S3 or Twitter • Per-deploy values such as the canonical hostname for the deploy Anything that changes between deployment environments: (does not include things like conf/routes) Configuration is…
  27. 27. Configuration should be strictly separated from code
  28. 28. Don’t check passwords into Git
  29. 29. Configuration belongs in the environment, not in the application
  30. 30. applicationContext.xml <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id=“dataSource"> <property name="driverClassName" value="org.postgresql.Driver"/> <property name="url" value=“${JDBC_DATABASE_URL}"/> // ...
  31. 31. application.conf db.default.url=${DATABASE_URL}
  32. 32. Can you make your app open source at any moment, without compromising any credentials? Litmus Test
  33. 33. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  34. 34. application.conf db.default.url=${DATABASE_URL}
  35. 35. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  36. 36. build, release, run
  37. 37. $ mvn clean install $ sbt stage $ ./gradlew build build
  38. 38. $ heroku deploy:jar -j myapp.war $ mvn heroku:deploy $ docker push ... release
  39. 39. $ java -jar myapp.war $ build/install/myapp/bin/myapp.bat run $ mvn jetty:run $ service tomcat start $ cp myapp.war TOMCAT_HOME/webapps/
  40. 40. $ git push heroku master build, release, & run
  41. 41. DemoTime
  42. 42. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  43. 43. Processes should be stateless
  44. 44. sticky sessions 😞
  45. 45. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  46. 46. The twelve-factor app is completely self-contained The web app exports HTTP as a service by binding to a port
  47. 47. .war Traditional Deployment
  48. 48. .jar Modern Deployment
  49. 49. Dropwizard
  50. 50. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  51. 51. Relax bro, I got this… java.util.concurrent RxJava java.util.stream
  52. 52. Scale Up Scale Out
  53. 53. web.1 web.2 worker.1 clock.1 Workload Diversity NumberofProcesses worker.2 worker.3
  54. 54. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  55. 55. Graceful shutdown Quick startup Resilience to failure
  56. 56. Servers are not pets Servers are cattle
  57. 57. Application Servers are pets
  58. 58. Application Servers are not disposable
  59. 59. Microservices are cattle
  60. 60. Microservices are disposable
  61. 61. Easy to replace Decoupled from external infrastructure Easy to modify
  62. 62. Microservices
  63. 63. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  64. 64. dev stage prod= =
  65. 65. dev sqlite stage mysql prod postgres = ≠ = ≠
  66. 66. dev sqlite postgres stage mysql postgres prod postgres postgres = ≠ = = ≠ =
  67. 67. dev tomcat jetty stage tomcat jetty prod jboss jetty = ≠ = = ≠ = .jar
  68. 68. disposability reproducibility parity
  69. 69. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  70. 70. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  71. 71. Admin tasks should be run in isolated processes
  72. 72. $ heroku run bash Running `bash` attached to terminal... up, run.1594 ~ $
  73. 73. web1 web2 web3 admin
  74. 74. • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port Binding • Concurrency • Disposability • Dev/Prod Parity • Logs • Admin Processes 12 Factor App
  75. 75. http://12factor.net http://jkutner.github.io
  76. 76. Create a bintray.com account1. set JDBC_DATABASE_URL=jdbc:postgres://…2. Measure your app’s boot time3. Click a Heroku button4. What next?
  77. 77. https://github.com/britter/spring-boot-heroku-demo
  78. 78. Joe Kutner @codefinger JVM Platform Owner (http://www.slideshare.net/jkutner/javaone-2015-12-factor-app) http://bit.ly/1PSRxcm

×