This document discusses stateful microservices in cloud native environments. It begins by introducing the authors Grace Jansen and Mary Grygleski. It then discusses the differences between stateless and stateful computing, and how data can exist in different states. The document explores how microservices operate on data and how statefulness was handled in older client-server systems versus modern cloud native environments. Finally, it discusses techniques like caching, databases, and tokens that can preserve state across boundaries, and provides examples using Kubernetes, Apache Pulsar, and reactive systems.
2. Who is Grace Jansen?
• Developer Advocate at IBM
• Java, Cloud-Native, Reactive,
MicroProfile, Open Source
• A Biologist turned software engineer
• Passionate about encouraging more WIT
• Love traveling and trying new activities
3. Who is Mary Grygleski?
• Senior Developer Advocate at DataStax
• Streaming, Event-Driven, NoSQL, Open Source
• Java Champion
• Over 25 years of software engineering experience that
span a wide spectrum from product development to
enterprise applications and beyond
• Previously a Senior Developer Advocate at IBM
• President of Chicago Java Users Group (CJUG)
• Active church volunteer and religious education
teacher
6. 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 simpler
8. 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
9. The States of Data
3 fundamental state of data:
● Data at rest
● Data in motion
● Data in use
10. The role of Microservices for the Data
● Microservices is a place where we “operate” on the data
● READ/WRITE: fetch from/place into the “data source”
● Data source: disk, in-memory, “cloud”
● Where I/O gets triggered to happen!
● Where transformation/remediation occur
12. Client-Server
Systems
Stateful database
systems on the
server side
Database-styled
transactions
2-Phase Commit
(2PC)
Java
Enterprise Java
Beans – Stateful EJB
(Session vs Entity
Beans)
Servlet –
HTTPSession
Client-side
caching of server
responses
Cookie-based
authentication
Token-based
authentication
(JWT)
15. Cloud Native Computing: An
overarching approach
► Essentially an “extension” to Cloud Computing by addressing the true
needs of enterprise-level distributed business application systems.
► What are the true needs? Netflix coined the term Cloud Native in the
early 2010’s and essentially they wanted to leverage on the cloud to
meet their goals for their systems to be:
► Highly available
► Scalable
► Performant
16.
17. The 12 Factor Application
A methodology that was drafted by developers at Heroku.
A set of guidelines or best practices for portable and resilient applications that
are well suited to be in cloud environments.
One of the factors indicates the need for self-contained services which are
to be deployed as stateless processes. Microservices architecture (so far) is
one that can satisfy such a requirement.
It does not enforce the tools and libraries that the applications must use, but it
provides the solid concepts that the applications must follow.
18. 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
19. HOW to preserve state
across session, transaction,
and network boundaries?
21. Leader Election
(etcd) StatefulSets PersistentVolume
Cookie/Session
affinity (sticky
session)
Cloud Native Infrastructure:
Containers/Kubernetes
This Photo by Unknown Author is licensed under CC BY This Photo by Unknown Author is licensed under CC BY-SA-NC This Photo by Unknown Author
is licensed under CC BY-SA
This Photo by Unknown Author is licensed under CC BY-SA-NC
22. Programming Design Pattern
Saga
Transactions spanning across multiple services
Concept of compensation – no ”rollbacks”
(forward strategy)
2 ways of coordination sagas:
•Choreography
•Orchestration
Long-Running Action / Saga
Interaction Pattern
“Compensator” model
Example Library implementing LRA:
•MicroProfile LRA (1.0 – May 13, 2021)
27. Open Liberty session persistence labs
Interactive Lab version:
https://openliberty.io/guides/#persistence
28. Apache Pulsar and Pulsar Functions
Free-Tier Astra Cloud: https://astra.datastax.com
● Separation of Compute and Data Storage (Apache
BookKeeper)
● Native from the start as a cloud-native provider
○ Multi-tenancy
○ Geo-replication
30. Resources (Code samples, Design Patterns, Open Source Libraries)
● Code samples:
○ Open Liberty session persistence using JCache & Hazelcast
https://openliberty.io/guides/sessions.html
○ A Stateful Open Liberty application in Kubernetes
https://github.com/mgrygles/stateful-kube-demo
Saga Design Pattern: https://microservices.io/patterns/data/saga.html
MicroProfile LRA 1.0:
https://download.eclipse.org/microprofile/microprofile-lra-1.0/microprofile-lra-spec-
1.0.html
LRA Blog: MicroProfile Long Running Actions in Open Liberty
● Open Liberty: https://openliberty.io/
○ Free tutorials/Guides: https://openliberty.io/guides
● MicroProfile: http://microprofile.io/
● Jakarta EE: https://jakarta.ee/
31. Resources (Cloud, Cloud-Native, DevOps)
● IBM Developer (all topics): https://developer.ibm.com
● IBM Developer (Cloud): https://developer.ibm.com/depmodels/cloud/
● IBM Developer (Cloud DevOps): https://www.ibm.com/cloud/devops
● IBM Developer (Cloud Native): https://www.ibm.com/cloud/cloud-native/
● IBM Developer (Saga Pattern):
https://developer.ibm.com/articles/use-saga-to-solve-distributed-transaction-management-pr
oblems-in-a-microservices-architecture/
● Programming with Java on IBM Cloud (IBM Cloud Docs):
https://cloud.ibm.com/docs/java?topic=cloud-native-overview
● Cloud Native Computing Foundation (CNCF): https://github.com/cncf/
● The 12 Factor App (Cloud Native Best Practices): https://12factor.net/
32. Resources (Apache Pulsar, Cassandra, AstraDB, Astra Streaming)
Astra Streaming:
https://www.datastax.com/products/astra-streaming
Luna Streaming:
https://www.datastax.com/products/luna-streaming
Astra Cloud (free-tier Managed Cassandra on the Cloud):
https://astra.datastax.com/
https://pulsar.apache.org/
https://bookkeeper.apache.org/
https://zookeeper.apache.org
33. Managed Cassandra on the IBM Cloud
https://www.ibm.com/cloud/databases-for-datastax
35. Join our community meetups & free trainings
IBM Expert TV: https://techtv.bemyapp.com/
IBM Developer on Meetup.com (includes all IBM Developer meetup groups in cities all over the world!)
https://www.meetup.com/pro/ibmdeveloper/
DataStax YouTube Channel: https://www.youtube.com/c/DataStax
Highly recommended also:
Chicago Java Users Group (CJUG) https://www.meetup.com/ChicagoJUG/
36. Follow Mary’s Twitch Stream
(Different topics: Java, Open Source, Distributed Messaging, Event-Streaming, Cloud, DevOps, etc)
Wednesday at 2pm-US/Central
https://twitch.tv/mgrygles
37. Join Pulsar at the ‘hood
https://www.meetup.com/pro/apache-pulsar-neighborhood
https://pulsar-neighborhood.github.io/
38. Join Mary on
Discord
https://discord.gg/RMU4Juw
Thank You!
@mgrygles
https://linkedin.com/in/mary-grygleski
https://github.com/mgrygles
https://dev.to/mgrygles
@gracejansen27
https://linkedin.com/in/grace-jansen
https://github.com/GraceJanse
https://developer.ibm.com/profiles/grace.jansen1/