Skip to main content

Moleculer Microservices Framework

Moleculer is a fast, powerful, and flexible microservices framework. Its core philosophy revolves around building applications by decomposing them into services. Each service is autonomous, allowing for independent deployment, scaling, and maintenance. Moleculer provides a lightweight messaging system, simplifying and optimizing communication between services.

Basic Architecture

The foundational architecture of Moleculer consists of several main components:

  • Services: This represents the cornerstone of the Moleculer architecture. Each service signifies an independent functional unit, deployable, scalable, and updatable in isolation.
  • Transporters: Responsible for conveying messages between various services or nodes. Moleculer supports numerous transport protocols such as NATS, MQTT, and AMQP, making it easily integrable into diverse environments.
  • Nodes: A node represents a computational instance running one or more services. Nodes communicate with each other through transporters.
  • Service Brokers: Service brokers offer a unified interface for each service, facilitating easy communication and interoperability.

Service Lifecycle

Within Moleculer, each service experiences its lifecycle, encompassing the following primary stages:

  • Creation: When a service initially starts up, it enters the creation phase. During this stage, the service initializes and prepares to process requests.
  • Start: Once the service is primed to accept requests, it transitions into the start phase. In this phase, the service can begin handling requests and responses.
  • Running: During the running phase, the service persistently processes requests until it's halted or restarted.
  • Stopping: When the service is no longer required to operate, it enters the stopping phase. Here, the service releases all resources and ceases to process new requests.

Nodes and Service Discovery

Moleculer employs dynamic service discovery to automatically detect and connect to other nodes and services on the network. Here are its key features:

  • Dynamic Discovery: As new nodes or services join the network, Moleculer automatically identifies and establishes connections with them.
  • Health Checks: Moleculer routinely inspects all nodes and services to ascertain their activeness and proper functioning.
  • Load Balancing: Moleculer adopts an in-built load balancing strategy to ensure requests are evenly distributed across all available service instances.
  • Failover: Should a service instance fail, Moleculer automatically redirects requests to other functioning instances, guaranteeing high availability.