Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

A Microservices approach with Cassandra and Quarkus | DevNation Tech Talk

A Microservices approach with Cassandra and Quarkus | DevNation Tech Talk

Descargar para leer sin conexión

We will dissect the world famous todo app that provides a REST API (which is the foundation of microservices) with data backed by Apache Cassandra. We will leverage the TODO MVC and the TODO backend projects with the back end that we will build with Quarkus and Cassandra. Attendees will get an overview of Cassandra, including the driver for Quarkus. Through live coding (that attendees can try out later) in a cloud-based environment, primarily in Quarkus and Cassandra, attendees will understand how to implement and connect the APIs to the backend and leverage the generic client(s)provided. After attending this session attendees will walk away with a good understanding of implementing microservices using Cassandra and Quarkus. They will also get a working knowledge of how Astra (Cassandra as a service) can be leveraged in other solutions.

We will dissect the world famous todo app that provides a REST API (which is the foundation of microservices) with data backed by Apache Cassandra. We will leverage the TODO MVC and the TODO backend projects with the back end that we will build with Quarkus and Cassandra. Attendees will get an overview of Cassandra, including the driver for Quarkus. Through live coding (that attendees can try out later) in a cloud-based environment, primarily in Quarkus and Cassandra, attendees will understand how to implement and connect the APIs to the backend and leverage the generic client(s)provided. After attending this session attendees will walk away with a good understanding of implementing microservices using Cassandra and Quarkus. They will also get a working knowledge of how Astra (Cassandra as a service) can be leveraged in other solutions.

Más Contenido Relacionado

Presentaciones para usted

Más de Red Hat Developers

Audiolibros relacionados

Gratis con una prueba de 30 días de Scribd

Ver todo

A Microservices approach with Cassandra and Quarkus | DevNation Tech Talk

  1. 1. Cassandra+Quarkus = Microservices Nirvana! 1
  2. 2. ➢ 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. 3. 3 Intro. 01 Agenda NoSQL 02 Cassandra/Astra/ k8ssandra 03 Microservices = Quarkus+Cassandra 05 Live Coding 06 Resources 07 Quarkus 04
  4. 4. Today’s challenge: Todo App
  5. 5. 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. 6. 6 Intro 01 Agenda NoSQL 02 Cassandra/Astra/ k8ssandra 03 Microservices = Quarkus + Cassandra 05 Live Coding 06 Resources 07 Quarkus 04
  7. 7. 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”
  8. 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. 9. 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
  10. 10. The CAP Theorem 10 Availability Consistency AP CA Partition tolerance CP pick two DataStax Graph
  11. 11. 11 Intro 01 Agenda NoSQL 02 Cassandra/Astra/ k8ssandra 03 Microservices (Quarkus + Cassandra) 05 Live Coding 06 Resources 07 Quarkus 04
  12. 12. 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)
  13. 13. 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.
  14. 14. 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.
  15. 15. Cassandra Biggest Users (and Developers) dtsx.io/cassandra-at-netflix And many others...
  16. 16. Hybrid-Cloud and Multi-Cloud On-premise Data is globally distributed Geographical Distribution
  17. 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. 18. 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. 19. + = 19
  20. 20. 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. 21. 21 Intro. 01 Agenda NoSQL 02 Cassandra/Astra/ k8ssandra 03 Microservices = Quarkus + Cassandra 05 Live Coding 06 Resources 07 Quarkus 04
  22. 22. 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
  23. 23. IT’S STILL JAVA!
  24. 24. @ @ </> 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?
  25. 25. @ @ </> @ @ </> Build Time Runtime Runtime Build Time The Quarkus Way
  26. 26. 26 Intro 01 Agenda NoSQL 02 Cassandra/Astra k8ssandra 03 Microservices = Quarkus + Cassandra 05 Live Coding 06 Resources 07 Quarkus 04
  27. 27. 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. 28. 28
  29. 29. 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
  30. 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. 31. 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 + -
  32. 32. 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) + -
  33. 33. 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
  34. 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. 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=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
  36. 36. Cassandra Driver Session Support 36 @Inject QuarkusCqlSession session;
  37. 37. 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; }
  38. 38. 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. 39. 39 Intro 01 Agenda NoSQL 02 Cassandra/Astra/ k8ssandra 03 Microservices = Quarkus + Cassandra 05 Live Coding 06 Resources 07 Quarkus 04
  40. 40. Specification of Service layer Create a new Task Mark a task as completed Delete a task List all tasks
  41. 41. 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↑
  42. 42. 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
  43. 43. TodoMVC.com http://todomvc.com/examples/angularjs/
  44. 44. Todo Backend.com
  45. 45. Rest API Specifications (specs)
  46. 46. Architecture FrontEnd Presentation Tier TODOBACKEND Backend Application Tier Databases Data Tier Database DRIVER /client/index.html /specs/index.html REST API
  47. 47. 47 Intro 01 Agenda NoSQL 02 Cassandra/Astra/ k8ssandra 03 Microservices = Quarkus + Cassandra 05 Live Coding 06 Resources 07 Quarkus 04
  48. 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. 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
  50. 50. Become a Jedi Master of Astra 50 datastax.com/workshops
  51. 51. 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
  52. 52. 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/
  53. 53. Thank You! Try Astra + Quarkus!

×