CQRS Design Pattern in Microservices Architecture | How to implement CQRS in Microservices | csharp

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey buddy so cqrs in microservices now when you create an application you always prefer that you know I will go with one database right most of the time it is rdbms because it store all the complex joints and we yes you know when we create database when we create application we think of you know normalization right so all those parameter and we choose this is my sequel or this is my Oracle database which is going to take care of my application this concept was without cqrs when you want to implement cqs in your project in your microservices over here don't confuse yourself with you know secure as your simple Secrets design pattern because you know that is about something about C sharp the core concept is same here that command and query but this is on bigger part over here you know this principle talk about not just single database this principle says that you know divide the responsibility of command which is right operation and query which is read operation and not just the operation but to the database level create two database Yes you heard it right create two separate database one database will take care of all the right operation through command that is insert update delete but on the other side the second database will take care of only and only read operation right so divide the responsibility into two different database now you know how we will decide the next question is how we will decide that you know for right database what sort of database we should use whether it's SQL no SQL right and same for read database so when it is the right database we should always choose rdbms because when you wanted to write something you will store the data in different tables right to different foreign keys right all sort of keys so the storing is always complex into multiple tables so go for rdbms now when you wanted to read the data you always need a fast you don't want your client to wait for a long time on the screen right so you want the performance over here you will go with no SQL because no SQL for sure they have the higher performance right so over here you can go for you know a mongodb cosmo DB or zero search search all those options are available there now if you look at this diagram this is the same thing I said over here you come they make changes on the UI let's say he operated the information from the the last name was Parveen he made that to yadav right now that will go through command and make the changes in the right database next step is he wanted to read the information for all the salaries for all the employees now that time this will not go to right database it needs to fetch the record so it will go to read database right and it will display the data so that is the cqrs on different database level you know what if I ask you that yes you have used sequence before you must be surprised right but yes most of us have used Seekers before whether you know that or not so you know you remember sometime in our application in our database level though we use just one database but directly indirectly we you know use the same strategy of cqs we go and we create views we know that you know we have complex joints and that will make my system quite slow and in that case we create views right so view does the same thing right so instead of going into the real tables you create one view table and you make all the select queries from there and all the right operations into real table right so if you look at this diagram it's like similar what I've shown before but over here if you see this says that you know right database is what tables and read database is what materialize view so yes my friend you have used it before right if you have worked with the view you have used that before so over here though the database is one see they are talking about tables it says right database but here we are saying tables it is saying every database but over here we are saying it's materialized view so we have used it okay okay now you know the bigger problem in maintaining these two database now you must be thinking how we will you know keep the synchronization with these two database if I have updated you know the salary of the employee into the right database how the at the same time read database get all those records right so we can use multiple strategy right what we can use we can use some sort of messaging system whether it could be event was it could be Azure service bars or any messaging system right so whenever you know there is any record if you look at this diagram any record in the right database it will push those record to event bus and event bus will take to you know update the read database as well right so within milliseconds whenever some information received in the right database within millisecond all these operations are performed and they are ready to give the updated information back to query back to UI right now you know sometimes time people think that what's the benefit if I have to store the same information in right database and same information in the read database then we are duplicating buddy no you know what in the right database we know we are going to store you know data in multiple tables let's say person table employee table right now employee would have designations employee would have Service employee would have department so we have understood a lot of foreign keys but read is no SQL database we are not going to store all the foreign keys only record which needs to send back to the UI let's say we just wanted to send in a person first name last name Person age person gender and person title and Department we don't want to expose a salary and foreign keys to know UI right so what we will do only those required information that needs sent back to UI we will store that in the read database not any other information and that is how we are making very fast to our re-database because we don't need to put any joints making a query we will just say you know give me this information and that information is just ready right and sent back to the UI that is how it is fast now if you look at this diagram over here you will see this is particular for microservices right so we have two application yeah the application is different but for same purpose one is web UI second is mobile UI right we wanted to perform some operation it will go to API Gateway for sure you know API Gateway is the best practices right as we talked in this video so you know according to the request for sure it will go to different microservices right but over here you will see that your API writing some data into right database which is SQL that means rdbms right and this cost API the job of cost API just to read data right and that is reading data from a read database now over here we have some you know strategy some event bus system which is you know syncing data between these two database SQL and nosql right now C chorus Works in microservices okay so that's all for today video I will see you in the next video
Info
Channel: CodeWith { Parveen Yadav }
Views: 2,385
Rating: undefined out of 5
Keywords: csharp, dotnet, microservices
Id: tLr_CdKc3XU
Channel Id: undefined
Length: 8min 0sec (480 seconds)
Published: Wed Jul 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.