SlideShare a Scribd company logo
COPYRIGHT (C) 2020, ECLIPSE FOUNDATION, INC. | THIS WORK IS LICENSED UNDER A CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE (CC BY 4.0) 1
12 May 2020
Emily Jiang, Liberty Microservice Architect @IBM
Twitter: @emilyfhjiang
Building 12-factor Cloud Native
Microservices
Contents
Basic concept of 12 factor app
Live coding 12 factor microservices using MicroProfile
12 Factors in a nutshell
– A Methodologie
– Best Practices
– Manifesto
https://12factor.net/ by Heroku
Why 12 factor?
• Define the contract between applications and infrastructure
Application Infrastructure
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
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
How to build 12-Factor App?
MicroProfile and Kubernetes come to rescue!
Community
Driven
Lightweight, Iterative
Processes
Specs, APIs, TCKs
NO Reference
Implementation
MicroProfile Community
● Over a dozen vendors and
Java user groups
● Around 178 individual
contributors and growing
● Around a dozen
independent
implementations
 Open specifications
 Wide vendor support
 REST Client
 OpenAPI support
 Security
 Fault Tolerance
 Configuration
 Metrics
 Health
 Open Tracing
https://wiki.eclipse.org/MicroProfile/Implementation
Quarkus
12
MicroProfile 1.0 (Fall 2016)
JAX-RS 2.0
CDI 1.2
JSON-P 1.0
MicroProfile 1.1 (August 2017)
microProfile-1.0
Config 1.0
MicroProfile 1.2 (Sept 2017)
MicroProfile-1.1
Config 1.1
Fault Tolerance 1.0
Health 1.0
Metrics 1.0
JWT 1.0
2017
2018
MicroProfile 1.3 (Dec 2017)
MicroProfile 1.2
Config 1.2
Metrics 1.1
OpenApi 1.0
OpenTracing 1.0
RestClient 1.0
MicroProfile 1.4 (June 2018)
MicroProfile 1.3
Config 1.3
Fault Tolerance 1.1
JWT 1.1
Open Tracing-1.1
Rest Client-1.1
2019
MicroProfile 2.0.1 (July 2018)
MicroProfile 1.4
JAX-RS 2.1 // Java EE 8
CDI 2.0 // Java EE 8
JSON-P 1.1 // Java EE 8
JSON-B 1.0 // Java EE 8
MicroProfile 2.1 (Oct
2018)
MicroProfile 2.0
OpenTracing 1.2
MicroProfile 2.2 (Feb
2019)
Fault Tolerance 2.0
OpenAPI 1.1
OpenTracing 1.3
Rest Client 1.2
MicroProfile 3.0
(June 2019)
MicroProfile 2.1
Metrics 2.0
Health Check
2.0
Rest Client 1.3
MicroProfile 3.2 (Nov
2019)
MicroProfile 3.0
Metrics 2.2
Health Check 2.1
2020
MicroProfile 3.3 (Feb
2020)
MicroProfile 3.2
Config 1.4
Metrics 2.3
Fault Tolerance 2.1
Health 2.2
Rest Client 1.4
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)
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)
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
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;
IV. Backing services
“Treat backing services as attached resources”
Application
My SQL Amazon S3 Twitter
MicroProfile REST Client
BA
@Inject
@RestClient
private SystemClient
defaultRestClient;
@Dependent
@RegisterRestClient
@RegisterProvider(UnknownUrlExceptionMapper.class)
@Path("/properties")
public interface SystemClient {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Properties getProperties() throws
UnknownUrlException, ProcessingException;
}
io.openliberty.guides.inventory.client.SystemClient/mp-rest/url=http://localhost:9080/system
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)
VI. Processes
“Execute the app as one or more stateless processes”
Stateless and share-nothing
Restful API
From “CERN Data Centre Evolution”
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 MicroProfile Config to inject ports to microservices for chain-up invocations
port=80
@Inject @ConfigProperty(name=”port”, defaultValue=“9080”)
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 kNative
 Build microservices
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
MicroProfile Fault Tolerance
A solution to build a resilient microservice
 Retry - @Retry
 Circuit Breaker - @CircuitBreaker
 Bulkhead - @Bulkhead
 Time out - @Timeout
 Fallback - @Fallback
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
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
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
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
How to get started?
https://start.microprofile.io/
https://appsody.dev/
Demo
Service-a
Service-b
12 factor app
• Use MicroProfile and K8s to build a microservice => 12 factor app
microservice
Infrastructure
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
References
• https://microprofile.io
• https://openliberty.io
• https://quarkus.io
• https://www.12factor.net/
• https://kubernetes.io/
• https://start.microprofile.io/
• https://appsody.dev/
• https://github.com/Emily-Jiang/vsummit-12factor-app-a
• https://github.com/Emily-Jiang/vsummit-12factor-app-b
• https://github.com/Emily-Jiang/vsummit-12factor-deployment
microservice
Infrastructure
K8s
@emilyfhjiang
Thank you!
COPYRIGHT (C) 2020, ECLIPSE FOUNDATION, INC. | THIS WORK IS LICENSED UNDER A CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE (CC BY 4.0)
@emilyfhjiang

More Related Content

PDF
Contributors Guide to the Jakarta EE 10 Galaxy
PDF
Voxxed Athens 2018 - Java EE is dead Long live jakarta EE!
PDF
Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...
PDF
Microservices with Java, Spring Boot and Spring Cloud
PPTX
Springboot Microservices
PDF
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
PPTX
Getting Started with Java EE 7
PDF
How Class Data Sharing Can Speed up Your Jakarta EE Application Startup
Contributors Guide to the Jakarta EE 10 Galaxy
Voxxed Athens 2018 - Java EE is dead Long live jakarta EE!
Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...
Microservices with Java, Spring Boot and Spring Cloud
Springboot Microservices
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Getting Started with Java EE 7
How Class Data Sharing Can Speed up Your Jakarta EE Application Startup

What's hot (20)

PDF
Writing Java EE microservices using WildFly Swarm
PPTX
Liferay (DXP) 7 Tech Meetup for Developers
PDF
Refactor your Java EE application using Microservices and Containers - Arun G...
PPTX
WebLogic and GraalVM
PDF
Finally, easy integration testing with Testcontainers
PPTX
Ready! Steady! SpringBoot!
PPTX
Introduction to Spring Framework
PPT
Spring introduction
PDF
Spring Framework - Core
PDF
Microservices with WildFly Swarm - JavaSI 2016
PDF
Cloud Foundry Open Tour India 2012 , Keynote
PPTX
Java EE 8 Update
PDF
Should i break it?
PDF
Microservices Technology Stack
PDF
Spring Framework
PPTX
JSF 2.3: Integration with Front-End Frameworks
PPTX
Java spring ppt
PPTX
Java EE 8
PPTX
Building web applications with Java & Spring
PPTX
Connect JavaEE to the cloud with JCA by Steve Millidge
Writing Java EE microservices using WildFly Swarm
Liferay (DXP) 7 Tech Meetup for Developers
Refactor your Java EE application using Microservices and Containers - Arun G...
WebLogic and GraalVM
Finally, easy integration testing with Testcontainers
Ready! Steady! SpringBoot!
Introduction to Spring Framework
Spring introduction
Spring Framework - Core
Microservices with WildFly Swarm - JavaSI 2016
Cloud Foundry Open Tour India 2012 , Keynote
Java EE 8 Update
Should i break it?
Microservices Technology Stack
Spring Framework
JSF 2.3: Integration with Front-End Frameworks
Java spring ppt
Java EE 8
Building web applications with Java & Spring
Connect JavaEE to the cloud with JCA by Steve Millidge
Ad

Similar to Building 12-factor Cloud Native Microservices (20)

PDF
Live Coding 12 Factor App
PPTX
Build12 factorappusingmp
PDF
Master a Cloud Native Standard - MicroProfile.pdf
PDF
Master a Cloud Native Standard - MicroProfile.pdf
PPTX
Cloud nativemicroservices jax-london2020
PPTX
Cloud nativemicroservices jax-london2020
PPTX
Master a Cloud Native Standard - MicroProfile.pptx
PDF
SpringBoot and Spring Cloud Service for MSA
PPTX
TechEvent Eclipse Microprofile
PPTX
Microservices with kubernetes @190316
PPTX
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
PDF
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
PPTX
Cloud native programming model comparison
PDF
Spring boot microservice metrics monitoring
PDF
Spring Boot - Microservice Metrics Monitoring
PDF
Pivotal Cloud Foundry 2.3: A First Look
PDF
Spring and Pivotal Application Service - SpringOne Tour Dallas
PPTX
Cloud-Native Workshop New York- Pivotal
PDF
Stmik bandung
PDF
CI and CD with Spinnaker
Live Coding 12 Factor App
Build12 factorappusingmp
Master a Cloud Native Standard - MicroProfile.pdf
Master a Cloud Native Standard - MicroProfile.pdf
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices jax-london2020
Master a Cloud Native Standard - MicroProfile.pptx
SpringBoot and Spring Cloud Service for MSA
TechEvent Eclipse Microprofile
Microservices with kubernetes @190316
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Cloud native programming model comparison
Spring boot microservice metrics monitoring
Spring Boot - Microservice Metrics Monitoring
Pivotal Cloud Foundry 2.3: A First Look
Spring and Pivotal Application Service - SpringOne Tour Dallas
Cloud-Native Workshop New York- Pivotal
Stmik bandung
CI and CD with Spinnaker
Ad

More from Jakarta_EE (20)

PDF
Applied Domain-Driven Design Blueprints for Jakarta EE
PDF
Shorten All URLs
PPTX
The Eclipse Transformer Project
PPTX
Eclipse Transformer
PPTX
Eclipse GlassFish 6.0.0-M1
PPTX
Jakarta EE 9 Platform Project
PPTX
Jakarta EE 9 Milestone Release Party - Overview
PPTX
Jakarta EE 9 Platform Report
PDF
Cloud Native Java: Present and Future at Eclipse Foundation
PDF
JakartaOne Livestream CN4J: Driving Jakarta EE Success
PDF
JakartaOne Livestream CN4J: Cloud Native Runtimes - Revolution or Evolution?
PDF
JakartaOne Livestream CN4J: Bringing Reactive to Enterprise Developers
PPTX
JakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native Companion
PDF
Kubernetes Native Java and Eclipse MicroProfile | EclipseCon Europe 2019
PDF
Jakarta for dummEEs | JakartaOne Livestream
PDF
Jakarta EE Meets NoSQL at the Cloud Age | JakartaOne Livestream
PDF
Turbocharged Java with Quarkus | JakartaOne Livestream
PDF
Building Interoperable Microservices With Eclipse MicroProfile| JakartaOne Li...
PDF
Jakarta RESTful Web Services: Status Quo and Roadmap | JakartaOne Livestream
PDF
Cloud Native Java Community Day | EclipseCon Europe 2019
Applied Domain-Driven Design Blueprints for Jakarta EE
Shorten All URLs
The Eclipse Transformer Project
Eclipse Transformer
Eclipse GlassFish 6.0.0-M1
Jakarta EE 9 Platform Project
Jakarta EE 9 Milestone Release Party - Overview
Jakarta EE 9 Platform Report
Cloud Native Java: Present and Future at Eclipse Foundation
JakartaOne Livestream CN4J: Driving Jakarta EE Success
JakartaOne Livestream CN4J: Cloud Native Runtimes - Revolution or Evolution?
JakartaOne Livestream CN4J: Bringing Reactive to Enterprise Developers
JakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native Companion
Kubernetes Native Java and Eclipse MicroProfile | EclipseCon Europe 2019
Jakarta for dummEEs | JakartaOne Livestream
Jakarta EE Meets NoSQL at the Cloud Age | JakartaOne Livestream
Turbocharged Java with Quarkus | JakartaOne Livestream
Building Interoperable Microservices With Eclipse MicroProfile| JakartaOne Li...
Jakarta RESTful Web Services: Status Quo and Roadmap | JakartaOne Livestream
Cloud Native Java Community Day | EclipseCon Europe 2019

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
Teaching material agriculture food technology
PDF
Modernizing your data center with Dell and AMD
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
Teaching material agriculture food technology
Modernizing your data center with Dell and AMD
The AUB Centre for AI in Media Proposal.docx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Big Data Technologies - Introduction.pptx
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction

Building 12-factor Cloud Native Microservices

  • 1. COPYRIGHT (C) 2020, ECLIPSE FOUNDATION, INC. | THIS WORK IS LICENSED UNDER A CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE (CC BY 4.0) 1 12 May 2020 Emily Jiang, Liberty Microservice Architect @IBM Twitter: @emilyfhjiang Building 12-factor Cloud Native Microservices
  • 2. Contents Basic concept of 12 factor app Live coding 12 factor microservices using MicroProfile
  • 3. 12 Factors in a nutshell – A Methodologie – Best Practices – Manifesto https://12factor.net/ by Heroku
  • 4. Why 12 factor? • Define the contract between applications and infrastructure Application Infrastructure
  • 5. 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
  • 6. 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
  • 7. How to build 12-Factor App?
  • 8. MicroProfile and Kubernetes come to rescue!
  • 10. MicroProfile Community ● Over a dozen vendors and Java user groups ● Around 178 individual contributors and growing ● Around a dozen independent implementations
  • 11.  Open specifications  Wide vendor support  REST Client  OpenAPI support  Security  Fault Tolerance  Configuration  Metrics  Health  Open Tracing https://wiki.eclipse.org/MicroProfile/Implementation Quarkus
  • 12. 12 MicroProfile 1.0 (Fall 2016) JAX-RS 2.0 CDI 1.2 JSON-P 1.0 MicroProfile 1.1 (August 2017) microProfile-1.0 Config 1.0 MicroProfile 1.2 (Sept 2017) MicroProfile-1.1 Config 1.1 Fault Tolerance 1.0 Health 1.0 Metrics 1.0 JWT 1.0 2017 2018 MicroProfile 1.3 (Dec 2017) MicroProfile 1.2 Config 1.2 Metrics 1.1 OpenApi 1.0 OpenTracing 1.0 RestClient 1.0 MicroProfile 1.4 (June 2018) MicroProfile 1.3 Config 1.3 Fault Tolerance 1.1 JWT 1.1 Open Tracing-1.1 Rest Client-1.1 2019 MicroProfile 2.0.1 (July 2018) MicroProfile 1.4 JAX-RS 2.1 // Java EE 8 CDI 2.0 // Java EE 8 JSON-P 1.1 // Java EE 8 JSON-B 1.0 // Java EE 8 MicroProfile 2.1 (Oct 2018) MicroProfile 2.0 OpenTracing 1.2 MicroProfile 2.2 (Feb 2019) Fault Tolerance 2.0 OpenAPI 1.1 OpenTracing 1.3 Rest Client 1.2 MicroProfile 3.0 (June 2019) MicroProfile 2.1 Metrics 2.0 Health Check 2.0 Rest Client 1.3 MicroProfile 3.2 (Nov 2019) MicroProfile 3.0 Metrics 2.2 Health Check 2.1 2020 MicroProfile 3.3 (Feb 2020) MicroProfile 3.2 Config 1.4 Metrics 2.3 Fault Tolerance 2.1 Health 2.2 Rest Client 1.4
  • 13. 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)
  • 14. 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)
  • 15. 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
  • 16. 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;
  • 17. IV. Backing services “Treat backing services as attached resources” Application My SQL Amazon S3 Twitter
  • 18. MicroProfile REST Client BA @Inject @RestClient private SystemClient defaultRestClient; @Dependent @RegisterRestClient @RegisterProvider(UnknownUrlExceptionMapper.class) @Path("/properties") public interface SystemClient { @GET @Produces(MediaType.APPLICATION_JSON) public Properties getProperties() throws UnknownUrlException, ProcessingException; } io.openliberty.guides.inventory.client.SystemClient/mp-rest/url=http://localhost:9080/system
  • 19. 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)
  • 20. VI. Processes “Execute the app as one or more stateless processes” Stateless and share-nothing Restful API From “CERN Data Centre Evolution”
  • 21. 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 MicroProfile Config to inject ports to microservices for chain-up invocations port=80 @Inject @ConfigProperty(name=”port”, defaultValue=“9080”)
  • 22. 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 kNative  Build microservices
  • 23. 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
  • 24. MicroProfile Fault Tolerance A solution to build a resilient microservice  Retry - @Retry  Circuit Breaker - @CircuitBreaker  Bulkhead - @Bulkhead  Time out - @Timeout  Fallback - @Fallback
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. How to get started? https://start.microprofile.io/ https://appsody.dev/
  • 31. 12 factor app • Use MicroProfile and K8s to build a microservice => 12 factor app microservice Infrastructure
  • 32. 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
  • 33. References • https://microprofile.io • https://openliberty.io • https://quarkus.io • https://www.12factor.net/ • https://kubernetes.io/ • https://start.microprofile.io/ • https://appsody.dev/ • https://github.com/Emily-Jiang/vsummit-12factor-app-a • https://github.com/Emily-Jiang/vsummit-12factor-app-b • https://github.com/Emily-Jiang/vsummit-12factor-deployment microservice Infrastructure K8s @emilyfhjiang
  • 34. Thank you! COPYRIGHT (C) 2020, ECLIPSE FOUNDATION, INC. | THIS WORK IS LICENSED UNDER A CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE (CC BY 4.0) @emilyfhjiang