At Woovi we focus on shipping production code with the simplest architecture, this helps us scale easier and have a simple DevOps approach.
We also wrote about all the use cases of Redis at Woovi. And we are going to cover how to implement it
BullMQ
BullMQ is a fast and robust background job processing library for Redis.
It uses Redis to create a queue of messages that will be processed in the background by workers.
You can achieve the same results using other more complex message brokers like RabbitMQ and Kafka.
For us, BullMQ has provided the best cost-benefit until now.
Node Implementation
You need to understand only two concepts to get up and running with BullMQ: Queue and Worker.
A Queue
creates a queue on Redis, where your application services can add messages to it or events.
A Worker
is a process that will process each message from a specific Queue
import { Queue } from "bullmq";
const queue = new Queue("Payment");
await queue.add("payment_received", {
payment,
});
import { Worker } from 'bullmq';
const worker = new Worker('Payment', async job => {
if (job.name === 'payment_received') {
await processPayment(job.data);
}
}, { concurrency: 100 });
BullMQ Architecture
BullMQ lets you emit events to any Queue from any server or worker and also scales your workers as your message grows.
Event Driven Benefits
When adopting an event-driven architecture you can easily decouple your code.
Decoupled Code: The code that emits the event does not need to know about the code or service that will process the event.
Fault-Tolerant: You can also add retries when processing a message, making your system more fault-tolerant.
Rate Limit: You can control the rate limit of your processing, read more about it here Control Rate Limit using Queues
In Conclusion
If you are looking for a message queue or distributed processing job, give BullMQ a try.
If you are already using Redis, adding BullMQ to your stack will be easy.
Move to more complex tools like RabbitMQ and Kafka when needed, if needed.
Woovi is an innovative startup revolutionizing the payment landscape. With Woovi, shoppers can enjoy the freedom to pay however they prefer. Our cutting-edge platform provides instant payment solutions, empowering merchants to accept orders and enhance their customer experience seamlessly.
If you're interested in joining our team, we're hiring! Check out our job openings at Woovi Careers.
Top comments (0)