NestJS materials

Write an awesome doc for NestJS tips, tricks, notes, things which are not in the doc (or are but not really obvious) and experimented to figure them out and use them.

View on GitHub

Microservices

Here I’ll try to examine and put into practice microservices.

Its concept

Microservices are small programs, each with a specific and narrow scope, that are glued together to produce what appears from the outside to be one coherent web application.

Network protocols

Name Description
HTTP/HTTPS Each microservice exposes endpoints that other services can call to request or manipulate data. Synchronous request/response-based.
gRPC Allows services to call methods or procedures on remote services as if they were local. High-performance communication using protocol buffers and HTTP/2.
TCP Reliable, connection-oriented communication channel between microservices. Useful for when you’re communicating within docker network or microservices cluster.

@MessagePattern Versus @EventPattern

  @MessagePattern @EventPattern
AKA Request-response pattern. Event-based pattern.
Upsides Simple to work with, and easy to debug. Register multiple event handlers for the same event (they will all fire in parallel). Asynchronous by default, the connection after sending the request is closed immediately. Thus more flexibility, as they offer the opportunity to create complex architectures that scale more easily and are highly responsive.
Downsides Connection to the other service being locked until it sends back a response(Potential time out errors). Harder time to debug issues.

Messaging mechanisms

Name Description
Messaging Queues Asynchronously communication through RabbitMQ, Apache Kafka, or Amazon SQS. Decouples communication. Supports event-driven architectures.
Event Streaming Services produce and consume events. Real-time communication and data processing. Useful for when we need to process events asynchronously and distribute them across multiple services.
NATS An infrastructure that allows data exchange, segmented in the form of messages. It is a messaging system. Designed for building distributed systems & microservices architectures.

RabbitMQ

Kafka