-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to avoid out-of-order events / lost events in sos-restful #14
Comments
I think events ordering and clock synchronisation in distributed systems is far harder topic than just generating timestamp on database node. For example, database can be replicated or sharded onto multiple nodes as well. There are already available solutions like vector clocks, but isn't it out of a scope of Spring Data? |
I am aware that I don't achieve something like 'global ordering' by the proposed improvements. But when using the sequence number instead of timestamp and by getting the sequence number after the insert statement for the aggregate (enforced by flush), I think it is at least guaranteed that the events for one aggregate are in the right order. |
By the way, we seem to agree that sos-restful has some flaws regarding event timestamps. So what is the solution you propose to make it work for 'real life'? |
I changed the description and title to make clear it is not my intention to get reliable timestamps. |
We should discuss what kind of consistency guarantees you need in the first place. Spring Data is an abstraction over diverse types of storage, including NoSQL databases as well. We should decide on application characteristic first, then come up with a solution. |
IMHO, sos-restful is an approach that is based on the transactional guarantees of a relational database. To be more specific: It relies on persisting the aggregate and the domain event within the same transaction. If the database does not support this, the sos-restful approach cannot be used. To make clear: I am not talking about Spring Data at all (as you seem to assume in your comments). All I wrote is specific to the sos-restful example where JPA and a relational DB are used. |
Hello Oliver,
at first, thanks a lot for the comprehensive example and for your efforts to bring more support for DDD into Spring (Data).
I have a suggestion for some minor improvements of sos-restful regarding event timestamps: Currently the timestamp is set in the constructor for the event. In case a transaction takes a bit longer than another one, it might happen that an event with an "earlier" timestamp is seen later by other transactions. That is, we get out-of-order events. Even worse, if a consumer polls between the commit of the first and the second transaction, it might miss the out-of-order event at all, since it has already stored the later timestamp in its database and will never query for "earlier" events again.
To solve this problem, we would need to store the "timestamp of the transaction commit" in the event. However... there is no such thing in JPA (or even in SQL) at all.
But I think, with some simple changes, we can get very close to that:
The text was updated successfully, but these errors were encountered: