I'm currently looking into NestJS to use as the framework for a new e-commerce project. The goal is to build multiple loosely-coupled services, which can communicate with each other using the pub/sub messaging pattern. NestJS offers some great integrations out-of-the-box with tools like Redis, NATS and RabbitMQ. I've read that Kafka is also supported, but that isn't properly documented yet.
The problem I have is about decision-making. After reading lots of material about event-based systems and how they work, I still don't have a clear vision on what tool to pick.
1) I think I need a message broker that can queue messages to ensure they get delivered (eventually) to the subscribers.
This is because I might have a CatalogueService
which emits events such as product_created
. Services like a CartService
and OrderService
should also hold a copy of the product data and these products should be up-to-date. I can't afford to have old prices in the OrderService
as the price calculations would be off. Also, if a service goes down, it can be restarted and properly process any unprocessed messages in the queue.
2) I think I need a message broker that can support FIFO (first in, first out) queues.
This is because I might have two product_edited
events that should be processed in the right order to prevent corrupted data. If a store manager changes a product price twice, the latter price should be considered as most actual.
I used the words "I think" in front of the two requirements as I'm not a 100% sure if my thinking is correct. Therefor I'm curious to see what your thoughts and experiences are. Any tips, tricks or advice would be highly appreciated!