Cassandra+Quarkus = Microservices
Nirvana!
1
➢ Developer/Architect
➢ Mechanical Engineer (so many moons
ago)
➢ Distributed systems
➢ Love to teach and communicate
➢ Inner loop == developer productivity
Developer Advocate @rags
@ragsns
Raghavan “Rags” Srinivas
@ragss
3
Intro.
01
Agenda
NoSQL
02
Cassandra/Astra/
k8ssandra
03
Microservices =
Quarkus+Cassandra
05
Live Coding
06
Resources
07
Quarkus
04
Today’s challenge: Todo App
Menti.com for surveys and quizzes
menti.com ⇒ enter code
Don't answer in YT chat
Look at phone (not at YT)
Keep it open for later
6
Intro
01
Agenda
NoSQL
02
Cassandra/Astra/
k8ssandra
03
Microservices = Quarkus
+ Cassandra
05
Live Coding
06
Resources
07
Quarkus
04
Origin of the term “NoSQL”
7
● Meetup name on June 11, 2009 in San Francisco
○ Catchy hashtag intended to refer to databases like BigTable and DynamoDB
○ Meetup presentations: Cassandra, MongoDB, CouchDB, HBase, Voldemort,
Dynomite, and Hypertable
● Sometimes referred to “Not only SQL”
Relational vs. NoSQL
8
● Relational
○ Standard relational data model
and language SQL
○ ACID transactions
○ Integration database
○ Designed for a single machine
○ Hard to scale
○ Impedance mismatch
● NoSQL
○ Variety of data models and
languages
○ Lower-guarantee transactions
○ Application database
○ Designed for a cluster
○ Easy to scale
○ Better database-app compatibility
The CAP Theorem
9
Availability
Consistency
AP
CA
Partition tolerance
CP
Always responds,
may not always return
the most recent write
pick two
Every read receives
the most recent write
or an error
Operates in the
presence of network
partition failures
The CAP Theorem
10
Availability
Consistency
AP
CA
Partition tolerance
CP
pick two
DataStax Graph
11
Intro
01
Agenda
NoSQL
02
Cassandra/Astra/
k8ssandra
03
Microservices (Quarkus +
Cassandra)
05
Live Coding
06
Resources
07
Quarkus
04
Master-less (Peer-to-Peer) Architecture
NODE
NODE
NODE
NODE
NODE NODE
NODE
1. NO Single Point of Failure
2. Scales for writes and reads
3. Application can contact any node
(in case of failure - just contact next one)
Why partitioning?
Because scaling doesn’t have to be [s]hard!
Big Data doesn’t fit to a single server, splitting it into
chunks we can easily spread them over dozens, hundreds
or even thousands of servers, adding more if needed.
Is Cassandra AP or CP?
Cassandra is configurably consistent. In any moment of the
time, for any particular query you can set the Consistency Level
you require to have. It defines how many CONFIRMATIONS
you’ll wait before the response is dispatched;
14
PreparedStatement pstmt = session.prepare(
"INSERT INTO product (sku, description) VALUES (?,
?)"
);
pstmt.setConsistencyLevel(ConsistencyLevel.ONE);
cqlsh> CONSISTENCY
Current consistency level is QUORUM.
cqlsh> CONSISTENCY ALL
Consistency level set to ALL.
Cassandra Biggest Users (and Developers)
dtsx.io/cassandra-at-netflix
And many others...
Hybrid-Cloud and Multi-Cloud
On-premise
Data is globally distributed
Geographical Distribution
State-of-the-art NoSQL Database
17
● DBaaS, serverless, auto-scalable
● Multi-cloud, distributed, multi-node cluster
● NoSQL, multi-model
● Tabular, document, key-value
● Based on open-source Apache
c
OSS Apache Cassandra
A tabular NoSQL database
OSS Stargate.io
A data gateway to allow
multiple usages
$25/month credit
Launch a database in the cloud with a few clicks, no credit card required.
Z
Swagger UI
GraphQL
Playground
Tools
User Interface
Web-based developer
tools and apps
CQL JSON GraphQL REST GRPC
Apps
CQL
Console
+ =
19
K8ssandra Components in Context 20
Kubernetes Cluster
Data Gateway
NoSQL DB
Web / Mobile Apps
Users
Ingress
Microservices Operators
Reaper
Medusa
Object Storage
Repair
Backup /
Restore
Deployment
Metrics UI
Metrics DB
21
Intro.
01
Agenda
NoSQL
02
Cassandra/Astra/
k8ssandra
03
Microservices = Quarkus
+ Cassandra
05
Live Coding
06
Resources
07
Quarkus
04
A cohesive platform for optimized Microservices
joy
● Based on standards
● Unified configuration
● Live coding
● Streamlined code for the 80% common usages
○ Flexible for the 20% uncommon
● No hassle native executable generation
Inner loop == Developer Productivity
“Our developers used to wait 2 to 3 mins to see their changes. Live coding does away
with this!”
22
IT’S
STILL
JAVA!
@
@
</>
Packaging
(maven,
gradle…)
Build Time
Runtime
Load config file
from file system
Parse it
Classpath scanning
to find
annotated classes
Attempt to load
class to
enable/disable
features
Build its
model of
the world
Start the
management
(thread,
pool…)
How does a Typical Java Framework Work?
@
@
</>
@
@
</>
Build Time
Runtime
Runtime
Build Time
The Quarkus Way
26
Intro
01
Agenda
NoSQL
02
Cassandra/Astra
k8ssandra
03
Microservices = Quarkus
+ Cassandra
05
Live Coding
06
Resources
07
Quarkus
04
Microservices Architecture evolution
Monolith 90s
User Interface
Services
Data
Multi Tiers 2000 SOA (2005) Microservices (2015)
Front End
Backend
Data Layer
UI UI
ESB
Service
RDMS
SPA
Backend for frontend
Native Web Component
API
gateway
Service
Registry
Service
Mesh
Service
Service
Service
Service
NoSQL
Object
BigData
NoSQL
NoSQL
Microfrontend
Service
MicroServices
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service Service
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
Data Mesh
28
Microservices Principles
✔ Organized around Business Capabilities
✔ Products not Projects
✔ Smart endpoints and dumb pipes
✔ Decentralized Governance
✔ Decentralized Data Management
✔ Infrastructure Automation
✔ Design for failure
✔ Evolutionary Design
Martin Fowler
Microservices
+
• Reduce Cost (Scaling, Design)
• Reduce Risk (resilience)
• Increase Release Speed
• Enable Visibility (security, monitoring)
• Complexity (Security, Transaction, Orchestration)
• Cultural Changes
• Bigger RUN footprint
ADVANTAGES
DISADVANTAGES
-
Rest vs gRPC vs GraphQL ?
● Decoupling Client / Server (Schema on read)
● API Lifecycle (Versioning)
● Tooling (API Management, Serverless)
● Verbose payloads (json, xml)
● No discoverability
● Not suitable for command-like (functions) API
● CRUD superstar
● Relevant for mutations (OLTP)
● Public and web APIs
● Limited Business Scope
+
-
Rest vs gRPC vs GraphQL ?
● High Performances (http/2 – binary serialization)
● Multiple stubs : Sync, Async, Streaming
● Multi languages - Interoperability
● Strongly coupled (schema with proto files)
● No discoverability
● Protobuf serialization format
● Distributed network of services (no waits)
● High throughput & streaming use cases
● Command-like (eg: slack)
+
-
Rest vs gRPC vs GraphQL ?
● Discoverability, documentation
● Custom payloads
● Match standards (JSON | HTTP)
● Single endpoint (versioning, monitoring, security)
● Complex implementation (tooling, still young)
● Nice for customers nasty for DB (N+1 select)
● Backend for frontend (JS)
● Service aggregation | composition (joins)
● When volume matters (mobile phones)
+
-
GraphQL
Quarkus Cassandra Extension
34
● Native Quarkus Config
● Cassandra Driver Session Support
● Cassandra Driver Object Mapper Support
● Support for Mutiny Types (Reactive Types)
● Native Image Support
● Support for DataStax Astra (Cassandra DBaaS)
Native Quarkus Config
35
quarkus.cassandra.cloud.secure-connect-bundle=/path/to/astra/bundle.zip
quarkus.cassandra.keyspace=ks1
quarkus.cassandra.auth.username=alice
quarkus.cassandra.auth.password=s3cr3t
quarkus.cassandra.request.timeout=5 seconds
quarkus.cassandra.request.consistency-level=LOCAL_ONE
quarkus.cassandra.request.page-size=1000
quarkus.cassandra.metrics.enabled=true
quarkus.cassandra.health.enabled=true
Cassandra Driver Session Support
36
@Inject QuarkusCqlSession session;
Cassandra Driver Object Mapper Support
37
@Dao interface ProductDao {
@Insert Uni<Void> create(Product product);
@Select Uni<Product> findById(String id);
@Select Multi<Product> findAll();
}
class ProductDaoProducer {
@Produces @ApplicationScoped
public ProductDao produceProductDao() { ... }
}
@ApplicationScoped class ProductService {
@Inject ProductDao dao;
}
Support for Mutiny Types
38
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path(“/product/{id}”)
public Uni<Response> findProduct(@PathParam(“id”) String id) {
return dao.findById(id)
.map(todo -> Response.ok(todo).build())
.ifNoItem().after(Duration.ofSeconds(5))
.recoverWithItem(Response.status(Status.NOT_FOUND).build());
}
39
Intro
01
Agenda
NoSQL
02
Cassandra/Astra/
k8ssandra
03
Microservices = Quarkus
+ Cassandra
05
Live Coding
06
Resources
07
Quarkus
04
Specification of Service layer
Create a new Task
Mark a task as completed
Delete a task
List all tasks
Data Model
CREATE TABLE todos.todoitems (
user_id text,
item_id timeuuid,
completed boolean,
title text,
offset int,
PRIMARY KEY ((user_id),item_id)
);
user_id
item_id
completed
title
offset
todoitems
TEXT
TIMEUUID
BOOLEAN
TEXT
INT
K
C↑
Rational
● Our Partition key is user_id
○ We chose to have one todo list per user (avoiding any select * from table)
● Service
○ findTodos() for user
○ createTodo() for user
○ deleteTodo() from its id (userid + itemid)
○ updateTodo() from its id (both to mark it as complete and update title)
● REST API
○ The userid will appear in the URL
○ Provide major version (best practice)
/api/v1/{user_id}/todos
TodoMVC.com
http://todomvc.com/examples/angularjs/
Todo Backend.com
Rest API Specifications (specs)
Architecture
FrontEnd
Presentation Tier
TODOBACKEND
Backend
Application Tier
Databases
Data Tier
Database
DRIVER
/client/index.html
/specs/index.html
REST API
47
Intro
01
Agenda
NoSQL
02
Cassandra/Astra/
k8ssandra
03
Microservices = Quarkus
+ Cassandra
05
Live Coding
06
Resources
07
Quarkus
04
48
Livestream: youtube.com/DataStaxDevs
YouTube
Twitch
Games menti.com
Discord
YouTube
Questions: https://dtsx.io/discord
L
i
v
e
a
n
d
i
n
t
e
r
a
c
t
i
v
e
Attend the live sessions
49
AstraDB astra.datastax.com Gitpod IDE: https://gitpod.io Katacoda katacoda.com/datastax
Complete Workshops Labs
2
c
Database + GraphQL + PlayGround
c
c
c
Become a Jedi Master of Astra 50
datastax.com/workshops
JOIN OUR ASTRA DB
BUILD-A-THON HACK!
📍 3 months, 3 rounds of challenges. 📍
Join 1 month, 2 months or all 3
Each month, we’ll reveal a fresh new set of
challenges you can partake in.
All you have to do is have Astra DB as your
backend.
USD$41,000 worth of prizes
➡REGISTER -
buildathonhack.com
Try Cassandra+Quarkus
52
● Create your quarkus + cassandra app (code.quarkus.io or running the following):
$ mvn io.quarkus:quarkus-maven-plugin:1.12.1.Final:create 
-DprojectGroupId=io.quarkus.astra 
-DprojectArtifactId=quarkus-astra-demo 
-DprojectVersion=1.0.0 
-DclassName="io.quarkus.astra" 
-Dextensions="resteasy-reactive, resteasy-reactive-jackson, micrometer-registry-prometheus, smallrye-openapi,
smallrye-health, cassandra-quarkus-client"
$ cd quarkus-astra-demo
$ ./mvnw clean quarkus:dev
● Stand up your Astra free database (astra.datastax.com)
● Check out https://k8ssandra.io
quarkus.cassandra.cloud.secure-connect-bundle=<path>/secure-connect-bundle.zip
quarkus.cassandra.auth.username=<user>
quarkus.cassandra.auth.password=<pw>
● Get coding + see docs for more info and try the Quarkus + Cassandra workshop
https://quarkus.io/guides/cassandra
https://github.com/datastaxdevs/workshop-intro-quarkus-cassandra/
Thank You!
Try Astra + Quarkus!

A Microservices approach with Cassandra and Quarkus | DevNation Tech Talk

  • 1.
  • 2.
    ➢ Developer/Architect ➢ MechanicalEngineer (so many moons ago) ➢ Distributed systems ➢ Love to teach and communicate ➢ Inner loop == developer productivity Developer Advocate @rags @ragsns Raghavan “Rags” Srinivas @ragss
  • 3.
  • 4.
  • 5.
    Menti.com for surveysand quizzes menti.com ⇒ enter code Don't answer in YT chat Look at phone (not at YT) Keep it open for later
  • 6.
  • 7.
    Origin of theterm “NoSQL” 7 ● Meetup name on June 11, 2009 in San Francisco ○ Catchy hashtag intended to refer to databases like BigTable and DynamoDB ○ Meetup presentations: Cassandra, MongoDB, CouchDB, HBase, Voldemort, Dynomite, and Hypertable ● Sometimes referred to “Not only SQL”
  • 8.
    Relational vs. NoSQL 8 ●Relational ○ Standard relational data model and language SQL ○ ACID transactions ○ Integration database ○ Designed for a single machine ○ Hard to scale ○ Impedance mismatch ● NoSQL ○ Variety of data models and languages ○ Lower-guarantee transactions ○ Application database ○ Designed for a cluster ○ Easy to scale ○ Better database-app compatibility
  • 9.
    The CAP Theorem 9 Availability Consistency AP CA Partitiontolerance CP Always responds, may not always return the most recent write pick two Every read receives the most recent write or an error Operates in the presence of network partition failures
  • 10.
  • 11.
  • 12.
    Master-less (Peer-to-Peer) Architecture NODE NODE NODE NODE NODENODE NODE 1. NO Single Point of Failure 2. Scales for writes and reads 3. Application can contact any node (in case of failure - just contact next one)
  • 13.
    Why partitioning? Because scalingdoesn’t have to be [s]hard! Big Data doesn’t fit to a single server, splitting it into chunks we can easily spread them over dozens, hundreds or even thousands of servers, adding more if needed.
  • 14.
    Is Cassandra APor CP? Cassandra is configurably consistent. In any moment of the time, for any particular query you can set the Consistency Level you require to have. It defines how many CONFIRMATIONS you’ll wait before the response is dispatched; 14 PreparedStatement pstmt = session.prepare( "INSERT INTO product (sku, description) VALUES (?, ?)" ); pstmt.setConsistencyLevel(ConsistencyLevel.ONE); cqlsh> CONSISTENCY Current consistency level is QUORUM. cqlsh> CONSISTENCY ALL Consistency level set to ALL.
  • 15.
    Cassandra Biggest Users(and Developers) dtsx.io/cassandra-at-netflix And many others...
  • 16.
    Hybrid-Cloud and Multi-Cloud On-premise Datais globally distributed Geographical Distribution
  • 17.
    State-of-the-art NoSQL Database 17 ●DBaaS, serverless, auto-scalable ● Multi-cloud, distributed, multi-node cluster ● NoSQL, multi-model ● Tabular, document, key-value ● Based on open-source Apache
  • 18.
    c OSS Apache Cassandra Atabular NoSQL database OSS Stargate.io A data gateway to allow multiple usages $25/month credit Launch a database in the cloud with a few clicks, no credit card required. Z Swagger UI GraphQL Playground Tools User Interface Web-based developer tools and apps CQL JSON GraphQL REST GRPC Apps CQL Console
  • 19.
  • 20.
    K8ssandra Components inContext 20 Kubernetes Cluster Data Gateway NoSQL DB Web / Mobile Apps Users Ingress Microservices Operators Reaper Medusa Object Storage Repair Backup / Restore Deployment Metrics UI Metrics DB
  • 21.
  • 22.
    A cohesive platformfor optimized Microservices joy ● Based on standards ● Unified configuration ● Live coding ● Streamlined code for the 80% common usages ○ Flexible for the 20% uncommon ● No hassle native executable generation Inner loop == Developer Productivity “Our developers used to wait 2 to 3 mins to see their changes. Live coding does away with this!” 22
  • 23.
  • 24.
    @ @ </> Packaging (maven, gradle…) Build Time Runtime Load configfile from file system Parse it Classpath scanning to find annotated classes Attempt to load class to enable/disable features Build its model of the world Start the management (thread, pool…) How does a Typical Java Framework Work?
  • 25.
  • 26.
  • 27.
    Microservices Architecture evolution Monolith90s User Interface Services Data Multi Tiers 2000 SOA (2005) Microservices (2015) Front End Backend Data Layer UI UI ESB Service RDMS SPA Backend for frontend Native Web Component API gateway Service Registry Service Mesh Service Service Service Service NoSQL Object BigData NoSQL NoSQL Microfrontend Service MicroServices Service Service Service Service Service Service Service Service Service Service Service Service Service Service Service Service Service Service NoSQL NoSQL NoSQL NoSQL NoSQL NoSQL NoSQL NoSQL NoSQL NoSQL NoSQL NoSQL Data Mesh
  • 28.
  • 29.
    Microservices Principles ✔ Organizedaround Business Capabilities ✔ Products not Projects ✔ Smart endpoints and dumb pipes ✔ Decentralized Governance ✔ Decentralized Data Management ✔ Infrastructure Automation ✔ Design for failure ✔ Evolutionary Design Martin Fowler
  • 30.
    Microservices + • Reduce Cost(Scaling, Design) • Reduce Risk (resilience) • Increase Release Speed • Enable Visibility (security, monitoring) • Complexity (Security, Transaction, Orchestration) • Cultural Changes • Bigger RUN footprint ADVANTAGES DISADVANTAGES -
  • 31.
    Rest vs gRPCvs GraphQL ? ● Decoupling Client / Server (Schema on read) ● API Lifecycle (Versioning) ● Tooling (API Management, Serverless) ● Verbose payloads (json, xml) ● No discoverability ● Not suitable for command-like (functions) API ● CRUD superstar ● Relevant for mutations (OLTP) ● Public and web APIs ● Limited Business Scope + -
  • 32.
    Rest vs gRPCvs GraphQL ? ● High Performances (http/2 – binary serialization) ● Multiple stubs : Sync, Async, Streaming ● Multi languages - Interoperability ● Strongly coupled (schema with proto files) ● No discoverability ● Protobuf serialization format ● Distributed network of services (no waits) ● High throughput & streaming use cases ● Command-like (eg: slack) + -
  • 33.
    Rest vs gRPCvs GraphQL ? ● Discoverability, documentation ● Custom payloads ● Match standards (JSON | HTTP) ● Single endpoint (versioning, monitoring, security) ● Complex implementation (tooling, still young) ● Nice for customers nasty for DB (N+1 select) ● Backend for frontend (JS) ● Service aggregation | composition (joins) ● When volume matters (mobile phones) + - GraphQL
  • 34.
    Quarkus Cassandra Extension 34 ●Native Quarkus Config ● Cassandra Driver Session Support ● Cassandra Driver Object Mapper Support ● Support for Mutiny Types (Reactive Types) ● Native Image Support ● Support for DataStax Astra (Cassandra DBaaS)
  • 35.
    Native Quarkus Config 35 quarkus.cassandra.cloud.secure-connect-bundle=/path/to/astra/bundle.zip quarkus.cassandra.keyspace=ks1 quarkus.cassandra.auth.username=alice quarkus.cassandra.auth.password=s3cr3t quarkus.cassandra.request.timeout=5seconds quarkus.cassandra.request.consistency-level=LOCAL_ONE quarkus.cassandra.request.page-size=1000 quarkus.cassandra.metrics.enabled=true quarkus.cassandra.health.enabled=true
  • 36.
    Cassandra Driver SessionSupport 36 @Inject QuarkusCqlSession session;
  • 37.
    Cassandra Driver ObjectMapper Support 37 @Dao interface ProductDao { @Insert Uni<Void> create(Product product); @Select Uni<Product> findById(String id); @Select Multi<Product> findAll(); } class ProductDaoProducer { @Produces @ApplicationScoped public ProductDao produceProductDao() { ... } } @ApplicationScoped class ProductService { @Inject ProductDao dao; }
  • 38.
    Support for MutinyTypes 38 @GET @Produces(MediaType.APPLICATION_JSON) @Path(“/product/{id}”) public Uni<Response> findProduct(@PathParam(“id”) String id) { return dao.findById(id) .map(todo -> Response.ok(todo).build()) .ifNoItem().after(Duration.ofSeconds(5)) .recoverWithItem(Response.status(Status.NOT_FOUND).build()); }
  • 39.
  • 40.
    Specification of Servicelayer Create a new Task Mark a task as completed Delete a task List all tasks
  • 41.
    Data Model CREATE TABLEtodos.todoitems ( user_id text, item_id timeuuid, completed boolean, title text, offset int, PRIMARY KEY ((user_id),item_id) ); user_id item_id completed title offset todoitems TEXT TIMEUUID BOOLEAN TEXT INT K C↑
  • 42.
    Rational ● Our Partitionkey is user_id ○ We chose to have one todo list per user (avoiding any select * from table) ● Service ○ findTodos() for user ○ createTodo() for user ○ deleteTodo() from its id (userid + itemid) ○ updateTodo() from its id (both to mark it as complete and update title) ● REST API ○ The userid will appear in the URL ○ Provide major version (best practice) /api/v1/{user_id}/todos
  • 43.
  • 44.
  • 45.
  • 46.
    Architecture FrontEnd Presentation Tier TODOBACKEND Backend Application Tier Databases DataTier Database DRIVER /client/index.html /specs/index.html REST API
  • 47.
  • 48.
    48 Livestream: youtube.com/DataStaxDevs YouTube Twitch Games menti.com Discord YouTube Questions:https://dtsx.io/discord L i v e a n d i n t e r a c t i v e Attend the live sessions
  • 49.
    49 AstraDB astra.datastax.com GitpodIDE: https://gitpod.io Katacoda katacoda.com/datastax Complete Workshops Labs 2 c Database + GraphQL + PlayGround c c c
  • 50.
    Become a JediMaster of Astra 50 datastax.com/workshops
  • 51.
    JOIN OUR ASTRADB BUILD-A-THON HACK! 📍 3 months, 3 rounds of challenges. 📍 Join 1 month, 2 months or all 3 Each month, we’ll reveal a fresh new set of challenges you can partake in. All you have to do is have Astra DB as your backend. USD$41,000 worth of prizes ➡REGISTER - buildathonhack.com
  • 52.
    Try Cassandra+Quarkus 52 ● Createyour quarkus + cassandra app (code.quarkus.io or running the following): $ mvn io.quarkus:quarkus-maven-plugin:1.12.1.Final:create -DprojectGroupId=io.quarkus.astra -DprojectArtifactId=quarkus-astra-demo -DprojectVersion=1.0.0 -DclassName="io.quarkus.astra" -Dextensions="resteasy-reactive, resteasy-reactive-jackson, micrometer-registry-prometheus, smallrye-openapi, smallrye-health, cassandra-quarkus-client" $ cd quarkus-astra-demo $ ./mvnw clean quarkus:dev ● Stand up your Astra free database (astra.datastax.com) ● Check out https://k8ssandra.io quarkus.cassandra.cloud.secure-connect-bundle=<path>/secure-connect-bundle.zip quarkus.cassandra.auth.username=<user> quarkus.cassandra.auth.password=<pw> ● Get coding + see docs for more info and try the Quarkus + Cassandra workshop https://quarkus.io/guides/cassandra https://github.com/datastaxdevs/workshop-intro-quarkus-cassandra/
  • 53.