With microservices comes great benefits but also great challenges! One such challenge is data consistency and integrity. Traditionally, tightly coupled transactions were used to ensure strong consistency and isolation. However, this results in strong coupling between services due to data locking and decreasing concurrency, both of which are unsuitable for microservices. So, how do we provide consistency guarantees for flows that span long periods of time in cloud-native applications? We'll address this challenge by investigating the Saga pattern for distributed transactions, the MicroProfile Long Running Action (LRA) specification and how these can be used to develop effective cloud-native Java microservices.
4. The 12 Factor Application
โข VII. Port binding
โข Export services via port binding
โข VIII. Concurrency
โข Scale out via the process model
โข IX. Disposability
โข Maximize robustness with fast startup
and graceful shutdown
โข X. Dev/prod parity
โข Keep development, staging, and
production as similar as possible
โข XI. Logs
โข Treat logs as event streams
โข XII. Admin processes
โข Run admin/management tasks as one-
off processes
โข I. Codebase
โข One codebase tracked in revision
control, many deploys
โข II. Dependencies
โข Explicitly declare and isolate
dependencies
โข III. Config
โข Store config in the environment
โข IV. Backing services
โข Treat backing services as attached
resources
โข V. Build, release, run
โข Strictly separate build and run stages
โข VI. Processes
โข Execute the app as one or more
stateless processes
7. Cloud-native definition - VMWare
Cloud native is an approach to building
and running applications that exploits
the advantages of the cloud computing
delivery model.1
Cloud native development incorporates
the concepts of DevOps, continuous
delivery, microservices, and containers. 1
1 https://tanzu.vmware.com/cloud-native
8. Cloud-native definition - Microsoft
Cloud native is about speed and agility. 2
Cloud-native systems embrace microservices, ... 2
2 https://docs.microsoft.com/en-us/dotnet/architecture/cloud-native/definition
9. Cloud-native definition โ Red Hat
Cloud-native applications are a collection of
small, independent, and loosely coupled
services. 3
You donโt always have to start with
microservices to speed up application delivery
as part of cloud-native apps, though.3
3 https://www.redhat.com/en/topics/cloud-native-apps
10. Cloud-native definition โ CNCF
Cloud native technologies empower organizations to build and run
scalable applications in modern, dynamic environments such as public,
private, and hybrid clouds. Containers, service meshes, microservices,
immutable infrastructure, and declarative APIs exemplify this approach.
These techniques enable loosely coupled systems that are resilient,
manageable, and observable. Combined with robust automation, they
allow engineers to make high-impact changes frequently and
predictably with minimal toil. 4
4 https://github.com/cncf/toc/blob/master/DEFINITION.md
13. Stateless Computing
โข State of the data does not get
recorded between
transactions
A communication
protocol that does
not retain any
session information
โข Scaling the system is easier
โข Recoverability from system
failure is easier
Architecture,
design and
implementation is
complex
14. Stateful Computing
โข State of the data gets recorded
at every step across all
transactions
A communication
protocol that would
retain all session
information
โข Scaling the system is difficult
โข Recoverability from system
failure involves a lot of efforts
Architecture,
design and
implementation is
complex
17. What do we mean by โTransactionsโ?
A transaction is a group of read and write
operations that only succeeds if all the
operations within it are succesfull.
Transactions can impact a single record or
multiple records.
Holiday
Request
19. What does ACID stand for?
Atomic
Consistent
Isolated
Durable
A
C
I
D
All changes to the data must be performed or not at all
Data must be in a consistent state before and after the
transaction
No other process can change the data while the
transaction is running
The changes made by a transaction must persist
20. What are ACID Transactions?
โข A set of properties of data transactions
โข Designed to be used as a set of guiding principles
โข Intended to guarantee data validity
โข Supports data integrity and security
โข Utilises consensus protocol
โข E.g. 2 phase commit (2PC)
40. What is the SAGA Pattern?
โข Failure management pattern
โข Helps to establish consistency in distributed applications
โข Coordinates transactions between multiple
microservices to maintain data consistency
โข It is a sequence of local transactions where each
transaction updates data within a single service
41. ACID vs SAGA (BASE)
Atomicity
Consistency
Isolation
Durability
Basically Available
Soft State
Eventual Consistency
A
C
I
D
BA
S
E
62. SAGA Pattern โ Approach 1
Microservice 1 Microservice 2 Microservice 3
SAGA SAGA
SAGA
Each microservices that is part of the transaction publishes an event
that is processed by the next microservice
68. 68
What is MicroProfile?
โ Eclipse MicroProfile is an open-source community
specification for Enterprise Java microservices
โ A community of individuals, organizations, and
vendors collaborating within an open source
(Eclipse) project to bring microservices to the
Enterprise Java community microprofile.io
75. What is MicroProfile LRA?
โข Loosely-coupled transaction model
โข Designed for cloud-native microservices
โข Based on the Saga Pattern
โข Relaxes constraints of ACID transactions
โข Long-running orchestrated activity
76. Goals of MicroProfile LRA
โข Have no strong coupling between services
โข Simplify application error-handling when multiple services are
running as part of single logical transaction
โข Ensure the execution of application-provided compensating actions if
an activity is cancelled
โข Allow actions to finish early.
77. Open Liberty and LRA
Consists of two parts:
1. LRA participants
2. The LRA coordinator
*Beta driver needed
79. Single LRA Participant
โข @LRA
โข A join/create LRA method that handles any required business logic
โข @Complete
โข Used by complete methods, to be called after the LRA completes successfully and
handles any required business logic
โข @Compensate
โข Used by compensate methods, to be called if the LRA fails for any reason and
includes any logic that is required to revert any changes that were made by the
join/create method.
https://openliberty.io/blog/2021/01/27/microprofile-long-running-actions-beta.html
85. Summary:
โข Stateful microservices are still needed in this cloud-native world
โข Traditional transactions arenโt suitable for cloud-native
โข Alternatives like SAGA and MicroProfile LRA can help to provide
suitable cloud-native transactions for microservices
โข OSS tools and technologies are available to try out these alternatives
โข E.g. MicroProfile LRA
87. 87
Links and Materials
MicroProfile
โข MicroProfile Starter: https://start.microprofile.io/
โข What is MicroProfile?
https://developer.ibm.com/components/open-
liberty/series/what-is-microprofile/
โข MicroProfile Homepage:
https://projects.eclipse.org/proposals/eclipse-microprofile
Open Liberty
โข Open Liberty Site: https://openliberty.io/
โข Open Liberty Guides: https://openliberty.io/guides
โข Open Liberty Docs: https://openliberty.io/docs
All Open Source!
ยฉ 2021 IBM Corporation