Top 5 Cloud-Native Message Queues (MQs) with Node.js Support
Tags: node, cloudnative, beginners, tutorial
Published: 2022-09-13 12:53:12

Message queues (MQs) allow you to run distributed services. This article will go over MQs in further detail. Then Discuss the benefits cloud-native has to provide for your application and why we need it for MQs. Finally, highlight the top five cloud native MQs that can be easily run with Node.js.

### The Beginning: Synchronous

The application's scalability model is a tremendous consideration when rolling out your application. Take an example of a simple application using a [request-response](https://en.wikipedia.org/wiki/Request%E2%80%93response) model. You have three major components to facilitate your services: a client, a server, and the database to process your system data.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1gns6fjuad4fduwbxuu.png)

[Image Source](https://www.geeksforgeeks.org/state-the-core-components-of-an-http-response/)

Using this approach, once the client sends the request to the server, it has to wait for the processing to finish before getting back a response. However, this itself being a problem, it doesn't pose any technical processing problems to a simple application with just a few random users. Here you are running a synchronous model that your database can comfortably handle.

What if your system starts to get popular? Your server will start handling time-consuming tasks to fit the demand of the growing user base. Imagine your synchronous model handling these requests each at a time. Your client, in this case, cannot proceed with any other operations. Once you open the http connection, you cannot close the connection until you get a response from the server.

The client will have to wait longer for a response as the server receives more and more requests. You will end up with a backlog of requests. Even when the client expects a simple success message as the response, it has to wait for the first request to get processed, as requests get expected in the order they are received. By the fact that [53% of mobile users abandon sites](https://smartbear.com/blog/5-10-15-seconds-how-long-will-you-wait-for-a-web-p/) take over 3 seconds to respond, your system paradigm ends up creating a huge gap between user expectations and the application capabilities.

### Introducing Asynchronous

One of the best ways to solve this problem is to create an asynchronous communication model. An asynchronous model will execute that first request and the rest of any received requests simultaneously.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8rl05hqjbjcbentpkb5.png)

[Image Source](https://www.smashingmagazine.com/2017/03/simplify-android-networking-volley-http-library/)

The beauty of this approach is that when the client sends a request to the server, it doesn't have to wait for the server to get any response. It can actually go ahead and do some other operations. Here your application is running to its full potential with no limitations on what it can do at any given time.

### Getting a Message Queue: Asynchronous Approach

One of the best ways to achieve asynchronous communication is to use a message queue (MQ). A message queue enables the client to reduce the wait time for a task to finish and, as a result, execute other tasks during that time. Additionally, it allows a server to carry out tasks in the order it chooses.

Message queues are a service to service asynchronous communication used to build highly decoupled and reliable microservice applications. It allows one service to communicate with another service by sending messages to each other.

Message queuing uses a broker for centralized data management to ensure that the communication is delivered in a reliable fashion between the services.

This architecture uses messages as the data. The server, also known as the producer, creates the messages (the data) and sends them to the centralized message queuing manager (the broker). The client, also known as the consumer, retrieves the message from the queue and processes the data.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zp4ofczwfzsttkl9zuxa.png)

[Image Source](https://hevodata.com/learn/message-queues/)

This way, the producers can send any amount of data without worrying about consumer availability. The application can now manage multiple heavy scaling tasks using this microservice-based architecture. When the client requires data, it simply requests messages from the queue anytime.

### Node.js for Message Queuing

You have decided to run your system asynchronously. Thanks to the message queuing architecture. But then again, you need to implement this architecture to leverage your system's capabilities. One of the best ways to [implement messages queues is using Node.js (Typescript/NestJS)](https://docs.memphis.dev/memphis-new/sdks/node.js-typescript).

[Node.js is a popular technology](https://medium.com/@chegerose84/5-enhancements-that-will-boost-your-node-js-app-ca0c57ab191d) that offers a wide range of features for your application. This include:

- Asynchronous/Non-blocking thread execution. Node.js allows you to create Non-blocking servers/API. Every Node.js API is non-blocking. The subsequent tasks in the stack are continuously run while waiting for a response for something outside of the execution chain. Its single-threaded asynchronous capabilities make it well-suited to real-time communication processes. This is the exact architecture that you would desire to build your servers with. The fact that message queues are Asynchronous, your application performs at full potential.
- Event-driven. A node.js server is Event-driven. It uses Event Loop to handle multiple clients simultaneously. It uses its multiple threads pool for concurrent executions. This way, each time a request is sent, a dedicated thread is created to handle that specific request. This, again, makes it easier for non-blocking executions.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu65q427rsxcsvnkpijh.png)

[Image Source](https://scoutapm.com/blog/nodejs-architecture-and-12-best-practices-for-nodejs-development)
The above are a few advantages that Node.js offers. They make it easier and more scalable to build microservices applications. Adding the benefits of message queues, the combination allows you to create complex and high performant apps.

There are many message queues that you can use to run with Node.js. However, setting up one requires layers of infrastructure such as databases, networks, servers, OS, security, etc. Setting up all these elements to run your infrastructure can be challenging to maintain and monitor. Yet, it reduces your infrastructure portability. Downtime of one layer can hugely affect the whole application as the entire infrastructure is closely coupled to run all these layers together.

To overcome such challenges, we need modern solutions that exploit a modern infrastructure's flexibility, scalability, and resilience. A huge thanks to cloud native computing that allows you to run and host applications in the cloud to take advantage of the inherent characteristics of a cloud computing software delivery paradigm.

### Going Serverless: Running Message Queues as a Service (Cloud Native)

As of right now, almost every IT tool or product is accessible as a service. A delivery model that allows you to run serverless architecture. And Message Queues haven't been left on the cloud bandwagon. Cloud-native is built to offer a serverless development strategy created specifically to properly exploit the cloud computing architecture.

Serverless architecture, a cloud-native development methodology, allows developers to create applications without provisioning servers or to handle scaling management. Instead, such tasks are abstracted and handled by the cloud provider. This allows developers to create vendor agnostic, auto-provisioning, and highly scalable applications with the faster release of production-ready and fault-tolerant models.

This is facilitated by the fact that:

- Cloud natives are microservices centric - this way, your messages queues still run loosely coupled. Specific features can be updated without causing any downtime to your apps.
- They are created with Continuous Integration/Continuous Delivery (CI/CD) pipelines in mind. This brings the concept of Accelerated Software Development Lifecycle (SDLC) to your team and members to collaborate at different levels, such as designing, development, and testing.
- CI/CD is packed with automation. This allows you to make high-impact changes with minimal effort.
- Cloud Native Architecture is container orchestrated. You don't have to be concerned about the platform, operating system, or runtime environments.

To sum up, cloud native apps principles are:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8frnm9tgsgffn2r2auxw.png)

[Image Source](https://www.techtarget.com/searchcloudcomputing/definition/cloud-native-application)

Now imagine running your whole Message Queue architecture as a service. This is a huge step forward with a tone of benefits:

- Automation opportunities allow you to focus on other pressing challenges.
- Portability - message queues become vendor agnostic. Containers allow you to connect to different microservices components through port mapping. This way, you avoid [vendor lock-in](https://www.cloudflare.com/learning/cloud/what-is-vendor-lock-in/).
- Increased Reliability. You have reduced downtime, and the failure of one component doesn't affect adjacent services.
- Easy to manage and scale your architecture.
- Language - cloud native message queues are built to work with modern languages and frameworks such as Node.js, Typescript, Go, Python, Rust, etc.

Since cloud native can be easily implemented with a wide range of frameworks and languages, choosing what you want to work with is easy. Node.js is an excellent candidate for message queueing. We have seen that Node.js compliments the message queuing architecture.

### Top 5 Cloud-Native MQs with Node.js Support

Let's dive and learn about Node.js top cloud native message queues (MQs) that Node.js supports.

#### 1. Memphis

[Memphis](https://memphis.dev/) is an open-source, real-time data processing platform with an embedded distributed messaging queue. It is made to eliminate the heavy-lifting tasks for in-app streaming use cases.

Memphis is cloud native. It thrives by offering a Real-Time Data Processing Platform for the producer-consumer paradigm.

##### What makes Memphis special

- Memphis is a distributed message broker built for async communication
- It supports numerous [Cloud Deployment](https://docs.memphis.dev/memphis-new/deployment/cloud-deployment) platforms.
- Unlike other message brokers and queues that use topics and queues, Memphis uses stations.

A station provides easy-to-use messaging queues. It abstracts you from creating a never-ending stream of producers, consumers, orchestrations, manual scaling, and decentralized monitoring. A station handles all this for you. And that's what makes Memphis a unique platform. [Check out how to create a station](https://docs.memphis.dev/memphis-new/dashboard-ui/stations) in just a few clicks.

Here is a basic example of Memphis station at work:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxqmbwyu1ovb4n5nx8tr.jpeg)

Memphis is great for cloud-native app development. It uses modern tools to create a development stack. These include:

- Docker - Allows your application to leverage the virtualized containers and isolated resources and run microservices at scale.
- Kubernetes - It offers orchestration services that let you decide how and where to run your containers.
- Terraform - an IaC (Infrastructure as Code) tool that defines resources as code.
- Node.js support. Node.js is a popular JavaScript runtime. It is great for creating real-time applications and microservices of any kind. Node.js allows you to create virtual servers and routes for connecting microservices.

Memphis has great support for [Node.js and Typescript](https://docs.memphis.dev/memphis-new/sdks/node.js-typescript). Check out [Memphis SDKs for Node.js and Typescript and start creating Producers/Consumers](https://docs.memphis.dev/memphis-new/sdks/node.js-typescript). Memphis also has support for other server-side languages such as [Go](https://docs.memphis.dev/memphis-new/sdks/go) and [Python](https://docs.memphis.dev/memphis-new/sdks/python),

Have you deployed your Memphis message queue? Choose your preferred environment and run a Broker like never before. You can run Memphis on:

- [Kubernetes](https://docs.memphis.dev/memphis-new/deployment/kubernetes)
- [Docker-Compose](https://docs.memphis.dev/memphis-new/deployment/docker-compose)
- [Cloud providers](https://docs.memphis.dev/memphis-new/deployment/cloud-deployment)

#### 2. Rabbitmq

[RabbitMQ](https://www.rabbitmq.com/) is an open-source distributed message broker. Due to the rise of the microservice architecture, where every concern has its own run time that scales independently, RabbitMQ is a tool that allows these microservices to communicate asynchronously with a variety of different protocols to run large-scale applications.

RabbitMQ uses Advanced Message Queueing Protocol (AMQP). This allows middleware brokers such as RabbitMQ to conform with client applications and communicate effectively.

RabbitMQ uses Exchanges to manage messages. When a producer sends a message, it is not registered immediately to the queue. The message is quickly registered to RabbitMQ Exchange, which uses bindings and routing keys to determine which queue a message belongs to. Here is a basic example of RabbitMQ infrastructure:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxeda9mdd7x0777qovk7.png)

[Image Source](https://www.cloudamqp.com/blog/part1-rabbitmq-for-beginners-what-is-rabbitmq.html)

Check this guide and learn [what RabbitMQ is, and the important concept around it](https://www.cloudamqp.com/blog/part1-rabbitmq-for-beginners-what-is-rabbitmq.html).

RabbitMQ uses distributed deployment mechanism. You can set up instances in a highly available manner. Just like Memphis, RabbitMQ is cloud available. This allows you to run a highly available cluster on top of infrastructure such as [kubernetes](https://www.rabbitmq.com/kubernetes/operator/operator-overview.html) in the cloud.

Leveraging such features creates huge cross-language support for favourite programming languages suitable for developing scalable apps. You can run your cloud support RabbitMQ architecture with popular Node.js and take advantage of its features.

Here are [RabbitMQ features that you can comfortably run with Node.js](https://www.rabbitmq.com/devtools.html#node-dev)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/py4a3zzui02vrzf4xexf.png)

[Image Source](https://www.rabbitmq.com/devtools.html#node-dev)

#### 3. Kafka

[Kafka](https://kafka.apache.org/) is a distributed platform for pushing events for high-performance data pipelines. [Over 80% of all Fortune 100 organizations use Kafka](https://kafka.apache.org/) to run their infrastructure events.

These events are generated from different services. Kafka then streams and persists these events to other targets. Kafka is made to connect hundreds of event sources.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z732a9l01ftyw50uk0iq.png)

[Image Source](https://developer.confluent.io/what-is-apache-kafka/)

Kafka is well known for her performance. As a distributed platform, building a message queuing system on top of Kafka becomes very easy. Check this [A-Z Guide and learn about Apache Kafka Architecture and Its Components](https://www.projectpro.io/article/apache-kafka-architecture-/442).


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgp0mtaps5esvqrqaqnl.jpeg)

[Image source](https://unixcop.com/kafka-and-zookeeper-ha-cluster-setup/)

To build scale and speed streaming events, Kafka has five core functions. These are:

- [Publisher](https://kafka.apache.org/documentation/#theproducer) - This forms the data source that publishes streams of events to Kafka topics.
- [Consumer](https://kafka.apache.org/documentation/#theconsumer) - forms a subscribed application that takes data from any subscribed Kafka topics.
- Process - Kafka uses [streams API](https://kafka.apache.org/32/documentation/streams/) as a processor. This allows Kafka to consume incoming events from different sources and produce the outgoing data stream to one or more topics.
- Connect - [Kafka Connect](https://www.confluent.io/blog/kafka-connect-tutorial/#:~:text=Kafka%20Connect%20is%20the%20pluggable,with%20topics%20full%20of%20events) allows you to scale streaming data between Apache Kafka and other systems. This links Kafka topics to existing applications and brings data to the Kafka cluster and from other external sources.
- Store - Kafka provides a major data storage tool for your events.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58l3trcg2trc9mvaeu5e.png)

[Image Source](https://www.confluent.io/)

**So what makes Kafka popular?**

Some advantages that make Kafka popular include:

- Scalability
- High Throughput
- Low Latency
- Fault Tolerance
- Reliability
- Durability

Despite its popularity and advantages, Kafka is a challenging infrastructure to set up, deploy, scale and manage for on-premises production.

To avoid such challenges, Kafka is now built and can be [managed as a service in the cloud](https://www.cloudkarafka.com/). This allows the cloud to perform hard tasks, such as complex cluster sizing and provisioning, building, and maintaining the Kafka infrastructure. Instead, you focus on building your application logic as the cloud handles the heavy lifting. This makes it easy to deploy Kafka without requiring specific Kafka infrastructure management expertise.

To showcase your producers and consumers, Kafka supports various programming languages. Kafka cloud platforms, such as [Confluent Cloud](https://developer.confluent.io/get-started/nodejs/), allow you to build and consume Kafka using Node.js.

#### 4. Strimzi

Given that many message queue technologies are leveraging dynamic technologies such as Kubernetes. We have seen it's easier to run your Kafka streams using a cloud-native platform. [Strimzi](https://strimzi.io/) provides deployment configurations for Kafka. Strimzi allows you to run Apache Kafka cluster on Kubernetes. This allows you to spread brokers across availability zones and dedicated nodes.

Strimzi is a [Cloud Native Computing Foundation](https://www.cncf.io/) sandbox project. Basically, it bridges [Kube-native management of Kafka's wide features](https://strimzi.io/docs/operators/in-development/overview.html) such as cluster, topics, users, Kafka MirrorMaker and Kafka Connect. This way, you can expose Kafka outside Kubernetes using NodePort, OpenShift Routes, Ingress, and Load balancer.

[Once Kafka runs on Kube-native support that Strimzi offers](https://github.com/tulios/kafkajs/issues/1251), you can now start utilizing Node.js to create your streams and use libraries such as [KafkaJS](https://kafka.js.org/docs/getting-started), a modern Apache Kafka client for Node.js.

#### 5. Redpanda

Kafka architecture uses Zookeeper to keep track of a cluster of Kafka brokers.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/phlkj4com4aqhpecvu0u.png)

[Image source](https://unixcop.com/kafka-and-zookeeper-ha-cluster-setup/)

[Redpanda](https://redpanda.com/) is a streaming data platform that is Kafka-API compatible, ZooKeeper-free, and JVM-free. Kafka API is great. [Redpanda is built to make Kafka fast](https://redpanda.com/blog/redpanda-vs-kafka-faster-safer). Redpanda allows you to pick the deployment option that best suits your needs.

This include:

- [Using Terraform and Ansible](https://docs.redpanda.com/docs/deployment/production-deployment/).
- [Configuring the Kubernetes Operator for Connectivity](https://docs.redpanda.com/docs/deployment/kubernetes-connectivity/).

Its capacity to utilize infrastructure such as Kubernetes allows you to run [Kubernetes on Cloud](https://docs.redpanda.com/docs/quickstart/kubernetes-qs-cloud/) and access Redpanda outside the Kubernetes network.

Redpanda allows you to create [Kubernetes cluster and run your broker using cloud providers](https://docs.redpanda.com/docs/quickstart/kubernetes-qs-cloud/#create-a-kubernetes-cluster) such as Google Kubernetes Engine, Amazon EKS, and DigitalOcean.

Redpanda, being Kafka API compatible, allows you leverage to the countless client libraries created for Kafka, such as [KafkaJS client for Node.js](https://kafka.js.org/docs/getting-started).

Check this guide and learn [how to use Node.js with Redpanda](https://docs.redpanda.com/docs/development/guide-nodejs/)

### Conclusion

There are many Message Queues that you can use. However, a message queue running as cloud-native outstands the rest. It gives you the capacity to run servers queuing with scalability at the core. This article helped you learn more about cloud-native MQs and the best choices you can use with Node.js.