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