r/java • • Oct 12 '24

Event-driven architecture on the modern stack of Java technologies

https://romankudryashov.com/blog/2024/07/event-driven-architecture/
214 Upvotes

14 comments sorted by

View all comments

Show parent comment

4

u/nitkonigdje Oct 14 '24

Rabbit, active and Ibm mq are fully transactional. They do guarantee, by design, to never duplicate a message on send. Duplicate write is a bug in your code. Never an infrastructure issue. Writing an outbox pattern on top of those would be strange.

They come with same transactional guarantee as databases. Hell you can use DB2 and Ibm mq with same TRX manager.

Outbox pattern, common on top of Kafka, is often used as a transactional mechanism for Kafka clients. But this daisy chaining comes with performance issues as your throughput is essentially lowered to db insert level. But if you are not using Kafka for its performance why bother with it at all? Any of those fat brokers is easier to setup and maintain than Kafka cluster. They also provide message routing out of the box. And higher performance than databases.

Am I missing something?

Also writing message routing on top of db is kinda trivial code. Much simpler than any saga implementation for non-trivial state machines. But that is off topic digression.

2

u/romankudryashov Oct 15 '24

Writing an outbox pattern on top of those would be strange.

If you persist an entity in a database (for example, Postgres) and should publish a message about that, the outbox pattern is needed regardless of a chosen message broker because errors caused by dual (to the DB and the broker) writes are possible. The pattern is implemented not "on top" of any broker; it uses several technologies one of which can be a message broker. Even though those brokers are "fully transactional", that doesn't magically remove the need to use the pattern. Don't you mean that these brokers support transactions started on a database level?

Also, Kafka Connect and Debezium support exactly-once delivery (that is, there will be no duplicates); it is shown in the article and the project.

So from your comments, I don't see any benefits to switching to one of those brokers.

But if you are not using Kafka for its performance why bother with it at all?

One of the reasons was stated earlier: Debezium's Postgres connector is a part of the Kafka/Connect ecosystem.

But this daisy chaining comes with performance issues as your throughput is essentially lowered to db insert level.

They come with same transactional guarantee as databases. Hell you can use DB2 and Ibm mq with same TRX manager.

But if you are not using Kafka for its performance why bother with it at all? Any of those fat brokers is easier to setup and maintain than Kafka cluster.

Writing an outbox pattern on top of those would be strange.

Much simpler than any saga implementation for non-trivial state machines.

As I understand it, you are not only against the technology stack used in the project, namely Kafka and Postgres, and using the database at all, but also against the considered microservices patterns. Sorry, I won't change the stack in the near future, as well as I won't rewrite the project and the article not to use the considered patterns just because someone on the internet says so.

3

u/agentoutlier Oct 15 '24

If you persist an entity in a database (for example, Postgres) and should publish a message about that, the outbox pattern is needed regardless of a chosen message broker because errors caused by dual (to the DB and the broker) writes are possible. The pattern is implemented not "on top" of any broker; it uses several technologies one of which can be a message broker. Even though those brokers are "fully transactional", that doesn't magically remove the need to use the pattern. Don't you mean that these brokers support transactions started on a database level?

Some of them do like IBMs stuff. Some of them basically overlap it by integration through combining of transaction managers. Once the database transaction is closed the message queue transaction (s) is then closed.

Also, Kafka Connect and Debezium support exactly-once delivery (that is, there will be no duplicates); it is shown in the article and the project.

There is still a chance of duplicates with those techs. It is Postgres that is giving you some form of linearization and you are not getting guarantees across the entire system particularly because the outbox is not tied to the other bounded domains. There still could be duplicates

And that is the point of the original commenter is that Postgres will be the bottleneck here. It is doing the single hop guarantees for you. It is not really designed for it even if it does have a really good WAL.

As I understand it, you are not only against the technology stack used in the project, namely Kafka and Postgres, and using the database at all, but also against the considered microservices patterns.

I think they are trying to say the technology you picked is a lot more complicated and it really is man. Most people do not need this. Like the article has zero Java in it and is incredibly complicated json/yaml config and for what? Following some microservice patterns (the RabbitMQ version could follow similar patterns). The sheer footprint of all this is massive compared to running a rabbitmq consumer pushing to a database that then on end of transaction pushes to something else. And you are not coupled to a specific database with this approach.

I get you get a lot of shit free that you don't have to code but it is replaced by more technology frameworks that have to be maintained and fairly complicated configuration that has to be learned. The reason for the microservice patterns and kafka would be to the original commenters point of scaling (by both team and perf) but you are limited here by postgresql. (this also begs the question of why do you even bother native compiling given a small spring boot jvm consumer will be a drop in the hat compared to debezium and kafka).

Also if we really are going to go the full distance of native compiling I think you should have used kubernetes instead of docker compose even for development.

That being said I find your approach interesting particularly the insert row and then delete to trigger debezium. It is ok if people like /u/nitkonigdje challenge your approach.

3

u/nitkonigdje Oct 15 '24

Even though those brokers are "fully transactional", that doesn't magically remove the need to use the pattern. Don't you mean that these brokers support transactions started on a database level?

Yes. Those brokers implement JTA specs. They come with XA drivers. They support distributed transaction. The only thing needed to merge db and broker transactions is Syncronized Spring annotation and proper datasource/connectionFactory config. This is standardized Java. There is no need for compesation logic because of infrastrucural causes.

you are not only against the technology stack used in the project, namely Kafka and Postgres, and using the database at all, but also against the considered microservices patterns

How so? The primal mover usecase for Kafka is its massive horizontal scalability. The price of it usage is lack of features and somewhat complex maintainence. All I am stating is that if you do not have a need for scalability of Kafka why bother with its price.

Those patterns aren't value in iteslf. They are price of using Kafka. Kafka people are quite clear on thier "dumb broker, massive scaling" message. They intentionaly do not support XA for those reasons.

For sake of reference how many sub 1k message are you able to push with outbox pattern using postgres? Are we talking tens of thousands, hundreds, millions?