Nest.js Microservices with NATS, SQL, and Docker

  Рет қаралды 16,530

Anson the Developer

Anson the Developer

Күн бұрын

Пікірлер: 41
@somerandomchannel382
@somerandomchannel382 Жыл бұрын
00:02 Microservices divide work into multiple processes. 02:28 Microservice architecture can vary based on business needs and scalability. 07:21 Sharing a single database for all microservices to simplify 10:02 Install NestJS microservices and NATS packages for setting up microservices and delivering messages 14:47 Setting up Docker and Docker ignore file for a Node.js project 17:05 Setting up other microservices in development mode 21:27 Setting up Nats protocol and Docker compose for microservices. 23:31 Exposing ports and setting up volume for hot reload 27:44 Configuring microservices to connect to Nats server and update via Docker 29:38 Services can connect to the NATS server using the service name as the host name in Docker. 34:05 Setting up communication between API Gateway and user microservice 36:11 Setting up user module and controller in Nest.js for microservice architecture 40:54 Fixing dependency resolution issue in Nest.js application 43:16 Creating a data transfer object (DTO) for user payload 48:03 Setting validation rules for request body in Nest.js 50:10 Sending validated request body to users microservice using NATS 54:24 Using the @Controller decorator and subscribing to events in Nest.js Microservices 56:41 Using Nest.js microservices with NATS and SQL 1:01:05 Understanding how to subscribe to an observable and return values in Nest.js 1:03:04 Creating a new payments module and controller in the API Gateway project. 1:07:02 Comparing event-based approach with request-response message style. 1:09:07 Setting up a payments module and controller for the microservice 1:13:18 Annotations and validations in microservices 1:15:16 Communicating between microservices using NATS and TCP connection 1:19:22 Setting up NATS for emitting and receiving events 1:21:18 Demonstration of microservices communication and event handling 1:25:10 Configuring SQL Server and connecting to database 1:27:26 Installing RM and database driver for SQL interaction 1:31:46 Setting up TypeORM entities for creating database tables 1:33:48 Setting up user entity with decorators and TypeORM module 1:38:44 Registering user service and entity in Nest.js module 1:40:59 Creating and saving user data to the database 1:45:15 Create and share entities as npm packages for reusability 1:47:24 Creating a payments service and interacting with payments table 1:51:35 Nest.js allows creating asynchronous microservices that don't depend on each other. 1:53:38 Establishing one-to-many relationship between users and payments entities in Nest.js Microservices 1:57:27 Registering user and payment entities in Nest.js app module and microservice project 1:59:52 Adding user ID as a requirement for creating payments 2:03:56 Destructuring and handling fields from the create payment DTO and interacting with the users microservice. 2:06:12 Using Nest.js to grab user data from the database and send messages to user microservice. 2:10:21 Logging and creating payment in sequential order 2:12:24 Logging and handling of user events in microservices 2:16:34 Using relations to grab all payments of a user from a shared database. 2:18:39 Implementing microservice architecture with Nest.js, NATS, SQL, and Docker. Crafted by Merlin AI.
@bugraotken
@bugraotken Жыл бұрын
It's very nice to see a dedicated Nest.js youtube channel even for a frontend developer like me =) thank you Anson for these precious videos about Nest.js!
@ansonthedev
@ansonthedev Жыл бұрын
Thank you! :)
@mykolatokariev
@mykolatokariev 11 ай бұрын
Very nice explanation. The schema at the beginning was very helpful. Before watching this video, I had also created a similar architecture, but I wasn't aware of microservices in NestJS, so I used sockets for asynchronous communication.
@serling3927
@serling3927 7 ай бұрын
Legend with the docker hot-reload.
@0xVantwoutMaarten
@0xVantwoutMaarten 7 ай бұрын
Anson this is awesome! Really enjoying this one!
@notabotlul
@notabotlul Жыл бұрын
thanks for this tutorial man, I really appreciate it
@ashernoa23
@ashernoa23 Жыл бұрын
This is pure gold. Thank you!
@jagajaga6908
@jagajaga6908 9 ай бұрын
Hello Anson! Thank you for such an amazing lesson, I really appreciate your work!
@ansonthedev
@ansonthedev 9 ай бұрын
Thank you very much. I appreciate the kind words!
@raudelgomezsmith4787
@raudelgomezsmith4787 Ай бұрын
Wow you are amazing. You explain like GOD. I was looking for a complete and exhausting explanation, and I got it. 😊😊♥♥ Could you make a video of a microservice auth with passport method in Nest Js and Reddis please??
@Mahadev-x7u
@Mahadev-x7u 10 ай бұрын
I love sqlzzz too 🔥💯 thank you so very much Anson for cool tutorial…🎉 very excited. We are waiting for cool project 🔥🔥🔥💯
@oleksii.shkulipa
@oleksii.shkulipa 8 ай бұрын
what the difference between RabbitMQ & NATS ? when do you recommend pick NUTS or RabbitMQ ? thank you
@jackw4150
@jackw4150 2 ай бұрын
can you show us how to have multiple Dockerfile, and how can we configure each for different environment ? and how can I set my nats port to different port ?
@PatalJunior
@PatalJunior Жыл бұрын
I think for the mysql probably the best thing would be to create a docker network instead of exposing ports
@overrevvv
@overrevvv Жыл бұрын
Thank you so much for this insightful video.
@ansonthedev
@ansonthedev Жыл бұрын
You're welcome!
@AmarjargalB
@AmarjargalB 6 ай бұрын
nice2 🤓 super easy to understand. Thank you.🤗.
@PatalJunior
@PatalJunior Жыл бұрын
I'm curious how scaling works with micro-services, how do you keep the data synced if you are horizontally scaling ? MySQL replication with K8s, would that be it ? (If not all of them are connecting to the same database, sure this is probably really overkill, I'm just curious)
@silviudinca6501
@silviudinca6501 4 ай бұрын
Totally a well structured and good quality of informations. But i dont understand why u can have both entities in both projects and also connecting to the same database. What happens if u add a field lets say currency: string only to the Payments.ts in Payments microservice. Which one will Typeorm choose to sync in the db. The one with the field currency or the other one ?
@ansonthedev
@ansonthedev 4 ай бұрын
You need to make sure both entities in both projects are parallel to each other. In other words, they have to have the same fields at all times. Otherwise, the micro service without the up to date entity will not have access to all possible fields from the record in the database. For a personal project or a small project with a few developers, it’s fine to have both entities in both projects and tracking when a change needs to be made to the entity. For a larger project with multiple teams, you’d want to move the entities to a downloadable npm module that can be used across all teams in the organization.
@silviudinca6501
@silviudinca6501 4 ай бұрын
@@ansonthedev thank u for your answer.
@AlAminChayan-r2s
@AlAminChayan-r2s 11 ай бұрын
Thanks for the nice tutorial. Your editor's font looks awesome. Would you mind to share the font name :)
@MuradRashidov-k1j
@MuradRashidov-k1j 7 ай бұрын
Very useful tutorial and excellent explanation, I did same with postgres, everything work fine, but nestjs_db doesn't appear on pgAdmin, is it normal?
@ObulRakhim
@ObulRakhim 11 ай бұрын
nestjs microservice "exception filters" code structure ??
@mkopoku
@mkopoku 10 ай бұрын
Awesome tutorial! Quick question...do the DTO's have to be classes or will the validation annotations still work even if they are represented as a TypeScript interface instead?
@ansonthedev
@ansonthedev 10 ай бұрын
You can use an interface, but the NestJS docs suggests you to use a class because TS will not store metadata for interfaces or generics which will result to the ValidationPipe not properly validating the data. You can read more here: docs.nestjs.com/techniques/validation
@od1ez
@od1ez 15 күн бұрын
Hello, what theme is it?
@mykolatokariev
@mykolatokariev 10 ай бұрын
Hey, Anson, how do I send some data to the API gateway from microservice correctly? It seams that NATS is not the best way to send the data.
@ansonthedev
@ansonthedev 10 ай бұрын
The API Gateway is a hybrid application so it can handle HTTP requests as well as other TCP requests via NATS. You can have the gateway also listen to an event that comes from any of the microservices.
@blaiseendizeye
@blaiseendizeye Жыл бұрын
Thank you very much for this video. I have a small question. I'm new in microservice world. Suppose i want to setup authentication or authorization through this way of Nats, will i have to do it on the http api gateway or to something else like other microservice? Best regards 🙏
@ansonthedev
@ansonthedev Жыл бұрын
You would do it on the API Gateway since that is your entry point to the application. The next question is "How do I protect my microservices"? The easiest thing to do is to put your microservices inside a Virtual Private Cloud with the API Gateway, with only the API gateway exposing itself to HTTP to incoming connections, while all the microservices sit in the VPC and can only receive connections from the API Gateway. This alone would be viable enough to protect the microservices from receiving HTTP requests. At the HTTP API layer, you'd just handle the authentication check on the user, whether you're using sessions or JWTs. If the request is made by someone with the valid permissions, then send the message to the NATS server or whatever you use. Of course, you could do additional things such as encrypt everything before sending it, too.
@blaiseendizeye
@blaiseendizeye Жыл бұрын
That's handful masterpiece of information. Thank you very much I really appreciate the hard work you put in these videos, they are invaluable to all fellow NestJS developers. I can't wait to implement all of that architecture in my next project. Wish you all the best 🙏. I'm looking forward to all other videos you share on this channel!
@ansonthedev
@ansonthedev Жыл бұрын
You're welcome & thank you!
@ObulRakhim
@ObulRakhim 11 ай бұрын
You forgot to specify how to install Exception filters in miceoservice. please give me a manual too
@oyinlolaolasunkanmi
@oyinlolaolasunkanmi 7 ай бұрын
Awesome, thanks
@mykolatokariev
@mykolatokariev 11 ай бұрын
Nice video. Btw. do you know how to avoid a duplication of the DTOs in the http-api-gateway and in the microservices?
@ansonthedev
@ansonthedev 10 ай бұрын
One thing you can do is create a module that has all of your exports, such as DTOs, enums, etc. that are shared between different projects, and then upload it to the npm registry and you can download it as a regular node package. If you have a company or want to keep it private, npm does have paid plans that allow you to host modules privately.
@chambaderaphael8946
@chambaderaphael8946 3 ай бұрын
Check verdaccio, self Host npm repository
NestJS Interceptors
24:05
Anson the Developer
Рет қаралды 7 М.
NestJS, MySQL, TypeORM Crash Course
1:17:38
Anson the Developer
Рет қаралды 106 М.
Learn Docker in 1 Hour | Full Docker Course for Beginners
1:27:53
JavaScript Mastery
Рет қаралды 461 М.
The Right way to write Nest.js & Typescript clean-code - SOLID
17:55
NestJs Microservices with RabbitMQ
23:21
Computerix
Рет қаралды 19 М.
Build Nest.js Microservices With RabbitMQ, MongoDB & Docker | Tutorial
1:24:40
Docker с 0 до 100%. Всё, что нужно знать.
5:08:24
How to Dockerize a MERN App | Docker Compose
44:00
Nikita Dev
Рет қаралды 8 М.
Decouple your NestJS code with this technique!
11:37
Marius Espejo
Рет қаралды 43 М.
Microservices with Databases can be challenging...
20:52
Software Developer Diaries
Рет қаралды 125 М.