đź’ˇ Tip for Coupling: Keep things that change together in the same module(s)
Cohesion:
Answer: Yes, you're correct. A queue being directly written to and read from by distributed services often results in tighter coupling compared to using a messaging service that facilitates publishing and subscriptions to a topic. Here's why:
OrderService directly puts an order into a ProcessingQueue, and an InventoryService reads from this queue. If the queue's structure or the message format changes, both services need to be updated. Additionally, if a new service like a ShippingService needs to process the same orders, it must also interact directly with the ProcessingQueue, increasing coupling and complexity.OrderService publishes orders to an OrderTopic. Both InventoryService and ShippingService subscribe to the OrderTopic. The OrderService doesn't need to know about the subscribers, and new subscribers can be added without affecting the publisher or other subscribers, leading to a more flexible and scalable architecture.In summary, using a messaging service with the publish/subscribe model provides a more decoupled, scalable, and flexible architecture compared to direct interactions with a queue, facilitating easier maintenance and the ability to evolve parts of the system independently.
đź““ Note: deriving components from domains in chapter 8