JQueue: A Library to Implement the Outbox Pattern

In microservices or any other event-based architecture, in some use cases, a service might require us to make changes to their own local database and also publish an event. That event is then consumed by other services. To have a consistent software system, it is mandatory that these two actions get performed atomically. Both actions need to complete successfully, or none of them need to complete. There should not be another way.  

An elegant way to solve this is by using the Outbox Pattern. This works by using a database table (if your service uses a relational database), usually called the outbox table, to store the events. In this case, you are able to include the insert SQL statement of the event into the use case local transaction. Another runner can periodically check if the outbox table is not empty and process the events by publishing them into a message broker.

Logical Separation in the Hexagonal Architecture

Have you ever lied to your stakeholders? I must confess that I did once (unintentionally)... I drew a very nice picture of boxes and arrows and I presented it to them as the "logical view" of the architecture of the software product they were in charge of. However, those logical boxes, which were supposed to be groups of classes with a specific purpose, were not represented in code. Source code was a real mess, basically just spaghetti code. There were dependencies everywhere without any defined rules or without any architectural rule. There was a clear gap between my picture and the source code.

If you have read my previous post, Coding your Architecture Structure, you know that one of the structures to architect a software system is created using syntactical constructions. Usually those constructions are packages, namespaces, or modules. So, with this idea we create an application using the Hexagonal Architecture Style, where each logical group of classes that this style suggests is represented as a package in the picture below.

Code Your Architecture Structure

When you read about software architecture structures and views, you will find different opinions from different authors. And what is worse, they use the same terms for explaining different concepts, which just contributes to the general confusion. 

This article just reviews these concepts and tries to clarify them proposing a simplification.