jdays 2015

64
12 Factor App Best Practices for JVM Deployment

Transcript of jdays 2015

Page 1: jdays 2015

12 Factor AppBest Practices for JVM Deployment

Page 2: jdays 2015

12 Factor AppBest Practices for JVM Deployment

Java doesn’t suck when you do things this way

Page 3: jdays 2015

XML sucks

Page 4: jdays 2015

10 page wikis to set up your app suck

Page 5: jdays 2015

Incongruent environments suck

DEV ≠ PROD

Page 6: jdays 2015

Apps that take more than 30 seconds to start up suck

Page 7: jdays 2015

Recompiling your entire codebase after fixing a typo sucks

Page 8: jdays 2015

Monolithic apps suck

Page 9: jdays 2015

The Java language sucks

Page 10: jdays 2015

But Java doesn’t suck

Page 11: jdays 2015

What does modern Javadevelopment look like?

Page 12: jdays 2015

Joe Kutner@codefinger

JVM Languages Owner@Heroku

Joe Kutner

Page 13: jdays 2015

12 Factor Appa methodology

ScalabilityMaintainability

Portability

Page 14: jdays 2015

12 Factor Appa methodology

ContinuousDelivery

Page 15: jdays 2015

12 Factor Appa methodology

Sleepingat

Night

Page 16: jdays 2015

Continuous Delivery

Slee

p

Page 17: jdays 2015

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 18: jdays 2015

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 19: jdays 2015

Graceful shutdown

Quick startup

Resilience to failure

| Disposability |

Page 20: jdays 2015

| Disposability |

Application Servers are not disposable

Page 21: jdays 2015

Application Servers are not disposable

| Disposability |

Page 22: jdays 2015

| Disposability |

Microservices are disposable

Page 23: jdays 2015

| Disposability |

Easy to replace

Decoupled from external infrastructure

Easy to modify

Page 24: jdays 2015
Page 25: jdays 2015

| Disposability |

Microservices

JavaGroovy

ScalaClojure

Scala Scala

Page 26: jdays 2015

Standalone ➤ Disposable

| Disposability |

Page 27: jdays 2015

Bootable ➤ Disposable

| Disposability |

Page 28: jdays 2015

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 29: jdays 2015

dev

sqlite

postgres

stage

mysql

postgres

prod

postgres

postgres

=

=

=

=

| Disposable | Parity |

Page 30: jdays 2015

dev

jetty

jetty

stage

tomcat

jetty

prod

jboss

jetty

=

=

=

=

| Disposable | Parity |

Page 31: jdays 2015

| Disposable | Parity |

dev

jetty

{}

stage

tomcat

{}

prod

jboss

{}

=

=

=

=

Page 32: jdays 2015

.war

Traditional JVM Deployment

Page 33: jdays 2015

.jar

Modern JVM Deployment

Page 34: jdays 2015

Reproducible ➤ Parity

| Disposable | Parity |

Page 35: jdays 2015

Reproducible ➤ Disposable

| Disposable | Parity |

Page 36: jdays 2015

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 37: jdays 2015

Configuration belongs in the environment, not in the application

Configuration should be strictly separated from code

| Disposable | Parity | Config |

Page 38: jdays 2015

Linux

Tomcat

WAR

server.xml

context.xml

web.xml

/etc/...

| Disposable | Parity | Config |

Page 39: jdays 2015

Environment

Java Application

PATH

DATABASE_URL

AWS_ACCESS_TOKEN

JAVA_OPTS

| Disposable | Parity | Config |

Page 40: jdays 2015

Containerless ➤ Separation

| Disposable | Parity | Config |

Page 41: jdays 2015

Containerless ➤ Parity

| Disposable | Parity | Config |

Page 42: jdays 2015

Containerless ➤ Disposable

| Disposable | Parity | Config |

Page 43: jdays 2015

Containerless ➤ 12 Factor App

| Disposable | Parity | Config |

Page 44: jdays 2015

Containerless Containerless Containerless

| Disposable | Parity | Config |

Page 45: jdays 2015

Dropwizard

Page 46: jdays 2015

@Configuration@EnableAutoConfiguration@ComponentScanpublic class Main { public static void main(String[] args) { SpringApplication.run(Main.class, args); }}

Page 47: jdays 2015

import org.eclipse.jetty.server.Server;import org.eclipse.jetty.servlet.*;

public class Main { public static void main(String[] args) throws Exception { Server server = new Server(); ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new App()), "/*"); server.start(); server.join(); }}

Page 48: jdays 2015

(defn -main [& [port]] (jetty/run-jetty (site #'app) {:port port :join? false}))

Page 49: jdays 2015

// Play example does not require any code

Page 50: jdays 2015

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 51: jdays 2015

| Disposable | Parity | Config | Concurrency |

Scale Up

Scale Out

Page 52: jdays 2015

| Disposable | Parity | Config | Concurrency |

web.1

web.2

worker.1 clock.1

Workload Diversity

Num

ber o

f Pro

cess

es

worker.2

worker.3

Page 53: jdays 2015

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 54: jdays 2015

| Disposable | Parity | Config | Concurrency | Admin |

Admin tasks should be run in isolated processes

Page 55: jdays 2015

web1

web2

web3

admin

| Disposable | Parity | Config | Concurrency | Admin |

Page 56: jdays 2015

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 57: jdays 2015

TODOList

Page 58: jdays 2015

Install the JDK

Three Steps to Setup Your App

Clone the SCM repo

Run the app

Page 59: jdays 2015

Get it under 30 seconds

Time your app’s startup

Get a stopwatch

Make Your App Startup Quick

Page 60: jdays 2015

Deploy or Scale Your App in One Step

Handle requests

Deploy the app

Provision a new environment

Page 61: jdays 2015

http://12factor.net

Page 62: jdays 2015

Java Doesn’t Suck

Page 63: jdays 2015

Java Doesn’t Suck(if you use it the right way)

Page 64: jdays 2015

Joe Kutner@codefinger

JVM Languages Owner@Heroku

http://www.slideshare.net/jkutner/jdays-2015