Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

JavaFest. Cedrick Lunven. Build APIS with SpringBoot - REST, GRPC, GRAPHQL which one should you pick?

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.

  • Be the first to comment

  • Be the first to like this

JavaFest. Cedrick Lunven. Build APIS with SpringBoot - REST, GRPC, GRAPHQL which one should you pick?

  1. 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. 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. 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. 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. 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. 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. 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. 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
  9. 9. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Entity => Spring-Data => Spring-Data-REST @Entity public class Customer { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; private String firstName; private String lastName; private Customer() {} private Customer( String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } @RepositoryRestResource( collectionResourceRel = "customers", path = "customers") public interface CustomerRepository extends CrudRepository<Customer, Long> { List<Customer> findByLastName(String lastName); Customer findById(long id); }
  10. 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. 11. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 CAP Theorem for Distributed Systems Consistency Availability Partition Tolerance ?
  12. 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. 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. 14. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Scales Linearly • Need more capacity? • Need more throughput? • Add nodes!
  15. 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. 16. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Data is replicated 59 (data) RF = 3 0 50 33 1783 67
  17. 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. 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)
  19. 19. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Self Healing RF = 3 0 50 33 1783 67 59 (data)59 (data)
  20. 20. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Self Healing RF = 3 0 50 33 1783 67 59 (data) 59 (data) 59 (data) Hint
  21. 21. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Self Healing RF = 3 0 50 33 1783 67 59 (data) 59 (data) 59 (data) Hint
  22. 22. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Self Healing RF = 3 0 50 33 1783 67 59 (data) 59 (data) 59 (data)
  23. 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. 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
  25. 25. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Reference Application http://killrvideo.github.io
  26. 26. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Data Model Design Entities & Relationships Queries
  27. 27. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Conceptual Data Model
  28. 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. 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. 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. 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. 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. 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)
  34. 34. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Api Design Methodology 1 killrvideo-dse Drivers DAO3 killrvideo-api-rest killrvideo-api-grpc killrvideo-api-graphql 2
  35. 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. 36. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 https://github.com/clun /javafest-2020 docker-compose up –d
  37. 37. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Configuration – 1# Convention
  38. 38. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Configuration – #2 Java Config
  39. 39. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Configuration - #3 Custom Definition
  40. 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. 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. 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. 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. 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
  45. 45. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Analysis Matrix
  46. 46. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Decision Tree
  47. 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. 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. 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. 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
  51. 51. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Github repo https://github.com/clun/javafest-2020
  52. 52. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 DataStax Developers on Youtube • https://www.youtube .com/channel/UCAIQ Y251avaMv7bBv5PCo -A
  53. 53. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 Sample CODES Micro-service REST https://bit.ly/31RL62I Micro-service GraphQL https://bit.ly/2MVicup Micro-service GRPC Micro-service Kafka Reactive with Webflux Micro-service Serverless https://bit.ly/2pofk0b https://bit.ly/34ePzhL https://bit.ly/2JwsFdM https://bit.ly/31VQz8G
  54. 54. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 community.datastax.com
  55. 55. switch(SpringBoot.api()) { Case REST,GRAPHQL,GRPC } | @clunven KYIV, 2020 NEW PROFESSIONAL JAVA EVENT MAY 30th, 2020 KYIV, UKRAINE THANK YOU ! (@clunven)

×