Exploring Stateful Microservices
in the
Cloud Native World
Mary Grygleski & Grace Jansen
@mgrygles April 2022 @gracejansen27
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
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
Stateful
Vs
Stateless
“Computing” Life used
to be simpler
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
Realistically,
we live in a
Stateful
world
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
The States of Data
3 fundamental state of data:
● Data at rest
● Data in motion
● Data in use
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
Statefulness in the
“cloud-less” days…
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)
Stateful
Microservices
in Cloud Native
environments
Cloud Native:
Stateless
containers?
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
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.
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
HOW to preserve state
across session, transaction,
and network boundaries?
Techniques / Mechanisms
Cache
Database-style
transactions Cookies
Sessions Tokens
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
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)
An example of a SAGA (choreography)
What
about
Reactive?
Reactive Systems and the Reactive Manifesto
Resilient
Elastic
Message-Driven
Responsive
Code
samples
Open Liberty session persistence labs
Interactive Lab version:
https://openliberty.io/guides/#persistence
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
Resources
and Links
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/
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/
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
Managed Cassandra on the IBM Cloud
https://www.ibm.com/cloud/databases-for-datastax
Other Great Devnexus Sessions:
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/
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
Join Pulsar at the ‘hood
https://www.meetup.com/pro/apache-pulsar-neighborhood
https://pulsar-neighborhood.github.io/
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/

2022-Devnexus-StatefulMicroservices.pptx.pdf

  • 1.
    Exploring Stateful Microservices inthe Cloud Native World Mary Grygleski & Grace Jansen @mgrygles April 2022 @gracejansen27
  • 2.
    Who is GraceJansen? • 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 MaryGrygleski? • 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
  • 4.
  • 5.
  • 6.
    Stateless Computing • Stateof 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
  • 7.
    Realistically, we live ina Stateful world
  • 8.
    Stateful Computing • Stateof 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 ofData 3 fundamental state of data: ● Data at rest ● Data in motion ● Data in use
  • 10.
    The role ofMicroservices 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
  • 11.
  • 12.
    Client-Server Systems Stateful database systems onthe 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)
  • 13.
  • 14.
  • 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
  • 17.
    The 12 FactorApplication 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 FactorApplication • 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 preservestate across session, transaction, and network boundaries?
  • 20.
  • 21.
    Leader Election (etcd) StatefulSetsPersistentVolume 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 Transactionsspanning 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)
  • 23.
    An example ofa SAGA (choreography)
  • 24.
  • 25.
    Reactive Systems andthe Reactive Manifesto Resilient Elastic Message-Driven Responsive
  • 26.
  • 27.
    Open Liberty sessionpersistence labs Interactive Lab version: https://openliberty.io/guides/#persistence
  • 28.
    Apache Pulsar andPulsar 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
  • 29.
  • 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 onthe IBM Cloud https://www.ibm.com/cloud/databases-for-datastax
  • 34.
  • 35.
    Join our communitymeetups & 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 TwitchStream (Different topics: Java, Open Source, Distributed Messaging, Event-Streaming, Cloud, DevOps, etc) Wednesday at 2pm-US/Central https://twitch.tv/mgrygles
  • 37.
    Join Pulsar atthe ‘hood https://www.meetup.com/pro/apache-pulsar-neighborhood https://pulsar-neighborhood.github.io/
  • 38.
    Join Mary on Discord https://discord.gg/RMU4Juw ThankYou! @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/