#CCOSS - Cloud-Native Cassandra Workshop: Build Cassandra Microservices with Spring

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well hello everybody and uh thank you for that introduction again i'm david jones gilardi joined by my friend and colleague cedric lavonne and as as pedro mentioned um so we'll have a couple parts to this right so the first part part one uh will be the build of spring java microservice with apache cassandra so we will get into an app we'll get into a little code we'll hook it up to an apache cassandra database and have some fun there for part two as you mentioned we'll bring in patrick mcfadden and uh patrick if you don't know patrick uh he is like a god in the cassandra community and he's going to explain to everybody like how how you can contribute back to the project than one with some q a so we can have some freeform questions and by the way at any point ask questions if there's anything that's not clear or something you want to know more about feel free to go ahead and ask questions and we will be watching the chat okay so with that um so this is a hands-on session we'll start off with a little bit of demo uh but to get you started there are two tools in particular we're going to use today the one you see there on the left hand side is is the screenshot anyway of datasets astra so astra is a managed apache service platform it's a patrick service in the cloud we will talk more about that we have a free tier it's free forever so for those of you who want to follow along with us while we do the workshop and and do the code and everything you're more than welcome to um and that is one way to do it on the right-hand side you'll see this mentee.com or mentimeter so this is actually fun we get to do some we're going to do ask you some questions but then later on it'll kind of you know more towards the end of the workshop we're going to do a quiz and the top three winners out of that quiz will get to win some swag from us um so the minty stuff is actually pretty fun um so we encourage you to join into that and especially two for the initial survey questions the things we ask it kind of gives us a better idea of who all of you are um so we definitely encourage you to check it out oops i almost played the video there let me put myself back my clicker was in the wrong spot don't mind me all right so yeah so this is you know just a disclaimer um this is a coding session uh you know to to kind of do it you do need to have some experience with java but honestly um the way that we build the workshop the way that the github repository is structured it is mount for self-service you could do this totally at your own pace even if you don't know java you'll be able to get around and follow along just fine you can also do all this locally on your own laptops if you wish but what we're going to do today is we're going to focus on doing things with gitpod up in the cloud if you're not familiar with gitpod it is a wonderful cloud-based ide that is provided for free through github so we're gonna in once we get to the part where we show you the github repository and where all the code and everything is um you'll see a little button where you can just click on that and launch gitpod and launch an ide up on the cloud and have everything running it's especially useful if you're doing say collaboration with teams but mostly if you have like say a lower resource laptop and you don't have to go through the ide configuration you click a button and go and it's it's wonderful from that standpoint cedric do you have anything you want to add on that one yes yes so just remember you don't have anything to install on your machine because we are using git pod you would have a full id in the cloud working the database is also in the cloud and you won't have to code really yourself in this two-hour session we will do code code walkthrough and you will start the app and execute unit test that should be working if you provide the proper the properties awesome all right so with that there we go all right so what we'll do here is these are some of the links that we're going to be working with let me grab these we should drop these down in the chat so the first one there for those of you who are going to follow along if you go to that link that dtsx data stacks dot io workshop that'll bring you to the registration for astra it takes just about a minute again everything that we're going to do today is completely free there's no credit card or anything like that so this will allow you to spin up a free apache cassandra database in the cloud that we can use to work with our code that second link there is that data sex academy spring boot to do app that is the github repository that we're working off of today uh and again it's meant to be self-service right so we're gonna kind of bounce back and forth between what we're showing you here in that repo but you could totally do that at your own pace um and then the last one there uh for those of you who are interested in in working with apache cassandra in java in particular we're using the 4.9 java driver the datasex driver java drivers for apache cassandra let's let me get those links actually i'll drop those oh did you already drop the link i joined the link everywhere oh thank you you're already on yeah i knew you'd be there oh i see it now i didn't see it at first all right so now we get into the first part of menti so if you would please go to mendy.com code 87 51 69. see if i can beat cedric to it he's probably going to beat me to it [Music] okay so right let me do that on slack then what we'll do is we'll pop over to our mentee yes and i already see some thumbs up that are coming in so if you would let me know when you get to mentee and you get in there give us a thumbs up and we'll get those numbers wonderful thank you cedric and we'll wait till let's see okay we've got 40 people in here so we'll let's get at least 20. come on let's get 20 people in the menu at least right yeah oh do you want me to add myself yeah boom oh no i'm sorry cedric here you almost there three more and don't forget once you do this part later on this is going to set you up for the quiz i love all the thumbs up coming in all right i'll go ahead and we're at 17 we're close enough we'll do it here all right so again these are just some survey questions we want to find out a little bit more about you these are totally anonymous no need on that uh first one is how much experience do you have with apache cassandra there's always an interesting one to see yes this workshop is meant to be live so this is wow this looks like almost yeah wow that's like almost everybody that's amazing all right so never used it well we may have to that's good to know because there'll be some parts where we talk about apache cassandra a little bit um we may have to uh ensure that we explain a couple things okay less than one year we have one person in there who's used a little bit more excellent all right thank you all right let's move on to the next one and then have you been to any of our workshops before i'm gonna guess it's gonna be no for everybody uh we do we have had workshops oh we have one yes what oh we have two wow because we our workshops uh the ones we've done outside of the conference and such um we do them for latin america and such well that is i did not expect that well welcome back by the way for those who've been to one of our workshops before and for those of you who haven't welcome and and thanks again for coming and checking this out i'm actually i'm really surprised here yeah that's cool so we are doing those live workshop on youtube on wednesday and thursday and i feel that best time for latam region is um yeah the wednesday at 12 yeah um all right wonderful thank you and all right so how did i this one's going to be funny you can you can select multiple in this one how did you hear about this workshop i have a feeling that from a conference might be it oh it came through an event wow okay i'm gonna get surprised again i'm definitely getting surprised again how cool super cool oh did you notice that because this is a green it's kind of so a little fourth wall here uh you might notice that we're using some video effects and apparently uh my green screen matches to the green bar that i added perfectly so you're seeing a background i didn't see that coming that's kind of fun oh and i see uh jose in the chat says i'm wrong because i follow you in twitch well that's good to know we should keep the twitch stream going all right then are you using microservices in production how many of you are using microservices oh yeah the legacy one's always fun right oh and there's our fun green pie again that's funny i think i know what it is i'm going to try something i hope i don't by accident uh mess anything up but if you give me a moment i'm going to turn that off there there we go i i see that nice okay all right all right so it seems like we have a really good spread there there are some folks that do not know what microservices are but it looks like um there are quite a few that are using that's wonderful true nice all right and the last one i believe which programming languages do you prefer yeah you can only pick the first so as well yeah right now we used to list like all of the languages well not all of them but some funny ones uh it but it gets to a point where there's too many on the screen all right so so we do have we've got a lot of python users in here all right awesome all right thank you for answering those questions and giving us that context now if you would leave this window open we're going to come back to it later for the quiz when we go to do the swag yeah all right so first thing we want to do is give you just a little bit of a demo quick demo on what it is we're doing today in the workshop and then we're going to give you an introduction into astra i briefly mentioned what that is i'll get into more detail later then cedric is going to take it and he is going to give you a nice primer on spring and spring boot what those are all about um and how then we can go about planning planning our application to use with spring um and then okay yeah go ahead no no nothing i thought you're going to say something oh good old good okay and then we'll follow up then working with the data sex drivers now to be clear the desex drivers can be used with open source cassandra astra data sex enterprise whatever right so if you're using and they're they're pretty much the standard for open source cassandra and such there is a ton that the drivers do for you right out of the box we'll talk about all of what that is and then the last part is we're going to go ahead and build and test our our basic crud app so the first thing here is you know if you think about it what do you usually do when you want to learn or need to need to learn a new language you know many of us have our own methods for how we go and jump into a new language um there is a project um if you're familiar with it by the way let us know um in the chats to do mvc uh so to do mvc is a project that has implemented essentially a known front-end ui a known interface um in a bunch of different javascript languages frameworks all that kind of thing what's really neat about this is then if you want to learn a new language let's say that you know you're really familiar using jquery and basic javascript but you want to get into react or something well then you can start by looking at and understanding the 2d mvc application it's a very simple app by the way you can start by looking at it in the language you know and then you just go ahead and you literally can just click on one of the ones that you don't you see it's the same exact implementation and then you can start taking a look at the code making a nice comparison in a matter of fact if i pop over there real quick and take a look at it i mean they have a ton of frameworks that are supported and again they're all implemented the same way so if i go to like ember you know i can then exercise the app that way if i go to react i can look at how it's implemented and react i can look at the source code for all of these so again it's a nice way you can use that as kind of like a jumping board to help you understand a new language now there's another project called to do back end so what they did is they built off of what to do mvc did were to do mvc is really the focus on the front end using javascript frameworks hence the name to do back-end is really focusing on the back-end languages things like java things of the business layer so again if i take a look i'll go to the back end this one by the way is even crazier um there are so many languages here it gets it's a little daunting actually um you know we're focused on java and springs so that's what we're going to be using uh today um but they they're wonderful tools uh if you are again if you're learning a new language from the front end and the back end piece to get into cedric is there anything you want to add to any of that uh i need i think i need to do a pull request to put our sample in this website yeah i know i was actually looking for it the other day that's why i asked you the question i did because what we're doing is because we we so so what we've done is we've taken the to do back end that's what we're doing today we've taken the to do back end and we've hooked it up to apache cassandra with astra is what we've done so matter of fact actually what this is doing could be used for regular vanilla cassandra as well um so so yeah we should we should commit that back that's a good idea okay and this is generally what it looks like i'm actually going to show this to you in a moment so we're going to take the the front end piece now we're not implementing the front end part today right but we are implementing the back end rest api and then using the swagger ui to expose that api and if you're not familiar with swagger it's really cool because if you've got a rest implementation in your app swagger allows you to very quickly and graphically explore that that particular api as a matter of fact if we take a look at it i've got it running already over here um so what this will do you can see here i've got all of the different rest end points that i might have um and so it allows me i can just kind of like click on one let's say i want to cancel that and i want to get you know implement corporations want to get all of the tasks that i might have i can just come here to the ui i can say execute it now right now i don't actually have any tasks in here um so why don't i go ahead and put one in there i can do that every time every time i click on the wrong thing yeah use the first it's funny so let's say yeah let's say i wanted to create some tasks through my rest endpoint i'm going to give it a title of just demoing creating a task i say execute wonderful and now if i go back to getting the complete list of tasks i can try that out execute and and i oh you know something i deleted the table i dropped the table cedric i have to go recreate that when we do the tests so um oh jeez okay yeah yeah i dropped it that's what i did so what we'll do though you can imagine what should happen there obviously is when you bring this up you're gonna you know you're gonna be able to interact with the rest api um so anyway for those of you who are again familiar with swagger it's nice because i don't have to write this in code i can just implement swagger and it exposes this graphically it's a really nice tool um to use um the last thing before i move on is just to show you by the way what uh the mvc app itself looks like the to-do mvc app looks like um so it's just a simple task list that's all it is right so you can see i was kind of playing around earlier i put in one for uh ccos awesomeness and some and more tasks um if i want to put something else in hello pedro cask or whatever um i have other interactions you know i can say delete a task or i can complete a task things like that so what this really does is it exposes basic crud operations right they're the exact types of operations that when you're first establishing connectivity to your database from an application standpoint you want to figure out that plumbing for for crud operations you know create read update and delete that's what this does so that's the front end piece and that is then um using the back end to talk to the database all right so moving on do we have any questions or anything oh can i zoom yes i can totally zoom yeah when i go back i'll make sure to zoom in thank you for pointing that out okay so astra simply enough deus ex astra is a fully managed cassandra without the operations so cassandra is a distributed nosql database for those of you we saw in the beginning right a lot of folks have never used it before many of us are used to using relational databases like mysql or you know oracle or whatever and the main difference is those are not distributed databases where cassandra by its nature and what it does um is actually a database that spans across multiple nodes it's a distributed system that can scale up um linearly and in scale up in real time it is known for its resiliency its robustness um its ability to be always on and to essentially kind of perform at scale and indefinitely scale um some really familiar names that use cassandra and have for years uh folks like apple fedex um oh geez there's a million others cedric and i'm all of a sudden blanking on all the good ones apple uber uber yeah instagram facebook is you know facebook is actually where it came from um geez home depot lowe's you know like many of the banking industries like there's there's there's a ton of big players and there are some clusters out there that are thousands of nodes right and so that's one of the big benefits of cassandra it allows you to scale up and and you can do it you know without incurring downtime but what that means what that translates into is that by the nature of being a distributed database it's a little bit more complex to run right it's not the same as just having a single mysql instance or something like that um so from a development standpoint when we're writing apps we don't really want to be spending a lot of time messing around with the database and worrying about that so that's where astro comes into play especially with the free tier and the free tier is what we're using today um so it allows you to spin up a fully managed cassandra cluster in a couple minutes and then just get going with development astra was kind of you know is developed with developers in mind you get a five gig free tier by the way so again everything we're doing today is is free forever um so it's a five gig free tier um it is perfect especially when you wanna start experimenting with cassandra and you wanna start understanding what that looks like from an application perspective you can spin up as many you know key spaces that you want uh you know tables that you need for different projects maybe for your different applications um so it allows you to do that all up in the cloud you don't have to worry about resources or installing anything locally anything along those lines okay so with that the first thing we want to do here real quick is spin up our astra database so what i'm going to do is come back over to our repo so for those of you who are following along we want to do two things notice here oh someone asked me to zoom let's do this let me zoom in make this a little better let me know if that's better if you can read that better by the way and i'll keep an eye let me know if that zooms better so the first thing we're going to do coming to the repo again we'll drop that link down in the chat done i love cedric okay [Laughter] right so you notice there uh there's this opening git pod link i'm just going to go ahead and control click that it's going to launch git pog git pod is going to launch the whole ide the repository and everything it's going to do that on its own but then the second link and that's the link that cedric just dropped that dtsx.io workshop that will bring me to the registration page for astra so what i'm going to do is i'm actually going to do this with you quick i'll just bring up a new window let's say astra now i've already registered obviously i have my accounts in place um but i'll show you what this looks like in a second so when you go to the registration you're going to see a page like this more like this you can sign up with your email with google github whatever you happen to have it only takes a minute then once you get signed up we'll kind of let everybody get to a point where okay after there we go where you get to a screen that looks like this all right you should see something like this actually i'm going to get rid of the one that we see here all right you should see a screen that looks like this give everybody a moment to get to that spot for those of you falling around following along if you would give us a thumbs up in any whether it's the chat in zoom or in slack let us know that you've gotten to this spot yes please and yeah didn't want to disturb i had a question about versus cassandra as usual in the chat so i was starting and swimming oh well do you want to while we're waiting for some thumbs up do you want to go ahead and talk to that or yeah yeah maybe so absolutely first um so both and cassandra are no sql database okay so first maybe for junior developer you would consider moving to nosql database when your data does not do not fit on a single server anymore you know if everything is fine on the server keep your server the rational database are very good and have a lot of things so acid transaction joints um so and ensure both consistency availability and network partitions so everything is fine in a single machine in the nosql world it's more distributed now we are working multiple nodes and so there is a theorem a famous theorem named mark blue theorem or cap and it tells you that you cannot achieve consistency network partition and availability at the same times and so pick consistency and network partition and cassandra pick availability and network partition so first even with the basic architecture you can say that cassandra is all about availability and is all about consistency so in you will store json document and in cassandra you will start you will store tables okay so what are the sweet spots of cassandra i throughput so very high rights very high read at the same times huge volume of data okay for cassandra one terabyte it's nothing um so in cassandra you will install multiple nodes on a single node you will have one terabyte and if you need more capacity add new node to the cluster or if you need more throughput add new node to the cluster it's scale linearly that's the strong the the main strength of customer now the data is replicated in multiple nodes so if you lose any of the node the data is still there so second range of use case for customer is really no data loss as the data is on multiple nodes you can lose oh you know it's not a big deal okay um [Music] yeah so this is my cell cap for the customer against another gains so cassandra and are not competitors yeah they are not dealing with the same use case yeah they may both be in the no sql space but yeah as cedric said they're not they're not really yeah directly recognized like yeah yeah yeah it's like you know yeah it's like tomato and cabbage they're born they both are vegetables but you know i like the tomato and cabbage analogy there [Laughter] okay so hopefully that answers uh i saw the question that came through um so if you have any follow-ups or anything of course let us know okay so hopefully uh you're here at a screen that looks like this now what we want to do now we've given you the the instructions here in the repo right everything you need is actually here in the repo um but when you come into it the first time after you register you go to add database now as i mentioned you want to pick that free tier if you get any kind of credit card anything it means you didn't pick the free tier uh so make sure you pick free uh that is free again forever uh it's perfect for um uh you know experimenting and development and just kind of you know getting your application going or getting your feet wet with cassandra you can pick from any of the main three cloud providers aws google cloud or azure now you'll notice in the free tier only google cloud is lit up if you go to some of the higher tiers um then the others will light up right so given it's the free tier we kind of control things just a little bit more it's the same thing with the regions in the free tier you're only presented with the two regions either u.s east or europe west again if you open that up a little bit and pick different areas you'll you'll see that they have regions that correspond to the cloud provider that you've chosen um and what's available there so again as it ramps up but our goal here i want to be very clear about this yes as you can see that as you start to go up in tiers you know you start getting into paid tiers that's not what we're talking about here really the key is to get the cassandra you can use this free tier indefinitely um and it's really nice as a development tool okay so with that i'm going to choose us east then once i've done that my configure button lights up i'll say configure and now as i scroll down we've provided you with the values that you need here the database name key space name so on and so forth for your own apps for your own use you can honestly use whatever you want right we just asked for those of you following along that you use these with us reason why is if there are any questions or anything that come up around this we know exactly what values you've used and then we can help you a lot more efficiently um so you'll notice here i just literally grabbed database went to database name so to do db uh to do app for the key space kv user for username and kb password for password again we're just using these values for today once you have filled all these out and of course as long as your passwords uh you know validate properly there we go like i would expect then this create database button will light up use the create database and boom you'll see the status go to pending it might take a minute or two but what'll eventually happen is it'll turn to the screen active like you see here and that's it you have a cassandra database it's ready to go right and at that point you know we anyone who's doing this we'll just go ahead and leave that there and that way when we come back around um we will we will then use that database with our with our application all right do i see any questions okay i see pet i see cedric is posting things thank you cedric wonderful okay yes all right excellent now the secure connect bundle piece um i'll just i'll just wait on this on the cedric you think it's a good idea to have them do it now i figured we'd give folks a chance to get the database going and then come back yes yes maybe let's come back to that later yes we'll come back to that by the way we will wait for sum up on the chat just to see if you your database is ready that's right that's right and the secure connect bundle is actually really nice if you think about it if you are connecting to a database that's out in the cloud that is accessible by public ips you probably don't want just anybody to be able to walk right on your database and do things astra is very secure and what astra does is once your apache cassandra database is up it will create what's called the secure connect bundle um that encapsulates all of your ssl uh like keystore trust store all that kind of stuff that you would need from your application to connect securely to your database it encapsulates all of that in there it knows where your nodes are all of that what makes that really cool is that once you download this bundle you just pass that in as a configuration line parameter to your driver initialization when it connects to the database and it handles all of the secure connection for you again it's made so developers can just get in drop the bundle and go and you don't have to mess with it all right so with that then we are going to move into the introduction to spring and spring boot i'm looking for questions i don't see any just yet um all right so oops sorry so i will give it to cedric all right okay um well so let's get that rolling um just before starting um you know i'm doing java for let's see 15 years now and i had the chance to work with spring very early in 204 and so spring has been released i think first version in 202 so it was designed by rod johnson and it used to be called interface 21. during that time it was all about application server you know web sphere [Music] web logic and in the oss world more tomcat and all the development you you did well you know simply interact with the application server to do database connectivity uh i i'm sure you remember about gndi you know good sweet memories right um and so at that time uh spring came with the idea to provide a lightweight framework and maybe to stay away from the huge and heavy application server and provide nice way to connect component one to each other one way to do that is by implementing a pattern called inversion of control so you define a service in a java interface here grading service with method signatures and you can have multiple implementations of this interface when you need these when you need to to use this interface in your code you will simply work with the interface and not implementation you know it's a lose coupled between implementation and interface and with that it's pretty cool because now you can have multiple version of your service you can do some mock of your service you can have multiple situation with multiple uh versioning of your service and you don't have to change the people who using the code because people using the code only use the interface of course now in the java world spring is not the only one to provide this version of control pattern we can think about google juice but they were the first and this is why i mean spring was a success in day zero and it was called interface interface two one you know i didn't know that about the interface two one part i didn't realize it had that name originally that's cool all right so let's switch next slide okay thank you david and so at the at the at first it was simply inversion of control a little bit of annotations but more and more components have been added to spring and now if you go to spring.iu you see that spring is a huge galaxy of multiple components you can do whatever you like with spring and one part is micro service this is the one that we will dig into today but you can do much more than spring micro service you can do reactive cloud web apps serverless event driven and batches we are running multiple workshops during the year and we had some content about spring micro service reactive and cloud okay so let's dig into microservice okay so if you look at spring components this is some categories you will find core technology where apps data access testing integration in languages today we won't use everything if you just click next next david you will see that we will use the core dependency injection we will expose an api a rest api so we'll use the rest part to build web application we will connect to the database so we will use the data access to run the exercise you will do test so we need the test context over here and we will simply use java the id is really keep it simple stupid for you to have the running app with only what's needed there to start the app okay so if you look again if you dig into all the categories you can see a bunch of framework so today let's keep it simple i told you we will simply use spring boots not a lot of spring data not a lot of spring cloud simply spring boot so what is spring boot okay spring boot is really the run time for your application in this runtime you will find multiple layers the presentation layer the rest api for us the business layer where you find all the algorithms all the business logic in your service and at the bottom you see the persistence layer how to interact with your database this is what we call dao or repository layer and this persistence layer is interacting with the drivers and drivers is really the piece of code that will connect to the external system like a database so instead of running web's web application server now it's standalone application it's a fat jar and the good part of a standalone app is you can ship that as a docker container and make it scale but it does not rely on anything else so it simplify your build and simplify the configuration and deployment so spring boot is this runtime and you will add multiple starter in the spring boot so you do have starters for metrics health check configuration and much much more the id is starting with spring boot core and for instance if you need production monitoring you will add spring boot starter actuator if you need that accessing you know any kind of database you can add spring boot starter spring data and so forth and so on so really spring boot is now the go-to uh framework when it comes to building micro service with spring because everything is packaged in the single runtime the spring boot runtime okay i told you about layers so presentation layers are the rest api for us also called controller the business layer is also called services persistence layer is repository or dio and the database what i want you to realize here is a service can interact with one two multiple repositories the purpose of the service is composing aggregating so data coming from multiple source and prepare the data to be used by the controller and that's it and if every single layer is a slice in your sandwich spring root is really how to build a nice sandwich [Laughter] okay let's move on so i told you about spring and spring boots okay so what do you want to build with this spring framework okay so as i told you i'm pretty old in the java world and i i i were there with these kind of revolutions so first all applications were monolithic so the big rectangle is a single runtime so in the mainframe for instance ui logic and data we're all in the single piece of hardware and so if you want to scale maybe your compute power because you may you know you know simply have more computation you need to scale everything and that's costing so what do you want to do you want to go to what they they call that open and they split in multi tier now we do a front end back end and data layer three runtimes and you can make one runtime scale and not the other and you can have people implementing only frontend with his own skills and another implementing backend and in between we created some format to end change so you know web services at that point at that time at that time maybe a pc yeah maybe sockets i actually remember applications they were just direct silence that's true that's true so i think it was beginning of so multi-tier was definitely in the 90s yeah so beginning of uh 20th century came the soa for service oriented architectures and now the idea is split again we are keep using front-end back-end and data layer are split but inside each box you split again so now in the ui you have maybe delegated ui for mobile dedicated ui for web server dedicated ui for administrators same in the service you have maybe a dedicated runtime called esb enterprise service bus hosting one or multiple service and service can be reused but they do have a single piece of software for the service you know in these esb architectures we tend to have osgi and you can make a service scale even if it's still inside a esb but it's still not the best scenario right same for the database now rdpms it's not the single silver ballet database handling all the situation you have so much data then you need to think about hadoop or no square database we had the question before and now let's go to the modern applications in the ui again the light to split split split splits again so now instead of having a single ui for uh the the the web for instance now you do have in the in the ui for the web you do have single page application you do have components inside a page you have some native part for mobile you know you just split into component again those components need a very specialized backend just to have exactly that as a need this is what we call back end for front end this is where you find graphql technology now because graphql is pretty neat for total front-end you only get what you asked and that's really the proper technology json format to interact with content in the backend though now each service is standalone and we call that microservice okay you got the id with the spring boot every single piece is standalone but you don't want to implement everything you know like security throttling monitoring inside each service even if it's possible that by simply adding stuff in just fat service why not delegating those technical functions to tools like api gateway put a proxy in front of all your microservice this proxy will do authentication throttling monitoring for you and service only have to expose now an endpoint for um to be able to expose all the metrics to be monitored so standalone services and try to delegate technical function to third parties like api gateway service mesh for a scaling and service discovery for dynamic scaling on the data layer we still have the same data technology okay new database come every day new kind of database come every day you may have heard about new sql or cloud db or something like that well but the fundamentals are still there rdbms nosql hadoop but inside each data technology now we think about data mesh we split service in business domain now we split database in business domain as well all right let's move to the next slide so what is a micro service so i don't reinvent the wheel here i simply reuse the the main books you might find on the topic so first is building micro service from sam newman we can see the small draw here so that's some characteristic you can find so culture of automation hide implementation decentralize deploy independently designed for failure and the principle is also unliked by my tinfoiler in one of these blog posts so organize our own business capability product.project smart 10 points decentralized decentralized infrastructure automation design for failure and evolution in design okay don't want to go too much into the detail it's mostly hands-on today but you know as a nutshell advantage of the microservice reduce cost okay use make you scale only what you need it reduced risk because now the micro service can be scaled multiple times it can be scaled out so if one piece fails you cannot you still have multiple instance to re to keep the service alive it increased the real speed because you ship only small piece of software any enable visibility because now everything is um and then in the single place for security monitoring and you do have a nice monitoring capabilities but on the drawback disadvantages it's complex it's not for everyone having hundreds of service in your it is not that easy it really needs some you know proper orchestration security management it's also a culture change and guess what it's a bigger run footprint because if single service has its own runtime it's huge cpu it's use ram okay next slide and so the last part introducing you microservice is really okay macro service really fit the apache cast way of thinking so i told you before cassandra is well known to be very good at scale out okay real time request scalability at core you need more more input add new nodes you need more capacity add new nodes they both fit distributed architectures so it's not acid anymore how would you do a distributed transaction with multiple microservice first i need to insert my user in my microservice one and then i need to insert the payment for this user in micro service number two oh but micro service number two is not there so do we remove a user doing a rollback no it's not working that way anymore there is no holdback in the micro service world so how do you do well it's working the same way as cassandra it's basic availability software eventually consistency so you will do compensation you will introduce orchestration um there are multiple ways to do that some are secures or even sorting and you will have dedicated service for business content okay and you might say that oh but i heard that in microservices there is one database per micro service okay you have to understand that when people told you that it's not one database installation per micro service it will be so costly and now you lose all the benefits to have nice micro service which cost less so the idea is simply one micro service has a domain some resources um so with the custom how you can have one key space per micro service or even one table per micro service so resources are very limited per micro service hey uh cedric real quick i just want to stop you i'm seeing some messages that are coming in that for some reason a set of folks cannot see the screen so i'm asking others just to make sure before you continue and and no one can see i so i'm i'm there i do this i see it as well okay okay i pin your video just to be sure that i can only see your video and not on the speaker yeah so for those um if for some reason the video did move away in zoom if you go to gallery view you should be able to find our screen if you right click and say pin that should bring it up so you can uh definitely see it there for some reason it got stuck on somebody else i i now i'm seeing some of the messages it looks like that was the case yes okay good it happened to me before i was seeing peter because it was speaker view and i what i did is simply go to david gillardy video right click and say pin video and now i'm stuck on david for good. yes sorry if you're stuck at me you have to look at me time that's okay on the other side okay so it looks i i think it looks okay from the messages i'm saying all right all right yeah definitely let us know thank you for uh sending the messages in we're all watching so let us know if you see anything else like that okay and that's good because now i'm done with all the you know um staff and explanation i think we can go back to real stuff all right so um can you take over there now yeah okay let's do that all righty so now we get into the fun i should go back over here all right let's go back over this way all right so i did see that there were some folks that were asking at what point should they be at really at this point all we need to do is we've created the database uh if you're following along in the repo so we've created the database you should get to a point where you have the status active with your to-do db database so what we're going to do is scroll down just a little bit now this is the part where we get into that secure connect bundle so i'm going to show this to you right so don't worry about if you're like hey what's he what's he doing he just you know went past this stuff a little fast i'm going to show you exactly what i'm doing um so here i've got my active database now if i click on my database i'll go to a detailed section right where i get more detailed information on the database now we're using the free tier right since we're using the free tier it's always going to be zero dollars per hour but obviously if you're using one of the other tiers you would see what the cost is information that might be really useful at some point like the username of your database how much capacity you're using that kind of stuff but what we want to do is we want to connect to this database right so what i'm going to do is i'm going to click on the connect button up here in the top right hand corner now today we're going to use the driver to connect but you notice that there are actually multiple ways you can do this you can connect with the rest api a graphql api which for those of you using graphql that's seriously cool stuff right there we're not doing that right now and then the driver this is when you click on driver you're gonna see the button for the download secure connect bundle um so this is the this is the part uh where we are now going to get that bundle i talked about that we can use in our application to hook up uh the app so what i'm gonna do is i'm actually gonna like just flip to a different screen and come back over yeah i need to start this up again to my app by the way let me reload my other astra i have two of these going on right now so one thing i want to point out if any one of you had previously been using astra and you had a database created with a different name like i do here and you're like hey i can't create this to do db because i already have this other one you can when you have a database created and it's active you'll notice at the bottom you'll see key spaces uh this add key space now something we haven't really explained if you're wondering what's a key space so in cassandra a key space is just like a database or a schema in their relational counterparts right it's the place where we're going to hold all of our tables set replication we're not going to worry about replication here but it's where you're going to hold all your tables the domain right so if i did need to create another key space i can just say add key space put in the name hit save that's it and you can see here i actually have two i've got another keyspace killer video that's my original one and then i have my my to-do app so those are for folks who may had already been using astra and you wondered how to do that so you can add multiple key spaces but for now um you know for those who started brand new you're going to see what we do with the tudo app so okay so now what we want to do is go back to our git pod i'll go back to mine if you hadn't launched it already uh make sure in the very beginning that was like that first button just control click to launch this and you will see it come to something that looks like this right you're gonna see it launch the app it does by the way git pod when you launch it the first time there are some artifacts it needs to pull some images and such and it might take it just a moment but you're going to see something just like this with a terminal window now what we want to do is in the default directory and scroll back down to where we were this is where this curl comes in now there are other ways to do this this is one way to do what we're just about to do to get the cred zip but what we're going to do is go back over to connect like i said pick driver and i want you to right click on the download secure connect bundle when you right click it say copy link address now what we're actually doing is we're just going to pull this directly into our app in git pod that's why we're doing it this way so i'm going to say curl this command by the way is right here it's right here in the github repository so i'm going to say curl dash capital l don't forget the quotes i'm going to paste in that link i'm going to redirect that to a file called creds.zip and what i should see you'll notice that i received a package and if i do an ls-la there you'll notice that i have a creds.zip it's about 12k that's about the right size right now one thing i would like to point out when you're here in the app this secure connect bundle link this this session will expire after about like five minutes right it's a security feature essentially so if for some reason that happens and you try to download it and you find that the the file and curls like 300 bytes or something like that it's really small just refresh this page and do it again um again that is for security reasons so just make sure that when you right click that and get that link address uh that you do go in here and and do the curl command pretty quick and let's see i you may have to make your tabby no yeah let's make it bigger you're right thank you for pointing that out otherwise it can be hard to read we go to like 1980s font sizes here you know we do when we do workshops right it's a terminal so but you can see that git board is pretty powerful so it's like eclipse or any ide and everything is installed so you can maven you can java you can npm if you want there everything's there yeah github github is really cool okay i see arturo in the chat is talking about an error oh why a spring bed clinic hmm where do you oh yeah you shouldn't need to use that yeah i you know arturo that's really interesting why you're seeing spring clinic yeah this is the definitely the one for the to do app i guess let's make sure that you're in the right pace let me copy the link address okay cedric you'll do that with this link yes okay you're going to drop that if you could drop that in the chat as well in slack because that's where our two oh you did okay thank you yeah make sure yeah we'll just make sure you're in the in the right spot there yeah you shouldn't be at the spring pet clinic that's kind of yeah so yes so curl command what i'll do is i can't give you the exact curl command that i used because this is going to be unique for mine but i'll just go through that process again so i'm going to go let's say i was here i'm going to go to connect connection method driver i'll right click say copy link address then i'm just going to copy notice in the github repo right here matter of fact i'll drop this i'll go recopy it i'll just drop this you have the oh you did it already cedric's on top of it that's great yeah that's great you presenting i appreciate that so at this point so i'm just going to type that command so curl dash capital l double quote i'm going to paste that link in double quote redirect to creds.zip oh okay so arturo missed the miss the [Music] double quote ah yes so it's so you did it great see yes put you you and you need to put double quotes around the link yes that's it yeah yeah that's an easy miss arturo yeah yeah that's i think i wonder sometimes if we need to do something different in the text here to kind of expose that and then again once you've done that if you do an ls al you should see i have a creds.zip and about like i said the size will be about 12k right you should see something like that okay good i think i think folks are getting wonderful then from there i'm just going to the next set of instructions so what i want to do is we're going to move our creds.zip down a directory so notice i'm going to move creds.zip into spring boot to do app and then i'm going to change directory to spring boot to do that and again if i do an ls here you'll see i have my creds.zip along with my palm and everything and kind of watch that okay good i see a thumbs up there wonderful all righty now once i'm at this point now i can go ahead and and perform the maven step so this is something if you notice that cedric just talked about this a second ago um gitpod is awesome i mean we're not behind getpod but we we'd love it it's it's great um you can you can by default you can actually install a lot of the stuff right by default in your configuration but it's it's really flexible you can you know work in a bunch of different languages um a lot of stuff is available so now i don't even notice i don't have to install maven right i can just say this and maven's already here and i will download the world yeah go ahead cedric no i just hide myself for a sec i'm in front of the prompt ah right right no problem i will be there soon yeah so all i did was copy this and again we can drop this down in the chat as well i'm gonna beat cedric on that one okay do it do it success all right so then it'll it'll it doesn't download as much of the world you should see the success at this point and now we can move to the first exercise um and let me know yeah let us know if you run in into any trouble at this point and hopefully you're here with us and we'll keep an eye on it it was a tricky part yeah it was a tricky part yeah and the cool thing downloaded yeah and once you have the zip you're all good to go from this point what we're just about to do you're going to see how easy it is to now connect up to our cassandra database in astra and that's kind of the point right you only need this once and boom you can use this all over the place in your in your app all right so what we want to do now is we're going to navigate uh in in our ide we're going to navigate to the directory here the spring boot to do app spring boot tutorial really source test java com data sex examples i'm going to go to source you see i've been playing in here earlier it does save your state by the way yeah there we go down to so again source test java com data stacks examples now the first one we want to bring up is going to be this connectivity to astra explicit it's the first one here this one and let me open this up a little bit so you can see it now what we're doing this is like the simplest pass if you will um all this is doing is you know essentially setting uh the values directly in our class here now would i ever want to explicitly store things like my username and password directly in the class probably not we're just using this as a quick example to show you like the quickest and dirtiest way to get going right but notice that here this aster zip file variable i have it's going to reference the directory and the creds.zip we just created then again if you use the username and password that we uh said before kbuser kb password and then our key space and let's see somehow cedric artero has the spring pet clinic stuff yeah yes i i just wondering um maybe he click on the wrong git butt link maybe the git bot link at the very beginning of the ring okay yeah cedric arturo cedric is going to take a look and uh he'll see what he can find on that one okay so just make sure that these values fit whatever you chose if you use the values from the workshop you should be good but if you did do something separate put those here and then later on in the code as we scroll down you'll see this is it so in cassandra when you're using the drivers you're going to establish something called a cql session the cql session is the object that manages everything for your database connection your connection pools all sorts of things so we want to establish we want to initialize one of those we're going to use our builder and in this case all we're doing is passing this one line with cloud secure connect bundle uh it passes the secure connect bundle we used up here and then our username and password and our key space and build that alone right there is enough to establish a secure connection to the database and start working with it and you'll see what we're doing here is in the logger when we go to test to make sure this is working we're going to use that cql session we're going to get some metadata from our database to get the key space that we're working with so once you're at that point now all i have to do is run the test so i'll go ahead and drop this here and i will drop it in the chat as well and the other chat and then if that all works now it's going to go ahead it's going to initialize connection to the database we're just using this to make sure it works i see a success if i take a look at my output boom okay connection established astro with key space to do app now in our in our output or log we didn't hard code in the to-do app right it's actually getting the key space that we're working with so we know that it has successfully connected to the database good that worked so we know that this particular pattern for connecting is working properly and we've we've got the basic plumbing in place all right how are we doing okay so now in the next one what we're going to do is we're going to go to the next class that we have here this connectivity to asteroid with conf test now here's the difference with this one in the first one we explicitly set all the values for our connection right in the code right but that's not really a best practice obviously again we don't want to store our username and password like right in our code what we can do with the drivers is configure an application.conf in our app put all the configuration there and then it's very simple to just tell the driver hey go look at the application.conf it'll use those settings and then you're good to go so that's what we're going to do in the second test so you'll notice here in this test we still have our cql session that hasn't changed the one difference though is we're going to get our resource our application conf if i go over to my resources i have my application conf so if i take a look at that you'll see some settings in here things like what's my key space where my secure connect bundle is and again you shouldn't have to change these if you have followed the instructions there in the repo and then the username and password another thing we've done here is we've increased the timeouts um if you're in you know if you're in a location that maybe has a slower connection to the internet or or something like that or maybe the region you have to connect to is a little far away it's good to just increase these right so you don't time out soon so we've increased these to 10 seconds just to make sure for slow connections that that's okay the key point though is that none of the configuration is in my class it's all in my application.com file all right so with that now i'm going to scroll down a little bit here's the next test so this is the one that we're using to use the config file i'll go ahead and drop those and after i do this i'll wait just a minute make sure everybody's on the same page yeah please yeah yeah i figured all right so we're running this one this one now is going from the config file again i should see the same thing right you see our log output we're going to establish connection but we're going to use the database metadata to pull the actual key space name and it looks like that was good and here it is so i know that i've connected now with my configuration file okay so with that i'm going to wait for a moment just let's get some thumbs up make sure that folks are with us we'll see what's going on with arturo there yeah that is um yeah i have no idea why arturo is in the in this the pet clinic workspace i'll just get another minute oh wonderful okay so cedric you're working with her turtle great yeah i'm so curious to find out what's gonna happen there okay got it all right let's see now one thing while we're waiting i just want to point out is at this point all we have done is establish a connection to the database right we haven't created any tables or anything like that um so what i'm going to do is i'm going to come back to my cql console we're going to do this a little bit later we're going to verify some things a little bit later in the in the repo and the instructions but i'm just gonna do it real fast just to take a look so i'm gonna take a look at my key spaces oh i should probably blow this one up too huh there we go yeah and we see that we have the to-do app one so i want to use to-do at now describe my tables okay so i need to drop this this is the one that i remember i said i was working with before because we didn't we haven't actually created this table yet yes wait what the oh you know something why was that even there that's interesting it helps if i use the right stuff yeah there we go you can't just you have to tell it that you're going to drop a table right you know details right let's try that again there we go much better okay so i don't have a table or anything like that i've just established a connection to the database and um and i see that arturo dropped an image okay all right so what i'm going to do in this next one when you go to exercise 2 here now we're going to create the schema real time with code and test some inserts out so what i want to do here is now we're going to navigate to that that same section but source test java com data sets examples here here we go down here and now you see this crate schema and astra test right now notice what we're doing here at this at this point we're actually going to use our application comp again we're using the same configuration and setup that we had before but this time we're now going to go ahead and essentially create the table you see this simple statement we're just creating a statement with the driver um all this by the way all this uh to do this repository today uh table to do these are variables that are in our to-do list repository um interface we'll look at that in a second actually it's just pulling the values out for the columns and everything that we're using there but we're actually creating the table so we're going to create the table our partition key our columns and then it's going to execute that in a matter of fact yeah i should pull that up and pull it up yeah and we can still go back to slide a bit because um we did not introduce which table we need that's true yeah let's do that i stopped b yeah i stopped a little bit before and i think during the time people connect and give out some things oh hey looks arturo has the right he's got the right one yes that was so interesting that that got into the wrong workspace like that cool that's our fault we do we probably have some wrong links we must yeah so we'll we'll have to fix that sorry about that uh thank you for being patient and uh i'm glad i'm glad you're moving the right place now great all right so cedric did you want to talk to these a little bit um and before we move on a little bit more sure so if you remember what i said about multi-layer in a spring boot so for the controller we will use spring web spring web mvc using rest controller we don't need any service layer because there is no aggregation composition we will simply go directly to the repository with to-do list repository and we will inject the repository into the controller layer and then we will use pretty clever tools named swagger that will based on annotation you provide in the controller layer will generate a working client and by the way this is the one david used before and it's pretty powerful so not only you can do a post put patch gets all the http method but it can also handle http basic and spring security if you would need to and what's really cool about it when you take a look at the the implementation classes for it for the rest for the rest endpoint the rest api um you don't have all of that ui code that we have in swagger you don't have to write any of it right it's provided for you and you use the annotations to hook all that up it's really nice actually yeah okay so next slide let's see what we got okay so what uh entity and query do we need with this app so to build a data model with customer you need entities and queries so if you look at entities pretty obvious right you need a task with a uid a title complete not complete and the order just to be able to put them in the right order on the ui next and then for queries we simply do create read update delete no no real complex queries but this is the workflow you need to follow just to be able to create the cassandra data model so let's go that word with the to-do app we simply have a single tables to do task pro having all the attribute from our task and we will use uid as our full primary key um yeah don't go into too much detail yeah it's i think this one's pretty self-explanatory because it's kind of a one-to-one relationship right between exactly the various uh items that we need for our tasks and then what we're implementing here in the table yes and because we do have a uid it's pretty easy to do insert and get by id delete by id update by id that is the only key we need to interact with the two app already so see that's pretty straight forward simple table and so in the to-do list repository all these constants for my tables i've put them as constants this is a trick because if tomorrow i need to change one column except uid you cannot change the primary key then if you want to rename a column you can and then in your code you simply have to update one constant and everything is updated and if for some reason you won't get rid of one column you just remove the constants and you can see everywhere in your code where you need that value okay so queries list all the tasks create a new task update delete and delete all okay by the way all the slides we are showing are on the github repo we shared with you it's a pdf so if if i go too fast you you can simply go back to the slide and download them we give you away everything yeah so you'll see at the very top in the table of contents there's a link for the slide deck or just in the repo you can see the slides here they're all presented for you yeah so you can totally go and do this at your own pace um if you need to later on exactly this workshop is really designed to be self-service if you need to so you do have the slide the exercise both astra and eatpod are free and you can use it free forever when you need so go if you if we go back to to-do list repository you can see the signatures of our method find by id so find by primary key they might be a task or not so i'm using optional and so to create or update i will simply define an upset because just for you to know in cassandra every every insert is an absurd if the task already exists if i insert a task with an id and i execute exactly the same statement i don't get any error record already exist it will be updated so every insert isn't observed in cassandra so let's go directly single method upset and i will delete by id because id is my full primary key okay so i think i think that's what you were after though because we if i remember cedric we started getting into the to-do list repository interface but we didn't actually tell them what it was yeah true so you know exactly exercise one and two was okay because i mean connectivity um yeah so it's not kind of connectivity but now if you go to exercise three where you will create the tables and do statement you need to know what the table look like right right okay so with that i haven't actually done exercise two um so now that we have a little bit more explanation of what this to-do list repository actually is right um and then of course is um as cedric is pointing out uh you know the various underlying objects that then support um here we go uh like implement from the from the driver standpoint so we've got our to-do list repository we have our method signatures but then what's going on underneath the hood right so as you mentioned for the upsert it's really just doing an insert because of the way that cassandra works right so if we take a look at the upcert method the actual implementation you can see oh look here's something familiar here's an insert statement right and i'm going to add in uh the values for for each of those and this is how we're going to interact with our task list uh you know when the when a call comes in from the rest api then as you remember when i went to the swagger api right you had you know get a list of all the tasks or you know insert a task it's it's actually calling these methods here in the back end all right so we've got that in place so what i'm going to do is i want to run this test we're still in the tested spot right um so the key thing is now we're going to go back over to our create schema astra test if you haven't done that already this is where we started talking to that to-do list repository so i'm going to run this test and i will drop these down here well i have to copy it myself anyway right so so this one's a little different where before we were just validating that we were making the connection to the database this time we're actually going to create a table right and it did say success so let's go take a look if you remember before i did in fact drop it um so i'm going to look at my key spaces and did that get smaller again i could swear i had made that bigger i will do this so i'm going to say use to do app and describe my tables now i have a to-do desk table but there's nothing in here because we haven't actually created any data so it's empty but you can see i've got the fields that we created my uid my completed offset and title uh so at this point we've used our code to connect to the database create the table that we want to work with and now we get to start inserting some data and hooking it up a little bit more okay so in the next one uh this is this is the part i said i kind of cheated and i went forward to the cql console this is what we're showing you here so if i went back to that summary view you're probably in you'll see cql console here if you click that it'll automatically put you into the console yes cedric uh you might notice that you don't have to uh authenticate anymore yes it just logs you in yeah yeah in i think in the readme they may ask you to provide user and password you don't have to do that anymore yeah that's right it'll automatically log you in this is this is a slightly older screenshot right here uh where you used to have to type those in yeah you just click on it it'll log you in you should get a prompt that looks just like that yes it's yeah it's evolving so fast as hard just great yeah and so for those by the way those commands that i've been typing in here this whole time i wasn't expecting all of you to know what they were you'll see here in the github repo that we're giving you the commands if you use to do app describe matter of fact if i were to do the way that it is here in the repo where i say describe a table and specify the exact table i'll get a little bit more information uh compared to what i was doing before you can see here's that create table statement and matter of fact if we take a look at our slides again go back here it is right this should look just like what we're seeing over here right it's it's pretty pretty darn close the only difference is the way it's being uh denoted here with the primary key but it's it's the same exact table all right so now what we want to do is move up a little bit we're going to put in some data oh there it is okay so now uh we want to open this class you'll see it's crud with ask for test so now that we have our table created we're going to just run a test that's going to do a simple insert now notice though it's using the same exact pattern that we saw uh when we were interacting with our taskless repository that's exactly what we'd want really right this is just a test to ensure it's all going so the sample title i forgot what it is but i've changed it to ccos awesomeness so and you'll see this here yeah it was a task that's right a task is the sample title so you can put honestly whatever you want uh in in that class and oh by the way i should point this out i totally forgot uh gitpod by default does not save i have my autosave on so make sure you're saving because if you changed any values before and you're like why isn't this working it might be because you just need to save so i turn on autosave or you can use save oh by the way david between you and i i know how to enable autosave oh yay we need to start enabling auto save yeah all right so now i'm gonna run this last test i'll drop these in here okay and this is to insert some data and again if you remember a moment ago i didn't have any data um right it should be empty i'm going to come here i'm going to run this test give it a second okay success so good it says the task created gave me the uuid if i go back over to my cqlsh console there we go my data is in place so i know now that my code is working with connectivity and basic credit operations to put something into the database all right and then we're gonna go to the the last one here exercise three but you know i'm gonna give a moment for everyone to catch up i also have a complaining dog behind me so i'm going to take care of that real quick uh give me just a moment oh what did you i mean i thinking it was something else talking oh that's funny well that's funny you know real condition yeah i'm not sure exactly what you were all hearing but this is what happens when you do conferences from home right yes yes i was wondering what it means or any anyone else [Music] that's great that's funny yeah alrighty so like i said yes now we have some data so we know that the basic plumbing the basic you know the base of plumbing to our database is hooked up with our app um so now going to exercise three by the way oh i see arturo's typing something i was gonna say if i can get some thumbs up let us know for those of you following along if you're with us and i did see arturo typing a second ago so i'll just keep an eye on that okay so now that was all from our our unit test right we're just using that to just test out to ensure that we do in fact have that connectivity that we can work with the database but that really didn't do anything for the actual application itself so now what we want to do is take a look at the cassandra driver config this is going to be the place uh where we are going to set the application cassandra configuration this is how we're going to manage what the uh the configuration parameters and such we're going to use for our database oh oh yeah totally i'm laughing at arturo that we should take a meme for that's kind of funny [Laughter] yeah we should all right so um all right so let's go to our uh back to our application up here um so you notice under our source main java you know com data sets we have conf and conf cassandra driver config now here's something that's really cool notice there's not much in cassandra driver config it looks quite empty so how exactly am i configuring to talk to my database well remember if i use if i drop an application conf in my resources directory all i have to do to initialize that application comp is say builder.build if i do if i use this pattern it will look for the application.conf automatically it'll pull all the configuration from there so it actually greatly simplifies what this particular configuration class looks like so this is it right here this is enough to connect my database because again it's going to use that application conf that has all the data all the connection parameters that i would use and yes and if you're familiar with spring boots and you're asking yourself why all these constants are not part of application.yemen well if if you open back this this file david you can see that there is a lot there so we simply put we simply say okay all the cassandra settings should be in dedicated file and that's pretty easy you can change that without changing your code exactly in the application yeah and imagine you know if you have an application that's on development it's in staging it's in production right you have multiple environments this is just a really nice way that you could have a different application conf for wherever your application is you don't need to touch a bit of code and arturo saying um unfamiliar i still have a nightmare spring boot when i worked at symantec i'm so curious arturo as to what that story is all right so like i said we're gonna use that application.conf um from the resources folder that'll configure the connection and we already kind of we already talked really about that to do this repository so i'm just gonna scroll past that piece uh the same thing with the implementation right that's where we actually see the implementation of the interface and the underlying details of what we're actually doing when we delete or we upsert and all those types of things okay let's see yeah and we kind of talked about these things but now this is getting into the rest the rest controller so let's pop over to our rust controller now this is this to me and cedric i don't know if you're going to have i assume you're going to have more you want to say about this this is actually some of the coolness as far as i'm concerned as spring and how it works um because of as i mentioned before to have a whole rest api implementation instead of having to write that code ourselves the spring framework does so much of it for us and being able to use annotations like this right at rest controller and then define what those endpoints are going to look like so if you remember our swagger api before we had like slash api slash v1 slash to do's we literally are defining that right here right and then we've got the implementation and the spring the spring framework is doing a lot of this for us right it's all this other stuff that's coming we i get that for free i don't have to code any of this up i don't know if there's any more you want to say about that cedric in that section um no all good okay i'm just checking yeah so without now this is the big part right here right so we've performed tests at this point um but we haven't actually run the app so that's what we want to do in this next piece now this is again using spring boot uh with maven and what's nice is notice i don't have to create a war file i don't have to deploy this i can just literally come especially for a micro service this is really nice and say spring boot run maybe in spring boot run like this and it will run the app now something that gitpod is going to do uh when you expose a port in gitpod it's going to give you this little dialog and say hey do you want to make this publicly available do you want to open a browser that kind of thing again that's really nice especially if you're let's say you're working with the team or if you're testing on your own and now this will expose the port for me it'll generate the url you'll see that here in a second this is what i expect i actually have to give it the rest of the the uri but you notice see this 8080 so we had exposed port 8080 for our application um and gitpod will actually generate this this url that you see like this this would be unique to your instance but the cool thing is that now if i take a look i do see that my app is up and it's running so now if i grab the rest of this right this is for the swagger ui in particular i can just go here did i forget my let's put a slash there slash is useful there we go and now boom there's my swagger ui right so all of these are implemented this is actually coming from my rest controller so again as you saw me if i now that we've played around in here a little bit and i do have something in place if i go to my swagger ui and get my complete list of tasks and execute there we go remember this is what i should have seen earlier but i didn't because i had by accident removed all my data but yeah you see this is what we created with the code earlier with our test and now we can see that is exposed here in the swagger ui let's see oh it looks like cool yeah i see i'm looking at arturo's screenshot there all right and then if we want to we can play around here a little bit and again insert some tasks or something if i want to say create a new task yes um so we do have a question what do we have so um did we use spring initializer to create this project so yes um if you yeah anybody can go to start.spring.io and you can initialize a template for your project so i picked spring web to have a rest api spring test to do uh testing and i think i put also spring actuator to get the monitoring you can see all these dependencies in the pump so this is what david showing right now but i did not pick spring data for instance for this demo um i do have the same project working with spring data but today was very keep it very simple simply use the basic drivers connect and do a few queries so yes we used a spring netherlands as a starter but we added some dependencies on our own after yeah and you can see the spring boot starter there i think i passed up web i must say yeah it's up here but that's pretty cool yeah i wouldn't start any spring boot project without start.spring.io now it's you know way simpler yeah it is it is actually kind of awesome how easy they made to like just start up an application from nothing and you get all the stuff built in all right so hopefully at this point you're you're here right if you've been following along um i know arturo's been putting some screenshots in for us so you can get to a point where you see the swagger ui that exposes the rest api that is then hooked up to your um apache cassandra database with astra and you know i've already kind of i've been exploring this you know getting a list of tasks you can kind of explore uh the rest api now something that's really interesting and could be um pretty fun here is um if you want right so in this particular workshop we're really just exposing the the swagger the swagger api here the back end piece uh with the rest implementation um but as we talked about in the beginning um there is a front end right there's a front end on the to do mvc where you can hook this up and you can hook this up full end to end have a full working front end implementation along with the back end now we're not doing that today but if you take a look at the very very bottom here you'll see this other link that brings you to another one of our workshops and it goes into a lot of detail and it will hook up all everything it'll hook up the whole thing um so you're always welcome to go take a look at that if you want that's so cool i see jimmy jesus enriquez oh sorry if i scored your name sharing is swagger super happy to have the app starting cool i i think i just saw um somebody post the link of theirs oh let's take a look yeah i should yeah i'm gonna do it it worked it should work yeah that's actually it's i love that about this yeah so this uh this came from jimil yeah boom right so so if we want to be really fun right i'm gonna totally create data in your thing will you i am yeah no no i am that's funny uh maybe you need to change uid just to be sure you know maybe you already have created one with the existing uid no that one was a brand new one but i guess i could just do that oh yeah all right but we should i okay so jamil gets to get gets to check us here and um here i'll do it this way and now if i get the list of them hopefully gmail you didn't put any terrible tasks in there oh boom yeah jamil's been busy yeah here they are they're both in here yeah cool yeah that's really cool yeah so again you can imagine what that might look like when you are collaborating with the team or maybe you have some code that you've deployed and you want somebody else to go take a look at it maybe do some tests or or whatever the gitpod makes it really really simple to collaborate and stuff there's there's a lot more features obviously we're not doing a workshop on gitpod it is seriously cool though it's a really cool tool yeah that was cool all right all right so let's see so that's it as far as that part goes now we get into a couple more slides and then we're going to um we're going to do the quiz we're going to enter the quiz yeah we can go quick to the through the slides this is mostly for reference for you just exactly okay so let's do this real fast all right so as we mentioned before um the data sex drivers for cassandra they actually do a ton for you it's not just for data sex astra it's for open source apache cassandra it's for data sex enterprise right you can use them for any of the flavors um one of the i think to me one of the best features of that is you can use the same exact drivers hook up to astra and the free tier as you know from a development standpoint experiment figure out your data models kind of get your initial plumbing going and then let's say that your it department has their own cassandra deployment all you have to do is change like one configuration parameter but use the same exact driver so instead of using the secure connect bundles you'd probably use you know your contact points um and you connect up to your your say your development cluster or something or or your production cluster something that's provided inside your own organization it's the same drivers it's the same everything you don't need to change your code um so that's that's really nice it's really flexible um but it's more than that so as i mentioned before uh when you were talking to astra right we're actually simplifying a lot uh because when you're when you're talking to a direct cassandra database and it would be like this for any distributed database you have to know you know um you have to know where the database is it's the same thing for my sql or anything right you need an ip address you need to know where it is um especially anyone here done ssl in java it's not fun at all at all um the secure connect bundle does it all for you right so it does simplify a lot um so what happens is again you just use that secure connect bundle it will automatically manage the connection for you between you and your your astra database but there's more so the drivers support all the main languages out there so we're talking java today but they're definitely not the only ones but if you take a look here on the left hand side this part i i never honestly thought i'd get excited talking about drivers uh database drivers i've been working with databases for a long time but this stuff is really cool and here's why so imagine you have a distributed database imagine you have one that's got a thousand nodes right um you might even one that has five nodes um you the first question that comes to people's mind is well is do i need a load balancer um how is it gonna know what node to go to for what data the driver handles all of that for you right so there are load balancing policies that are already in place they're pretty smart so they're going to look at they're going to optimize for which nodes should get a particular request and what's cool in cassandra is because it's a peerless it's a not a peerless it's a leaderless peer-to-peer system so any node can do what any other node does any node in your cluster can receive the request it will know what to do to facilitate that request what this means then is the driver could end up talking to any one of the nodes and it's going to optimize for which node is best to get the particular query that you're essentially trying to execute to have the fastest response time to ensure nodes aren't getting overloaded all of this and it's doing it by default in the drivers as they already are so that's what we're talking about when we say like token and data center aware load balancing policies there are retry reconnection policies in there so if a node goes down or for some reason there's a network partition and it can't see one it'll automatically retry all sorts of things so this is being done for you connection pools are being maintained for each of your nodes that's another reason why your session your sql session object you only need one you treat it as a singleton in your app because like i said it is more an expensive object that is maintaining all of this it does maintain gossip with your cluster so it knows the state of your cluster right so it's it's talking to your nodes just like any other node and your cluster does so there is a ton there's a reactive api in there we have a whole other workshop on that uh so for those of you who are familiar with asynchronous programming um if you're if you're not familiar with reactive it's definitely something to take a look at it's it's a really nice evolution of the asynchronous api and how to work with that that's all supported there right so there's there's a ton that the drivers do for you right out of the box uh that you don't have to code on your own it's either any does it support angular um i would i would say like through things like graphql um through more of the rest endpoint the graphql endpoint yes i don't think that there's a driver that supports angular directly like because that's javascript unless you can tell me otherwise so um so we do have a javascript driver so it will simply you know b can be used in any gs framework but i don't think we are using advanced function from angular if there are some object mapping for instance we have our own so that's totally doable on angular but i don't sure we are using advanced function from angular yeah that's right i forgot there's the node driver duh yeah there's the node driver wait it's sitting right in front of me and in the middle of your screen and we've used it how many times yeah because this is because i'm doing all the code you know yeah and you're just showing that code nice just kidding cedric has thrown shade yeah all right so as we as we talked before you saw this in the example with the tests where we're doing explicit settings again this isn't something i would recommend doing in a real live app um as far as like storing your username and password that kind of thing it's just an example this is like if you're creating your first app and connecting up to uh astra this is the simplest thing you can do to connect to the database and get going but the example we showed you again is using the application comp this is definitely the more provided or preferred method to use and if you are using your application conf this is it to initialize your sql session you just need cql session.builder.build it will know to look in the resources directory and use the application call um we already talked about using as a singleton so i'm not going to restate that but one thing you should get in the habit of is to ensure that you close out on applications shutdown ensure that you are closing out your session in some languages it will do this for you automatically but it's a good practice just to to make sure that you are in fact doing it explicitly and then you know we ran through uh all of these tests and such so um all right yeah i guess yeah let me see we've got we've got time cool all right so when you're working with the driver um at its very simplest execution uh if you have your sql section session object you say dot execute you can pass in a query or a statement and there you go you can execute that query that is the simplest way to do it now this is good when you're just first starting up and you're just again testing out to make sure you have connection and things are working i would never suggest using this for real just because it's it's kind of it exposes you to some some potential uh um issues that you can come into play security issues things like that um i would definitely start using your statement objects um the simplest one is the simple statement simple statements are really good if you know that you're going to execute a query once you may have noticed that in a lot of the tests that we did they were using simple statements in your simple statements you can either do an explicit definition like you see here again this would be vulnerable to something like a sql injection so i wouldn't you know i wouldn't suggest doing this in real code this is uh something you might want to do when you're just first testing but it's probably a good idea to externalize your parameters whether you used positional values like you see here the question mark or if you want to use named values either way works the key thing is this once you create your statement object you just pass that to that same cql session.execute and it will execute that statement now when using cassandra the suggested the much preferred path is to use a prepared statement right this really comes down to optimizing the amount of times that you have to parse and compile your statements and reducing network traffic imagine we're talking about patrick cassandra database cassandra databases an individual node can handle many many thousands of operations a second on its own right just one node so imagine you've got an app that is handling you know um multiple sets of thousands of operations a second you don't want to have to be parsing and compiling your statement for every single one of those and then of course passing that across uh to your servers or anything like that so when you prepare a statement and all you have to do is use this prepared statement type so you say cql session.prepare now this statement is actually going to get cached on the nodes where it's being used and the only thing that you're passing along is that is the payload of what the actual parameter values are right um so it again it really reduces network traffic and again get given a cassandra database that can handle so many transactions or so many operations a second this is a huge optimization so generally speaking you should be using a prepared statement that's really what it comes down to unless you have a good reason like in a test once you create your prepared statement object you'll see that later then we'll bind the variables so i have my prepared statement ps i'm now going to use a bound statement later on when i have the values and i will just use my prepared statement object dot bind and pass the values that'll get passed into my parameters and then i'll pass my bound statement to the execute method okay so then with result sets um honestly if you've been using java for any time or really any language uh with a database whether it's a relational database or not results that's been around for some time those are the objects you're going to use to get the results back out of the database they should look and feel pretty familiar if you've been doing that with relational databases uh so here you can see i've got my cql session.execute here's my statement i'm going to pass that back to resultset object one big difference here is there are there are some extra metadata extra information that are in the result sets that are particular to the way cassandra works things like getting execution info um that'll come into play later or if you want to do like a query trace or something you can get that and then the result sets themselves are they they you can pass back an iterator that you can use to just iterate over them so if i do have multiple results and results that i can just iterate through those results and here are some examples of working with the result sets so you see the first case i've got a result set here where i just want to get a single row that single result that one uh one thing to be careful with when using dot all is you know the default page size in cassandra has 5000 but cassandra you know you could have a database that's holding a petabyte of data right um so make sure that you're being very explicit in what you are returning and if you do a dot all and you have a table that has a billion rows you're going to you know it's going to page by default but you're telling it i want to get actually the all is going to get them all because you're going to fetch all pages so so don't use dot all unless you know unless you know that you have a very specified number of results that are coming back again the results that are iterable as you see in the for loop here in this example so you can very easily just go ahead and implement a for loop and iterate through um those values you can also use uh land of functions as well and once you get a row or once you you know if you want to pull out individual values you know visual columns they're types you can see a bunch of examples of doing this now by the way what we're providing in the slides they're just you know a handful of examples to give you an idea of the feel of it this is all stuff that is in the documentation if you remember in the slides in the very beginning there was a documentation link to the driver it's got all of the you know the gross implementation details as well so this is just kind of giving you an example okay we already passed through that part um cedric is there you want to talk about this part here um so i talked before about inversion of control in the spring world this is done either using constrictor or auto wired auto wireless like like we did that okay and we provide the name of the implementation with the qualifier notation but today as we have only one implementation for our interface we don't need the qualifier qualifier all right all right and then again this was in hands-on exercise three where this is the magic right this is the magic where i don't need to deploy a war or anything like that and just run and then here we go all right and with that i will drop our part of the i'll stop sharing and pass it over to patrick um thank you by the way everybody i mean we're gonna still be here we're not going anywhere because patrick's gonna talk and we'll be quiet for a moment um but thank you everybody for for being with us and being attentive and for your questions for the last two hours i hope you got something out of it and patrick it's all yours
Info
Channel: Software Guru
Views: 40
Rating: 5 out of 5
Keywords: SG
Id: IHF9m-9i6m0
Channel Id: undefined
Length: 111min 2sec (6662 seconds)
Published: Mon Nov 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.