Depending on your use cases you may need to access databases with different patterns: CRUD, commands, Streaming, Batches, Asynchronous, Reactive At DataStax, the developer advocates team implements reference applications for developers. We had the chance to implement multiple approaches and can provide feedback. KillrVideo.com is one of this application, it has been written in 4 languages (Java, C#, NodeJS, Python) and implements API with REST, Grpc and GraphQL.
Though live session, browsing real code, you will see implementation details, lessons learned and get working source code in Github as a takeaway.
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
JavaFest. Cedrick Lunven. Build APIS with SpringBoot - REST, GRPC, GRAPHQL which one should you pick?
1. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Cedrick Lunven | Director of Developer Advocacy #DataStax @clunven
Build APIS with
SpringBoot
REST, GRPC, GRAPHQL
Which one should you
pick?
2. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
About me: Cedrick Lunven
Director of Developer Advocacy
Creator and Maintainer of FF4j
Java and Spring Dinosaur
3. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Agenda
50min
2
3 DEMO and Code Browse
Data Model & Persistence with Apache Cassandra
1 Anatomy of a Spring Boot Micro service
4 Decision tree
5 Take my code and slides + Q&A
4. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
NEW PROFESSIONAL
JAVA EVENT
MAY 30th, 2020
KYIV, UKRAINE
Cedrick Lunven | Director of Developer Advocacy #DataStax @clunven
Anatomy of a Spring Boot Microservice
1
5. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Monolithic
Business Logic
User Interface
Data Interface
Multichannel
UI Mobile UI Web
ESB
SOA
Specialization
BUS
S1 S2 S3 Sn
RDBMS
noSQL
DataLake
Micro
Frontend
All Things Distributed
Web Components SPA Native
BFF (Backend for Frontend)
Micro
Services
Data Mesh
Api Gateway Service Discovery
RDBMS Graph Hadoop
Document KV newSQLColumn
TSDB
Distributed Tracing
Containerization
Layers
Business Logic
(Services)
User Interface
Data Interface
(Dao)
Backend
Front-end
OLTP OLAP
RDBMS
Microservices Architectures
6. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Building a Spring Boot Microservice
Exposition Layer
Service Layer
Persistence Layer
Database
Data Model
Configuration
Monitoring
Security
Access Patterns
Volume
Throughput
Latency
Security
(Service, Component)
(Controllers)
(Dao, Repository)
7. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
« Vanilla » So easy….
Exposition Layer
Service Layer
Persistence Layer
Database
Microservice
(Service, Component)
(Controllers)
(Dao, Repository)
1
Normalized
Data Model
2 CRUD
8. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
« Vanilla » So easy….
Exposition Layer
Service Layer
Persistence Layer
Database
Microservice
(Service, Component)
(Controllers)
(Dao, Repository)
DATA
DATA-REST
WEB MVC
Configuration
Monitoring
Security
Database Driver
10. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
When volumes grow ?
Exposition Layer
Service Layer
Persistence Layer
Database
Microservice
(Service, Component)
(Controllers)
(Dao, Repository)
CREATE INDEX
JOIN
SHARDING
…
3 CUSTOM QUERIES
11. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
CAP Theorem for Distributed Systems
Consistency Availability
Partition
Tolerance
?
12. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
NEW PROFESSIONAL
JAVA EVENT
MAY 30th, 2020
KYIV, UKRAINE
Cedrick Lunven | Director of Developer Advocacy #DataStax @clunven
Persistence Layer and
Data Model with Apache Cassandra™
2
13. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
NODE
NODE
NODE
NODE
NODE NODE
NODE
Apache Cassandra™
1 Installation = 1 NODE
ü Capacity: ± 1TB
ü Throughput: 3000 Tx/sec/core
Communication:
ü Gossiping
DataCenter | Ring
= Distributed NoSQL Database
14. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Scales Linearly
• Need more capacity?
• Need more throughput?
• Add nodes!
15. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Data is Distributed
Country City Habitant
USA New York 8.000.000
USA Los Angeles 4.000.000
FR Paris 2.230.000
DE Berlin 3.350.000
UK London 9.200.000
AU Sydney 4.900.000
FR Toulouse 1.100.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
DE Nuremberg 500.000
CA Montreal 4.200.000
CA Toronto 6.200.000
Partition Key
16. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Data is replicated
59 (data)
RF = 3
0
50
33
1783
67
17. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Data is replicated
RF = 3
0
50
33
1783
67
59 (data)59 (data)
18. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Data is replicated
RF = 3
0
50
33
1783
67
59 (data)
59 (data)
59 (data)
23. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Use Cases
High Throughput
High Volume
Mission Critical
Availability
Realtime
Distributed
Heavy Writes
Heavy Reads
Event Streaming
Internet of Things
Log Analytics
Any TimeSeries
Caching
Market Data
Prices
No Data Loss
Reponsive
System
Any CRUD
API Layer
Geograhically
DeploymentsD
R
A
S
Banking
Track and Trace
Customer Apps Enterprise Data
Layer
Applications
Global Company
Retailers
Hybrid Cloud
MultiCloud
?
24. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Apache Cassandra MicroServices
• REALTIME REQUESTS & SCALABILITY AT CORE
• DISTRIBUTED ARCHITECTURES
– From ACID to BASE (Basic Availability, Soft-State, Eventual Consistency)
– Implementations: CQRS, Event Sourcing
– Colocate service and Data
• DECOUPLING BY DESIGN
– 1 KEYSPACE = DOMAIN
– 1 QUERY = 1 TABLE
28. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Application Workflow
R1: Find comments related to target video using its identifier
• Get most recent first
• Implement Paging
R2: Find comments related to target user using its identifier
• Get most recent first
• Implement Paging
R3: Implement CRUD operations
29. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Mapping
Q2: Find comments posted for a user with a
known id (show most recent first)
comments_by_video
comments_by_user
Q1: Find comments for a video with a
known id (show most recent first)
Q3: CRUD Operations
30. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Logical Data Model
userid
creationdate
commentid
videoid
comment
comments_by_user
K
C
↑
videoid
creationdate
commentid
userid
comment
comments_by_video
C
↑ K
C
↑
↑C
31. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Physical Data Model
userid
commentid
videoid
comment
comments_by_user
TIMEUUID
K
TEXT
C
UUID
UUID
↑ videoid
commentid
userid
comment
comments_by_video
TIMEUUID
K
TEXT
C
UUID
UUID
↑
32. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Schema DDL
CREATE TABLE IF NOT EXISTS comments_by_user (
userid uuid,
commentid timeuuid,
videoid uuid,
comment text,
PRIMARY KEY ((userid), commentid)
) WITH CLUSTERING ORDER BY (commentid DESC);
CREATE TABLE IF NOT EXISTS comments_by_video (
videoid uuid,
commentid timeuuid,
userid uuid,
comment text,
PRIMARY KEY ((videoid), commentid)
) WITH CLUSTERING ORDER BY (commentid DESC);
33. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
We have everything we need
Conceptual Data
Model
(Entities, Relations)
Application Workflow
(Queries)
Database Family
(Technos +Table)
35. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
NEW PROFESSIONAL
JAVA EVENT
MAY 30th, 2020
KYIV, UKRAINE
Cedrick Lunven | Director of Developer Advocacy #DataStax @clunven
DEMO
3
36. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
https://github.com/clun
/javafest-2020
docker-compose up –d
40. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
CLIENT API DRIVER
Parameters
SynchronousQueries
PreparedStatement
& Parameters
Bind
Parameters
BoundStatement
ResultSet
ResultSet
Results
Blocked
API
41. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
CLIENT API DRIVER
v
Parameters
AsyncQueries
PreparedStatement
& Parameters Bind
Parameters
BoundStatement
AsyncResultSet
AsyncResultSet
Result
API
CompletionStage
Callback Hell
42. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
CLIENT API DRIVER
v
Parameters
ReactiveQueries
PreparedStatement
& Parameters Bind
Parameters
Row
ReactiveRow
Flux
API
ReactiveResultSet
Subscribe
BoundStatement
Subscriber.onNext
Query execution
onComplete()
43. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
NEW PROFESSIONAL
JAVA EVENT
MAY 30th, 2020
KYIV, UKRAINE
Cedrick Lunven | Director of Developer Advocacy #DataStax @clunven
DECISION TREE
4
44. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
Analysis Criteria
Conceptual
Data Model
Application
Workflow
(Queries)
Database Family
(Technos +Table)
Caching
Sync vs Async Reactive
SLA (Volume)
Data Integrity
Filters
Paging
Sort
Latencies Throughput
Versionning
Confidentiality
Atomicity
Cardinality
Developers
Users/Consumers
Language
CodeFirst/
Vs SchemaFirst
Documentation
Test
Build
Packaging
Api Catalog
Internal vs
Public Techno
Profile
XP
47. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
v Decoupling Client / Server (Schema on read)
v Api Lifecycle (Versioning)
v Tooling (API Management, Serverless)
v Verbose payloads (json, xml)
v No discoverability
v Not suitable for command-like (functions) API
v CRUD superstar
v Relevant for mutations (OLTP)
v Public and web APIs
48. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
v High Performances (http/2 – binary serialisation)
v Multiple stubs : Sync, Async, Streaming
v Multi languages - Interoperability
v Strongly coupled (schema with proto files)
v No discoverability
v Protobuf serialization format
v Distributed network of services (no waits)
v High throughput & streaming use cases
v Command-like (eg: slack)
49. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
v Discoverability, documentation
v Custom payloads
v Match standards (Json | Http)
v Single endpoint (versioning, monitoring, security)
v Complex implementation (tooling, still young)
v Nice for customers nasty for DB (N+1 select)
v Backend for frontend (JS)
v Service aggregation | composition (joins)
v When volume matters (mobile phones)
GraphQL
50. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
NEW PROFESSIONAL
JAVA EVENT
MAY 30th, 2020
KYIV, UKRAINE
Cedrick Lunven | Director of Developer Advocacy #DataStax @clunven
RESOURCES
5
55. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020
NEW PROFESSIONAL
JAVA EVENT
MAY 30th, 2020
KYIV, UKRAINE
THANK YOU ! (@clunven)