
Explore building a two-microservice app for rider tracking: a logging service saving rider coordinates in mongodb via endpoints and a rider service for login and details, with tcp-based inter-service communication.
Explore setting up a NestJS microservices project, compare standard mode and monorepo workspaces, and convert from standard to monorepo using the Nest CLI to share code across services.
Implement the logging service with a separate database per microservice, using MongoDB for the logging service. Install MongoDB via local server or Docker and start the server on port 27017.
Docker streamlines local development for multi-service architectures by provisioning databases and tools with a single docker compose file, enabling one-command setup of MongoDB, Elasticsearch, Redis, Postgres, and more.
Learn to run MongoDB in a Docker container using the official image, manage containers, and introduce Docker Compose for multi-service setups.
Connect a logging service to MongoDB using mongoose with NestJS. Install mongoose and nestjs/mongoose, configure the dynamic mongoose module, and run the service with docker-compose and npm start.
Diagnose and fix database connection issues by configuring docker port forwarding to map MongoDB port 27017, restart containers, and verify the connection with MongoDB Compass.
Refactor the logging service and build a new rider coordinates module in NestJS, creating a rider coordinates controller, service, and module; test the get endpoint with a REST client.
Define the first mongoose schema to store rider coordinates (latitude, longitude, riderId) in MongoDB and create the model in a new schemas folder.
Define the writer coordinate schema using NestJS Mongoose, create a hydrated document type, and generate a schema with property decorators, required fields, and options like unique and index.
Explore how a schema class exposes its properties and constructor, and how the Mongo schema returns the class and its instance under the hood.
Validate the post request body with class-validator to verify longitude, latitude, and writer id from the Android app every three hours, and validate arrays, sets, maps, and nested objects.
Install class-transformer and class-validator, define validation rules, and create a post endpoint for safe rider coordinates using a create rider coordinates DTO, with the body decorator in NestJS.
Create a coordinates dto with longitude and latitude as numbers and writer as a non empty string, and apply class-validator decorators in a dto folder to validate the request body.
Validate rider coordinate requests in a NestJS microservice using the class validator package and a global validation pipe. Ensure latitude, longitude, and writer fields are required and correctly typed.
Save coordinates by integrating the Ryder coordinates model into a NestJS coordinate service, leveraging mongoose methods for create, update, and delete via a feature module.
Learn to implement save coordinates in a nestjs service by wiring the writer coordinate model with mongoose, exporting/importing the schema, and using a create coordinate DTO with dependency injection.
Test the rest http method to create the rider coordinate, address internal server error during command insert, and enforce required authentication.
Resolve mongo connection issues by applying the correct docker compose credentials and admin auth, then save latitude and longitude into the writer coordinates collection with NestJS mongoose.
Implement the get coordinates method in the writer coordinates controller to fetch coordinates via the writer coordinates model's find method, and fetch rider details from the rider microservice via RabbitMQ.
Explore API communication between microservices, contrasting synchronous HTTP request–response with asynchronous TCP and brokers like RabbitMQ and Kafka, and see a TCP-based example for rider coordinates by id.
Refactor the service to rider, launch a rider app on port 3001, and implement a mock get rider by id endpoint returning a sample rider object via a prams decorator.
Define event-driven communication between NestJS microservices by wiring a rider microservice via a TCP-based client proxy to call get rider by id and enrich coordinates with writer details.
Learn to register a message pattern and consume cross-microservice events in NestJS using a producer–consumer model, injecting the rider service as a provider to fetch rider details.
Diagnose and fix NestJS microservice startup issues using try and catch and enhanced logs to reveal default port problems, Ryder coordinates, and TCP-based communication.
Resolve an internal server error by validating rider details and testing get rider by id via the rider controller and client send, while logging the rider data and coordinates.
Test copying the rider observable to verify if missing the first value causes the persistent issue.
Speed up NestJS app reload time by integrating a rust-based SWC compiler and a webpack config for a monorepo. Run the microservices faster with docker and batch mode SWC builds.
Explore rabbitmq, an open source message broker, enabling reliable delivery between microservices via queues, routing keys, and acknowledgements. Learn producer, consumer, exchange, binding, queue, and routing key.
Demonstrate RabbitMQ flow in a NestJS microservice: a writer producer sends a command to the default exchange, routing it to the writer queue for the writer controller to consume.
Install and run RabbitMQ as a Docker Compose service using the official image, then access the GUI at localhost to manage queues, exchanges, and channels.
Configure RabbitMQ in a NestJS microservice by installing amqp dependencies, connecting through Docker, defining a rider queue, and updating producer and consumer to use RabbitMQ context and payload.
Update the rider coordinates microservice to use rabbitmq for inter-service communication, configuring host, queue, and routing with the client proxy send; test end-to-end with updates and data flow.
Learn to connect the rider microservice to Postgres using TypeORM in NestJS and fetch rider details from the database.
Connect the writer microservice to Postgres by adding a Postgres service in docker compose, configure environment variables, and persist data with volumes across restarts.
Refactor the rider microservice by adding a root app module for typeorm with Postgres, injecting rider entities via a dynamic module, and enabling auto loading of entities and schema synchronization.
Import the app module to connect the rider microservice with Postgres and run in watch mode; logs confirm Postgres connection while each launch auto-creates new tables in development only.
Enable auto load entities in TypeORM to register writer and rider. Define writer entity with a primary generated column, first name, last name, email, active status, and enable schema synchronization.
Implement a rider service method to find a rider by id using a TypeORM repository, injecting the rider entity, and returning the rider or null asynchronously.
Create a rider via a post route with a create rider DTO, saving in the repository, returning rider details, and using the rider ID to call the rider coordinates service.
Explore testing rabbitmq-based communication between NestJS microservices and databases, and bridging http requests via an api gateway. See how a rider microservice interacts with Postgres and MongoDB to fetch coordinates.
Establish a single API gateway as the entry point, routing requests to product, order, and payment services, while centralizing authentication and applying rate limiting.
Explore how the API gateway centralizes client routes, enforces authentication and rate limiting, and routes requests via RabbitMQ to microservices on ports 4001 and 4002.
Delete the Uber services, remove them from the CLI, and replace them with an API gateway as the route project, wrapping all usage around the new gateway.
Create an api gateway for NestJS microservices on port 3000 to enable http based communication and route rider details from the rider microservice for mobile apps.
Define routes in the api gateway for the rider microservice, including a post route to create a rider and a get route by id, and outline rider controller methods.
Send the get dash Ryder command to the rider microservice using NestJS microservices' send method via tcp or rabbitmq, then test the http route /riders with docker compose.
Define and test the create rider data flow in the api gateway using a create rider dto and a command structure, replacing http-based communication with app-based messaging.
Define logging microservice communication by implementing a rider coordinates microservice in the api gateway using rabbitmq queues, routes, and message patterns, converting main.ts to a microservice setup.
Configure microservices transport and queue, send create and get writer coordinates with an ID through the api gateway, and test rider coordinates endpoints on localhost:3000.
fixing bug demonstrates using payloads instead of frames, parsing string ids to numbers, and enabling two-way communication via an api gateway, logging microservice, and rider microservice, with proper dependencies.
Build an authentication microservice using Postgres with Prisma ORM, communicate via RabbitMQ through the API gateway, and implement a JWT authentication flow for signup, login, and protected profile access.
Create an authentication microservice for a NestJS microservices stack, converting the HTTP-based setup to a microservice with docker compose, using auth and writer queues, and running in watch mode.
Install authentication dependencies for the microservice by adding Prisma client, Nest JWT, Nest passport, passport and passport JWT, then run npm install.
Define routes for authentication in NestJS microservices. The API gateway forwards login and sign-up requests to the authentication service and sets up routes for register, login, and profile.
Define and connect an authentication service in the api gateway using rabbitmq transport to support register, login, and validate token commands. Inject this service into the gateway controller.
Define the signup route by implementing the register method in the authentication controller, using Prisma to access the database, and wiring the API gateway to trigger the register command.
Verify api gateway and auth microservice communication by sending a register request and confirm data return, then prepare to save user details with Prisma ORM to Postgres.
Set up Prisma in the authentication microservice with npx prisma init, create the prisma folder and dot env file, define schema.prisma for Postgres, and run npx prisma generate.
Configure the postgres connection string in dot env for Prisma, place models in schema.prisma, and map docker ports (44543 to 5432) for the localhost postgres database with public schema.
Define a Prisma user model in a schema file, mapping to a Postgres table with a unique auto-incrementing id, an email, and a password; convert to a class for CRUD.
Create and register a Prisma service in the authentication module to expose user CRUD via the Prisma client and connect to Postgres.
Define a Prisma model in schema.prisma, including id, email, and password, and let the Prisma service perform CRUD operations to create users in the users table.
Save a new user in authentication microservice by generating the user class with Prisma generate, hashing the password with bcrypt, creating the user via Prisma client, and returning the email.
Execute a test signup by sending a register request to create a new user, verify the response email, and confirm the user in a Postgres database via Prisma migrations.
Implement the login feature using JSON web token to access protected routes, validate users by email and password with bcrypt, and generate a JWT via a configured JWT service.
Implement a protected profile route in NestJS using an authorization guard that validates and decrypts the token from the authorization header to obtain request.user.id and email.
Create an authorization guard in NestJS, generate the guard, implement header-based login validation, and return true to proceed or an error to deny access to protected routes.
Fixes a prisma client error caused by missing auth data in docker compose by creating separate postgres volumes for auth and rider databases, and running prisma migrate to sync models.
Test the signup route with varied users, create a user, log in, and obtain the token to confirm access works and the issue is fixed.
Implement an auth guard in the API gateway to extract auth header, validate token with the auth service, attach user id and email to request.user, and gate profile access.
Implement token validation by routing the validate token command from the api gateway to the authentication service, where jwt verify decrypts the token and returns a boolean and user data.
Test auth guard by logging in to obtain a token and access a protected route via API gateway, logging the token and user data from the authentication microservice over RabbitMQ.
NestJS is one of the best frameworks for modern backend development. It combines the best features of Angular, Express, and TypeScript, making it a go-to choice for building scalable, maintainable, and production-ready applications.
Are you struggling to build scalable, production-ready microservices with NestJS? Do you want to master RabbitMQ, MongoDB, Postgres Docker, Prisma, and API Gateways while learning real-world best practices? This course is for you!
In this comprehensive NestJS Microservices course, you’ll learn to build a fully functional microservices architecture from scratch. You’ll master inter-service communication, authentication, database integrations, and deployment – all with hands-on projects and practical coding exercises.
What You'll Learn:
Setup a Scalable NestJS Microservices Project from scratch
Implement TCP, RabbitMQ, and API Gateway-based communication
Secure microservices with JWT authentication and NestJS Guards
Work with MongoDB, PostgreSQL, Prisma, and TypeORM
Containerize microservices with Docker & Docker Compose
Why Take This Course?
Hands-on projects – Code alongside real-world applications
Step-by-step explanations – No prior microservices experience neede
Updated for 2024 – Covers the latest NestJS & microservices patterns
If you’re ready to master NestJS Microservices and become a job-ready backend developer, enroll now and start coding!
NestJS microservices offer several benefits, especially for building scalable and maintainable backend applications.
1. Scalability
Microservices allow independent scaling of different services based on demand.
NestJS supports distributed systems, enabling horizontal scaling.
2. Decoupled Architecture
Each microservice is independent, making it easier to modify, deploy, and maintain.
Services can be developed, tested, and deployed separately.
3. Built-in Transport Layer Support
Supports various transport layers like Redis, RabbitMQ, NATS, Kafka, MQTT, gRPC, and more.
Enables event-driven communication, improving performance and resilience.
4. High Performance
Efficient handling of requests through asynchronous communication.
Reduces load on individual services by distributing workloads.
5. Improved Fault Tolerance
If one microservice fails, others continue working, reducing the impact on the system.
Supports circuit breakers and retries to handle failures effectively.
6. Technology Agnostic
Each microservice can use different technologies or programming languages.
NestJS allows seamless integration with external APIs and services.
7. Better Team Productivity
Different teams can work on separate microservices without dependency bottlenecks.
Faster development cycles due to modular architecture.
8. Enhanced Maintainability
Clear separation of concerns makes debugging and updating code easier.
Smaller, well-defined services reduce technical debt.
9. Security and Isolation
Each service has its own security boundaries, reducing the impact of vulnerabilities.
Allows implementation of zero-trust security models at the service level.
10. Support for Domain-Driven Design (DDD)
Helps structure services based on business logic and domain requirements.
Encourages clean and maintainable architecture.