Nest.js Microservices with NATS, SQL, and Docker

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 37

  • @bugraotken
    @bugraotken 10 месяцев назад +6

    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!

  • @somerandomchannel382
    @somerandomchannel382 10 месяцев назад +8

    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.

  • @serling3927
    @serling3927 4 месяца назад +3

    Legend with the docker hot-reload.

  • @mykolatokariev8260
    @mykolatokariev8260 8 месяцев назад

    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.

  • @0xVantwoutMaarten
    @0xVantwoutMaarten 4 месяца назад

    Anson this is awesome! Really enjoying this one!

  • @notabotlul
    @notabotlul 10 месяцев назад +1

    thanks for this tutorial man, I really appreciate it

  • @jagajaga6908
    @jagajaga6908 6 месяцев назад

    Hello Anson! Thank you for such an amazing lesson, I really appreciate your work!

    • @ansonthedev
      @ansonthedev  6 месяцев назад

      Thank you very much. I appreciate the kind words!

  • @ashernoa23
    @ashernoa23 9 месяцев назад

    This is pure gold. Thank you!

  • @andrejkling3886
    @andrejkling3886 7 месяцев назад +1

    I love sqlzzz too 🔥💯 thank you so very much Anson for cool tutorial…🎉 very excited. We are waiting for cool project 🔥🔥🔥💯

  • @oleksiishkulipa1626
    @oleksiishkulipa1626 5 месяцев назад +2

    what the difference between RabbitMQ & NATS ? when do you recommend pick NUTS or RabbitMQ ? thank you

  • @overrevvv
    @overrevvv 9 месяцев назад

    Thank you so much for this insightful video.

  • @AmarjargalB
    @AmarjargalB 3 месяца назад

    nice2 🤓 super easy to understand. Thank you.🤗.

  • @PatalJunior
    @PatalJunior 9 месяцев назад

    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)

  • @PatalJunior
    @PatalJunior 9 месяцев назад

    I think for the mysql probably the best thing would be to create a docker network instead of exposing ports

  • @mkopoku
    @mkopoku 7 месяцев назад

    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  7 месяцев назад

      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

  • @oyinlolaolasunkanmi
    @oyinlolaolasunkanmi 4 месяца назад

    Awesome, thanks

  • @MuradRashidov-k1j
    @MuradRashidov-k1j 4 месяца назад

    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?

  • @AlAminChayan-r2s
    @AlAminChayan-r2s 8 месяцев назад

    Thanks for the nice tutorial. Your editor's font looks awesome. Would you mind to share the font name :)

  • @silviudinca6501
    @silviudinca6501 Месяц назад

    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  Месяц назад +1

      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 Месяц назад

      @@ansonthedev thank u for your answer.

  • @mykolatokariev8260
    @mykolatokariev8260 7 месяцев назад

    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  7 месяцев назад

      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 10 месяцев назад

    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  10 месяцев назад +2

      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 10 месяцев назад +1

      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  10 месяцев назад +1

      You're welcome & thank you!

  • @ObulRakhim
    @ObulRakhim 8 месяцев назад

    nestjs microservice "exception filters" code structure ??

  • @ObulRakhim
    @ObulRakhim 8 месяцев назад

    You forgot to specify how to install Exception filters in miceoservice. please give me a manual too

  • @mykolatokariev8260
    @mykolatokariev8260 7 месяцев назад

    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  7 месяцев назад +1

      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 9 дней назад

      Check verdaccio, self Host npm repository