33
Application Modernization Technical Conference 2019 Live Coding 12-Factor App Emily Jiang Java Champion STSM, IBM Liberty Microservice Architect, Advocate MicroProfile Architect @emilyfhjiang

Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

Application Modernization Technical Conference 2019

Live Coding 12-Factor App

Emily JiangJava ChampionSTSM, IBMLiberty Microservice Architect, AdvocateMicroProfile Architect@emilyfhjiang

Page 2: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

Contents

Basic concept of 12 factor app

On stage hacking of creating 12 factor microservices using MicroProfile

Page 3: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

12 Factors in a nut shell

– A Methodologie

– Best Practices

– Manifesto

https://12factor.net/ by Heroku

Page 4: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

Why 12 factor?

• Define the contract between applications and infrastructure

Application Infrastructure

Page 5: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

What is a Twelve-Factor App?

In the modern era, software is commonly delivered as a service: called web apps, or software-as-a-service. The twelve-factor app is a methodology for building software-as-a-service apps that:

Use declarative formats for setup automation, to minimize time and cost for new developers joining the project;

Have a clean contract with the underlying operating system, offering maximum portability between execution environments;

Are suitable for deployment on modern cloud platforms, obviating the need for servers and systems administration;

Minimize divergence between development and production, enabling continuous deployment for maximum agility;

And can scale up without significant changes to tooling, architecture, or development practices.

The twelve-factor methodology can be applied to apps written in any programming language, and which use any combination of backing services (database, queue, memory cache, etc).

From https://12factor.net

Page 6: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

THE FACTORS

1. Codebase

2. Dependencies

3. Config

4. Backing Services

5. Build, Release, Run

6. Processes

7. Port binding

8. Concurrency

9. Disposability

10.Dev / Prod parity

11.Logs

12.Admin Processes

Page 7: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

How to build 12-Factor App?

Page 8: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

MicroProfile and Kubernetes come to rescue!

Page 9: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

Community Driven

Lightweight, Iterative Processes

Specs, APIs, TCKsNO Reference Implementation

Page 10: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

MicroProfile Community

● Over a dozen vendors and Java user groups

● Around 169 individual contributors and growing

● Around a dozen independent implementations

Page 11: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

✓ Open specifications✓ Wide vendor support✓ REST Client✓ OpenAPI support✓ Security✓ Fault Tolerance✓ Configuration✓ Metrics✓ Health✓ Open Tracing

https://wiki.eclipse.org/MicroProfile/Implementation

Quarkus

Page 12: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

12

MicroProfile 1.0 (Fall 2016)JAX-RS 2.0CDI 1.2JSON-P 1.0

MicroProfile 1.1 (August 2017)microProfile-1.0Config 1.0

MicroProfile 1.2 (Sept 2017)MicroProfile-1.1Config 1.1Fault Tolerance 1.0Health 1.0Metrics 1.0JWT 1.0

2017

2018

MicroProfile 1.3 (Dec 2017)MicroProfile 1.2Config 1.2Metrics 1.1OpenApi 1.0OpenTracing 1.0RestClient 1.0

MicroProfile 1.4 (June 2018)MicroProfile 1.3Config 1.3Fault Tolerance 1.1JWT 1.1Open Tracing-1.1Rest Client-1.1

2019

MicroProfile 2.0.1 (July 2018)MicroProfile 1.4JAX-RS 2.1 // Java EE 8CDI 2.0 // Java EE 8JSON-P 1.1 // Java EE 8JSON-B 1.0 // Java EE 8

MicroProfile 2.1 (Oct 2018)

MicroProfile 2.0OpenTracing 1.2

MicroProfile 2.2 (Feb 2019)

Fault Tolerance 2.0OpenAPI 1.1OpenTracing 1.3Rest Client 1.2

MicroProfile 3.0 (June 2019)

MicroProfile 2.1

Metrics 2.0Health Check

2.0Rest Client 1.3

MicroProfile 3.2 (Nov 2019)

MicroProfile 3.0

Metrics 2.2Health Check 2.1

2020

MicroProfile 3.3 (Feb 2020)

MicroProfile 3.2Config 1.4Metrics 2.3Fault Tolerance 2.1Health 2.2Rest Client 1.4

Page 13: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

I. Codebase

• Dedicate smaller teams to individual applications or microservices.

• Following the discipline of single repository for an application forces the teams to analyze the seams of their application, and identify potential monoliths that should be split off into microservices.

“One codebase tracked in revision control, many deploys.”

ØUse a single source code repository for a single application (1:1 relation). Deployment stages are different tags/branchesØi.e. use a central git repo (external Github/GitHub Enterprise also suitable)

Page 14: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

II. Dependencies

A cloud-native application does not rely on the pre-existence of dependencies in a deployment target.

Developer Tools declare and isolate dependencies• Maven and Gradle for Java

“Explicitly declare and isolate dependencies”

ØEach microservice has its own dependencies declared (e.g. pom.xml)

Page 15: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

III. Config

“Store config in the environment”

Ø Changing config should not need to repackage your application

Ø Use Kubernetes configmaps and secrets for container services

Ø Use MicroProfile Config to inject the config properties into the microservices

App Password=blah

Page 16: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

MicroProfile Config

Why?– Configure Microservice without

repacking the application

How?– Specify the configuration in

configure sources

– Access configuration via

• Programmatically lookup

Config config =ConfigProvider.getConfig();

config.getValue(“myProp”, String.class);

• Via CDI Injection

@Inject @ConfigProperty(name="my.string.property") String myPropV;

Page 17: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

IV. Backing services

“Treat backing services as attached resources”

Application

My SQL Amazon S3 Twitter

Page 18: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

MicroProfile REST Client

BA

@Inject@RestClientprivate SystemClientdefaultRestClient;

@Dependent@RegisterRestClient@RegisterProvider(UnknownUrlExceptionMapper.class)@Path("/properties")public interface SystemClient {@GET@Produces(MediaType.APPLICATION_JSON)public Properties getProperties() throwsUnknownUrlException, ProcessingException;}

io.openliberty.guides.inventory.client.SystemClient/mp-rest/url=http://localhost:9080/system

Page 19: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

V. Build, release, run

“Strictly separate build and run stages”

Ø Source code is used in the build stage. Configuration data is added to define a release stage that can be deployed. Any changes in code or config will result in a new build/release

Ø Needs to be considered in CI pipeline (e.g. Tekton)

Page 20: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

VI. Processes

“Execute the app as one or more stateless processes”

Stateless and share-nothing

Restful API

Page 21: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

VII. Port binding

“Export services via port binding”

Ø Applications are fully self-contained and expose services only through ports. Port assignment is done by the execution environment

Ø Ingress/service definition of k8s manages mapping of ports

Ø Use MP Config to inject ports to microservices for chain-up invocations

Port=80

@Inject @ConfigProperty(name=”port”, defaultValue=“9080”)

Page 22: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

VIII. Concurrency

“Scale out via the process model”

Ø Applications use processes independent from each other to scale out (allowing for load balancing)

Ø To be considered in application design

Ø Cloud autoscaling services: [auto]scaling built into k8s

Ø Build micorservices

Page 23: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

IX. Disposability

“Maximize robustness with fast startup and graceful shutdown”

Ø Processes start up fast.

Ø Processes shut down gracefully when requested.

Ø Processes are robust against sudden deathØ Use MicroProfile Fault Tolerance to make it resilient

From “CERN Data Centre Evolution”

Page 24: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

MicroProfile Fault Tolerance

A solution to build a resilient microservice

v Retry - @Retry

v Circuit Breaker - @CircuitBreaker

v Bulkhead - @Bulkhead

v Time out - @Timeout

v Fallback - @Fallback

Page 25: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

X. Dev/prod parity

“Keep development, staging, and production as similar as possible”

Ø Development and production are as close as possible (in terms of code, people, and environments)

Ø Can use Operators to deploy in repeatable manner

Page 26: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

XI. Logs

“Treat logs as event streams”

Ø App writes all logs to stdout

Ø Use a structured output for meaningful logs suitable for analysis. Execution environment handles routing and analysis infrastructure

Page 27: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

XII. Admin processes

“Run admin/management tasks as one-off processes”

Ø Tooling: standard k8s tooling like “kubectl exec” or Kubernetes Jobs

Ø Also to be considered in solution/application design

Ø For example, if an application needs to migrate data into a database, place this task into a separate component instead of adding it to the main application code at startup

Page 28: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

THE FACTORS

1. Codebase

2. Dependencies

3. Config

4. Backing Services

5. Build, Release, Run

6. Processes

7. Port binding

8. Concurrency

9. Disposability

10.Dev / Prod parity

11.Logs

12.Admin Processes

Page 29: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

How to get started?

https://start.microprofile.io/https://appsody.dev/

Page 30: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

12 factor app

• Use MicroProfile and K8s to build a microservice => 12 factor app

microservice Infrastructure

Page 31: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

THE FACTORS

1. Codebase

2. Dependencies

3. Config

4. Backing Services

5. Build, Release, Run

6. Processes

7. Port binding

8. Concurrency

9. Disposability

10.Dev / Prod parity

11.Logs

12.Admin Processes

Page 32: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

References

• https://microprofile.io

• https://openliberty.io

• https://www.12factor.net/

• https://kubernetes.io/

• https://appsody.dev/

• https://github.com/Emily-Jiang/qcon-12factor-app-a

• https://github.com/Emily-Jiang/qcon-12factor-app-b

• https://github.com/Emily-Jiang/qcon-12factor-deployment

microserviceInfrastructure

K8s

@emilyfhjiang

Page 33: Application Modernization Technical Conference 2019 Live … · And canscale upwithout significant changes to tooling, architecture, or development practices. The twelve-factor methodology

Thank YouThank You

@emilyfhjiang