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.
Deploying Scaleable JVM Apps on 
Heroku 
Joe Kutner 
JVM Languages Owner at Heroku 
@codefinger
Java 
Scala 
Groovy 
Clojure 
JRuby
Traditional WAR file deployment… 
.war
Why WAR?
What does modern Java deployment 
look like?
Modern Java deployment is… 
Containerless
Modern containerless deployment…
Let’s see it in action…
java -jar myapp.jar
java -jar jetty-runner.jar /my/app/
$ heroku deploy:war myapp.war
The Twelve Factor App
The Twelve Factor App is… 
• a manifesto 
• a methodology 
• a collection of experiences
Its goals are… 
• scalability 
• maintainability 
• portability
Its does this through… 
declarative setup 
…explicit dependencies 
…external configuration 
! 
clean contracts 
…between y...
• Port binding 
• Concurrency 
• Disposability 
• Dev/prod parity 
• Logs 
• Admin processes 
Twelve Factors 
12factor.net...
I. Codebase 
One codebase, many deploys 
Test 
Staging 
Production
I. Codebase 
One codebase, many deploys 
Test 
Staging 
Production 
$ git push heroku-test master 
$ git push heroku-stg m...
II. Dependencies 
Explicitly declared
II. Dependencies 
Explicitly declared 
<dependency> 
<groupId>postgresql</groupId> 
<artifactId>postgresql</artifactId> 
<...
II. Dependencies 
Explicitly declared 
! 
libraryDependencies ++= Seq( 
"postgresql" % "postgresql" % "9.0-801.jdbc4" 
)
II. Dependencies 
Explicitly declared 
<dependency> 
<groupId>org.eclipse.jetty</groupId> 
<artifactId>jetty-servlet</arti...
II. Dependencies 
Explicitly declared 
libraryDependencies ++= Seq( 
"com.twitter" % "finagle-http" % "6.18.0", 
)
III. Configuration 
Store config in the environment, not the app
III. Configuration 
Store config in the environment, not the app 
! 
<dbUrl>jdbc://postgres...</dbUrl>
III. Configuration 
Store config in the environment, not the app 
URI dbUri = new URI(System.getenv(“DATABASE_URL"));!
III. Configuration 
Store config in the environment, not the app 
$ heroku config:set JAVA_OPTS=“-Xmx512m”
IV. Backing Services 
Treat backing services as attachable resources
IV. Backing Services 
Treat backing services as attachable resources
IV. Backing Services 
Treat backing services as attachable resources 
$ heroku addons:add papertrail
V. Build, release, run 
• A build step vendors dependencies, prepares assets, etc. 
• A release step creates a package fro...
V. Build, release, run 
$ mvn package
V. Build, release, run 
$ git push heroku master
V. Build, release, run 
$ sbt stage deployHeroku
VI. Processes 
Stateless
VI. Processes 
Stateless 
Don’t write to the local filesystem.
VII. Port binding 
• Export services via port binding 
• Self-contained, not relying on runtime injection by a web server ...
VIII. Concurrency 
• Scale out 
• Scale up
VIII. Concurrency 
• Scale out 
• Scale up 
$ heroku ps:scale web=3
VIII. Concurrency 
web.2 
web.1 
worker.3 
worker.1 clock.1 
Workload Diversity 
Number of Processes 
worker.2
IX. Disposability 
Fast startup and graceful shutdown 
• Spring Boot and Play do this for you… 
• as opposed to big App Se...
X. Dev/prod parity 
Keep dev, staging, prod and everything in between as similar as possible
X. Dev/prod parity 
Keep dev, staging, prod and everything in between as similar as possible 
dev! 
sqlite! 
postgres 
sta...
XI. Logs 
Treat logs as event streams
XI. Logs 
Treat logs as event streams 
DB Web Worker 
Event Stream 
2014-09-10T22:38:43.427311+00:00 heroku[worker]: ... 
...
XII. Admin Processes 
Admin and management tasks should be one-off processes
XII. Admin Processes 
Admin and management tasks should be one-off processes 
web1 
web2 
web3 
admin
• Port binding 
• Concurrency 
• Disposability 
• Dev/prod parity 
• Logs 
• Admin processes 
Twelve Factors 
• Codebase 
...
Further reading… 
! 
Heroku DevCenter: devcenter.heroku.com 
! 
Spring Boot Example: https://github.com/kissaten/spring-bo...
Thank You! 
Joe Kutner 
JVM Languages Owner at Heroku 
@codefinger
Creating Scalable JVM/Java Apps on Heroku
Upcoming SlideShare
Loading in …5
×

Creating Scalable JVM/Java Apps on Heroku

1,037 views

Published on

  • Be the first to comment

Creating Scalable JVM/Java Apps on Heroku

  1. 1. Deploying Scaleable JVM Apps on Heroku Joe Kutner JVM Languages Owner at Heroku @codefinger
  2. 2. Java Scala Groovy Clojure JRuby
  3. 3. Traditional WAR file deployment… .war
  4. 4. Why WAR?
  5. 5. What does modern Java deployment look like?
  6. 6. Modern Java deployment is… Containerless
  7. 7. Modern containerless deployment…
  8. 8. Let’s see it in action…
  9. 9. java -jar myapp.jar
  10. 10. java -jar jetty-runner.jar /my/app/
  11. 11. $ heroku deploy:war myapp.war
  12. 12. The Twelve Factor App
  13. 13. The Twelve Factor App is… • a manifesto • a methodology • a collection of experiences
  14. 14. Its goals are… • scalability • maintainability • portability
  15. 15. Its does this through… declarative setup …explicit dependencies …external configuration ! clean contracts …between your app and its platform …reduced coupling ! minimum divergence …between each deployment …between dev and prod environments
  16. 16. • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes Twelve Factors 12factor.net • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes
  17. 17. I. Codebase One codebase, many deploys Test Staging Production
  18. 18. I. Codebase One codebase, many deploys Test Staging Production $ git push heroku-test master $ git push heroku-stg master $ git push heroku-prod master
  19. 19. II. Dependencies Explicitly declared
  20. 20. II. Dependencies Explicitly declared <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> </dependency>
  21. 21. II. Dependencies Explicitly declared ! libraryDependencies ++= Seq( "postgresql" % "postgresql" % "9.0-801.jdbc4" )
  22. 22. II. Dependencies Explicitly declared <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlet</artifactId> </dependency>
  23. 23. II. Dependencies Explicitly declared libraryDependencies ++= Seq( "com.twitter" % "finagle-http" % "6.18.0", )
  24. 24. III. Configuration Store config in the environment, not the app
  25. 25. III. Configuration Store config in the environment, not the app ! <dbUrl>jdbc://postgres...</dbUrl>
  26. 26. III. Configuration Store config in the environment, not the app URI dbUri = new URI(System.getenv(“DATABASE_URL"));!
  27. 27. III. Configuration Store config in the environment, not the app $ heroku config:set JAVA_OPTS=“-Xmx512m”
  28. 28. IV. Backing Services Treat backing services as attachable resources
  29. 29. IV. Backing Services Treat backing services as attachable resources
  30. 30. IV. Backing Services Treat backing services as attachable resources $ heroku addons:add papertrail
  31. 31. V. Build, release, run • A build step vendors dependencies, prepares assets, etc. • A release step creates a package from build and config. • A runtime step executes, without special knowledge.
  32. 32. V. Build, release, run $ mvn package
  33. 33. V. Build, release, run $ git push heroku master
  34. 34. V. Build, release, run $ sbt stage deployHeroku
  35. 35. VI. Processes Stateless
  36. 36. VI. Processes Stateless Don’t write to the local filesystem.
  37. 37. VII. Port binding • Export services via port binding • Self-contained, not relying on runtime injection by a web server java -Dserver.port=$PORT -jar …
  38. 38. VIII. Concurrency • Scale out • Scale up
  39. 39. VIII. Concurrency • Scale out • Scale up $ heroku ps:scale web=3
  40. 40. VIII. Concurrency web.2 web.1 worker.3 worker.1 clock.1 Workload Diversity Number of Processes worker.2
  41. 41. IX. Disposability Fast startup and graceful shutdown • Spring Boot and Play do this for you… • as opposed to big App Servers that take several minutes to boot
  42. 42. X. Dev/prod parity Keep dev, staging, prod and everything in between as similar as possible
  43. 43. X. Dev/prod parity Keep dev, staging, prod and everything in between as similar as possible dev! sqlite! postgres stage! mysql! postgres prod! postgres! postgres =! ≠! = =! ≠! =
  44. 44. XI. Logs Treat logs as event streams
  45. 45. XI. Logs Treat logs as event streams DB Web Worker Event Stream 2014-09-10T22:38:43.427311+00:00 heroku[worker]: ... 2014-09-10T22:38:49.629790+00:00 heroku[web.1]: Starting process... 2014-09-10T22:39:22.056033+00:00 heroku[router]: at=info method=... 2014-09-10T22:38:43.427311+00:00 heroku[postgres]: ... 2014-09-10T22:38:43.427311+00:00 heroku[api]: Release v34 created... 2014-09-10T22:38:49.629790+00:00 heroku[web.1]: Starting process ... 2014-09-10T22:39:22.056033+00:00 heroku[router]: GET mysite.com/ ...
  46. 46. XII. Admin Processes Admin and management tasks should be one-off processes
  47. 47. XII. Admin Processes Admin and management tasks should be one-off processes web1 web2 web3 admin
  48. 48. • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes Twelve Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes
  49. 49. Further reading… ! Heroku DevCenter: devcenter.heroku.com ! Spring Boot Example: https://github.com/kissaten/spring-boot-executable ! Link to slideshare ! Twitter: @codefinger
  50. 50. Thank You! Joe Kutner JVM Languages Owner at Heroku @codefinger

×