Spring Caches with Protocol Buffers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so next up let's talk about spring cashiers with protocol buffers protocol buffers or protobufs are a language and platform neutral mechanism for serializing structured data this next talk focuses on how infispan uses protobuf encoding to marshal and store data in context of caching for spring applications let's go ahead and join katia arresti software engineer at red hat to talk us through it so spring caches with protocol buffers i'm super happy to be here with all of you in this spring one uh from paris it's a 7 30 here and i'm katy arresti i'm uh i'm senior up i think this is not um i'm a senior sober engineer from from red hat hi and um so sorry i have just a question do we see here the the do we see only my presentation or or do we see myself here sorry do we say well my presentation i hope we are anyway i'm a senior sober engineer working at red hat in the engineers fan team and i'm a java champion since 2019 well i'm tweeting sometimes from time to time on cadesti so uh just to join me there so um stream a screencast spring caches um spring caches so uh the spring um spring framework proposes a spring cast abstraction uh from from the very beginning because most applications need uh caching at a point for offloading data uh for from the database uh performing uh fast calculations and putting them in in in a cache or avoiding latency um and having better performance in is in applications and so with sprint caches provide this uh cache abstraction that can where we can plug correctly any any of different cache providers uh that can be embedded caches like caffeine that is a local cache uh or esks or different jks jks implementations and we do support infinite span for uh for a long time as well with the spring caches and so a little word about infinity span in genespan we are in version 1217 right now and the development version is the version 13. we are around 100 open source in memory distributed data essentially we build our functionalities on top of distributed caches and we have a major version every year so uh one of the first key features is the interoperability we can use in finnish span with with a springboard and with java applications and java applications in general but not only we can work with node.js or with csharp as well do we propose we have a resilient and full tolerant data through different consistency levels and availability strategies we can perform acid transactions as well in memory over on top of the distributed caches clustering processing of the data and querying over the values of the caches so even if we can use embedded mode in infinistan which means that we will get and every every instance for example of uh of an springboat application with a will embedding an infinite span and create a distributed cache where uh the data will be distributed across many nodes um since this kind of use cases uh lead to um stateful applications where scaling up and down and deployments in the cloud are much trickier the best is to to focus now on the infinite span client server use case where we will use uh we will deploy our applications uh can be an ojs application id of application with a springboard as c-sharp and from from one side using a maintenance pan client and from another side we will have the infinixpan server cluster on kubernetes deployed with the finish panel operator as well and using the rest api or code which is the binary protocol the one used by the uh by the clients uh we will interact with infinity span and this allows perfectly to get the separation between scaling up and down cpu and the scaling up and down memory so um the spring cache um starter and the implementation of a spring boot with infinix fan for now supports embedded caches if you want to use the client server mode you should use the infinispan spring boot starter this starter was developed some years ago with the help of the springboot team and it's maintained by infinix fan so we're focusing again on the client server mode we have our application and steering group application and we want to use caching with infinispan as a caching provider in our springboot application we need to tell the springboot application how we want to mark when we want to serialize the data and how we want to marshal and marshal the data that will be stored in infinite span for that we may want to use java serialization and use java marshaller or a string marceline or protostream seller and i will explain what this is uh in a minute uh from another site the uh caches uh are in the server and the server caches are going to define the configuration we want uh for for the the format the encoding and the format um on how we want to store the data so we can be with java marceline as well with text.json xml or protobuf and um today uh for example all the query features work uh mostly work well yeah you can do some some of the things with the java marsalin but since java marceline has been endless um an endless source of vulnerabilities in the java ecosystem for a long time it was designed many years ago and um today there are other serialization formats that are better so uh we really focused on moving into protobuf as the the stabilization format that will be the best suited for having all the features of infinite spam fully supported so this is what we recommend today until version 11 spring caches weren't fully supported with protobuf uh for example new values weren't supported with um a spring spring boot and in finnish fan caches with protobuf encoding and the sprint session wasn't experiencing abstraction uh is also using infinite span caches to store session data and this wasn't neither supported with protobuf since version 12 of infinispam we can use encoding um encoded caches with protobuf and use deep proto-stream marshaller which is the marshaller that it's part of the protostream library that it's part of infinispan and it's our integration with uh protobuf so the product stream api allows us to um [Music] just using annotations like protofactory or protofield here on the slide uh to annotate our projects and tell infini's fan how to master a new martial protobuf from our hojos and it's it will also the protest stream library create the proto schema and the protest schema is needed also for for proto stream protocol will use this schema to know how to uh transform the data martial and numerous all the data from java to protobuf or but um it also this schema is used by the server to know how to um marginalize our data also on the server side so the only thing the server needs to know to be able to correctly perform all the features uh is the knowledge of this proto schema so uh the best this thing now for me is really to show you instead of show you the slides or more theory to show you a little example i i developed where i'm running an infinite span um in a cluster of a single node in local so i'm not going to the best place in the world on this presentation i will stay in stay in paris which is a nice place in the world as well uh and i have my spring boot application that it's going it's connecting to infinispan in a protobuf that is holding protobuf serialized data and i will show you how this integration is really great and really useful beyond just caching um because i will also show you how running another cluster also in my local which will be in another site new york we'll connect and create a data configure a backup in the london site we've done this in production many times so having different data centers different deployments and different cloud providers connecting each other and doing backup from from the data which is really great because we don't want to lose data sometimes right so um i'm just going to run um coming here to my first so i'm running here with docker compose two different sites and this is the infinistan web console i'm just going to close this a little so here is the london site which is completely empty and i have a a single node running on this cluster that is perfect we can see some statistics of this cluster here nothing has happened yet and i do have another cluster running here which is new york is another with docker compose again together uh it's another site so they are connected through through cross-site replication london new york now i'm going to focus only on the new york on the london the london site in my paris local host so here is my customer application it's a very simple application where here instead of using the spring cache starter i'm using the infinity span spring boot as started remote because we do support embedded and remote client server mode on this starter and to connect to a simple infinite stand this is a workaround for docker for max you can ignore because my my inflation is not complicated or anything so i just need to tell local coast and port one one two two two to be able to connect with my infinispam hotrod client so i'm just going to run here my application and since it's starting i will show you here i just have it's a really very very simple application that has a rest controller with a get buy id here and a customer that i want to retrieve and i will inject the customer repository um to use caching in a springboard application we will enable caching with an annotation over here so when i go to define by id you want to cache maybe put in the cache this method i use the cacheable annotation so the first time this method will be executed if the key is not found in infinite span but these successive calls of this method will be ignored and the value will be retrieved for infinity span and i'm configuring here the customer cache so this is the same thing even if you're using java marsalin or protobuf but we want to use protobuf so the first thing is that my um the cache i want to use i need to define an encoding to tell him that the encoding of the cache is a protostream and i'm also using indexing indexing here because i want to perform some search and if you see here the i want to use um index and index on some values called the spring one dot customer which is here a string dot spring customer is a java a java class that doesn't implement serializable because it's not necessary since it's going to be it's going to be serialized with protobuf with protostream in protobuf value and using these annotations of protofactory and protofield the protoschema has been created i have another meta annotations here that relates to indexing indexing and i will show you that after in a minute uh what this is for [Music] i have also an enumeration of the cd because the customer i'm setting a cd so i can i can tag those to be marshalled with protonium value annotation and then i will create with an interface extending generated schema where i will say a spring one is the package and these are the included classes with all this protostream has created an schema [Music] so i'm just going to [Music] try the http localhost 8080 customers last one just to check what it does this has taken me the sara talbot one and i'm gonna check what happened in infinite span so a cache has been created automatically for me and i have an estimate here as well so this proto schema has been created and i uploaded this schema from my springboot application and this has been done with the infinispam protostream library as you see here with some comments for metadata metadata for the indexing and here i have the customer cache where i can convert to json my my object without any trouble so my comp the configuration of the cache it's protostream and here i have some metrics as well i'm just gonna um heat the cache a little here with um so and this is going to create more more data and i'm going to just explain how this cache was created as well with the infinite span spring boot starter um in the configuration here i can say uh with remote the remote api over here get the xml configuration and this cache will be created on first access if it doesn't exist this is important since by default the marshaller used by a springboard application is the java marshaller so if we want to use protobuf we need to tell that this cache is using protostream instead this is for backwards compatibility and this is for the schema um we need to tell also which how the schema the schema generated the schema has has to be worked this here and also the schema blog over here it's a little code to blow the schema that has been generated this is something we will add with a property to be done automatically for yourself in the next version of the spring water starter but now i'm using version 12 this will be in version 13. so just i'm just showing some small small usability api stuff that we are working on that will be completely transparent for you don't need to do it yourself if you don't want to do that um yourself with an api so um now if i come back here to my i have 40 entries and this cash is a it's an indexed which means that i can perform full text queries so i will show you how thanks to the spring spring uh sorry the protobuf integration we can perform queries like this and this is uh as i said a complete a javascript application is not that java application and we can um get just an order by age so we see we have some customers that have 109 years old and yeah they are triggered like this we can sort it like that we can also run this query over here oops i oh i yeah obviously i have a i have an issue on my on my so here so okay i don't know why this is the demo effect i've run this like a million times i don't know why it's not working now i'm so disappointed right okay now it's working sorry something happened on my on my console so here we have uh only the uh the seven entries the seven values with the age 35 to 50. over here seven and i can't run as well i hope this uh query yeah that i have i haven't any value here this was this was a good i would a good a good result because i don't have any any customer which whose name is len but i can try to find one similar so i have here ben valentin so um this is what i i i saw this is the the how query works sorry i'm a bit nervous now so i'm just going to show you how the new york integ in new york cross-site replication might work over here so first um first i'm gonna show you how uh here if i try to find the uh it doesn't it doesn't exist the customer 1000 doesn't exist i have another customer here 1000 doesn't exist and it's since i said i want to cash everything it has been cash the null value has been it's on the cash as well so we see here that the type of the key 1000 is null value so now what i'm gonna try here is to just replace that null null value over here so um i don't need to use as i said i don't need to use the java api or or anything to create the proto schema i can use the rest api so the console in this way and this is how i'm gonna do it here in the new york protest schema so first i created the schema here as well and now i'm gonna create a cache that it's called customers as well and i will create this cache with this configuration here where uh the uh the marceline is protostream as well and the backup uh cache is in london so i create this and there is nothing here and now i'm gonna add an entry with key 1000 and i'm gonna get um adjacent over here to place it this way so it's a type and there's four type stream one customer and i'm gonna change the name and here as well the id and so if if i add this now here in london i should be seeing yeah spring one customer 1000 the copy has been done from new york to um to the london side and now i don't have a new value anymore so if i go here to my springboot application that it's using the the rest api over here that i show you just at the beginning now we have a spring one new york so i'm [Music] i'm done with the demo part so that's that's all that's all i i have for today thank you very much i hope you you enjoyed this presentation where at the beginning i didn't know if we were you were seeing stuff as it should be seen i was a bit this yeah sorry a bit nervous and i have some links here of the infinixban documentation we've built a very nice demo as well with infinispam and yeah with a competitor but there is a very nice video where you can do the same thing with springboot and infinispam we had a global ranking of players um using infinite span and and querying and sorting and we were able to to have three different clusters deployed and all the data getting copied around and having a global ranking of players in an online game we developed so that's something really cool that can be done with a spring booth springboot caches and infinite span as well so going beyond the use case of just getting behind your cast abstraction and you can also imagine that maybe you are going to use maybe not a springboard but another but not js for another another another use case and you need to grab some data so the integration with protobuf is is really good and really cool so that's that's all for me um we can go to the q a i think i finished on time hey uh thanks katya that that talk was great this is your domain and i loved your confidence it was so great to have you on and for our audience if you have more questions about infispan or and or protobuf and our spring caches please follow catia to the postdoc zoom that will be up shortly a reminder that q a will continue on slag for a bit later too all right with that that's actually the end of my shift as an emcee your next talks are starts at 205 pm eastern and you'll meet my colleague jimmy chunga who will be the mc for the next set of talks enjoy the rest of spring one we're so glad you came this is aditya over and out
Info
Channel: SpringDeveloper
Views: 608
Rating: 4.6363635 out of 5
Keywords: Data/Databases
Id: KvRrgK-_wQo
Channel Id: undefined
Length: 26min 9sec (1569 seconds)
Published: Wed Sep 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.