Is multiple aggregates update in one transaction good?

I don't believe there is anything wrong with using multiple repositories to fetch data in a transaction. Often during a transaction an aggregate will need information from other aggregates in order to make a decision on whether to, or how to, change state. That's fine. It is, however, the modifying of state on multiple aggregates within one transaction that is deemed undesirable, and I think this what your referenced quote was trying to imply.

The reason this is undesirable is because of concurrency. As well as protecting the in-variants within it's boundary, each aggregate should be protected from concurrent transactions. e.g. two users making a change to an aggregate at the same time.

This protection is typically achieved by having a version/timestamp on the aggregates' DB table. When the aggregate is saved, a comparison is made of the version being saved and the version currently stored in the db (which may now be different from when the transaction started). If they don't match an exception is raised.

It basically boils down to this: In a collaborative system (many users making many transactions), the more aggregates that are modified in a single transaction will result in an increase of concurrency exceptions.

The exact same thing is true if your aggregate is too large & offers many state changing methods; multiple users can only modify the aggregate one at a time. By designing small aggregates that are modified in isolation in a transaction reduces concurrency collisions.

Vaughn Vernon has done an excellent job explaining this in his 3 part article.

However, this is just a guiding principle and there will be exceptions where more than one aggregate will need to be modified. The fact that you are considering whether the transaction/use case could be re-factored to only modify one aggregate is a good thing.

时间: 2024-10-27 16:08:37

Is multiple aggregates update in one transaction good?的相关文章

解决yum update时提示Transaction Check Error的问题

今天帮一个朋友update系统时,发现其中一台server居然提示: Transaction Check Error: file /usr/lib/perl5/5.8.8/CGI.pm from install of perl-5.8.8-32.el5_7.6.x86_64 conflicts with file from package perl-5.8.8-32.el5_6.3.i386 file /usr/lib/perl5/5.8.8/Digest.pm from install of

sql server-SQL Server 一条UPDATE执行超时 这时会自动回滚所有已经执行的更行吗

问题描述 SQL Server 一条UPDATE执行超时 这时会自动回滚所有已经执行的更行吗 如题 我误操作执行一条UPDATE执行 后在执行过程中立即关闭了客户端. 因为数据量极大 肯定会超时的 这时会自动回滚所有已经执行的更新吗 没有加上事务语句,但是一条更新语句应该属于SQLServer的隐式事务吧.这个时候会自动回滚吗? 求教各位大神 谢谢大家 解决方案 启动SQL SERVER时自动执行存储过程启动SQL Server时自动执行存储过程sql server 自动执行存储过程 解决方案二

领域驱动设计常见问题FAQ

本文出处:http://www.cqrs.nu/Faq What is a domain? The field for which a system is built. Airport management, insurance sales, coffee shops, orbital flight, you name it. It's not unusual for an application to span several different domains. For example, a

元旦技术大礼包 - 2017金秋将要发布的PostgreSQL 10.0已装备了哪些核武器?

标签 PostgreSQL , 10.0 , 金秋 , 元旦 , 大礼包 , commitfest 背景 早上送给大家的新年大礼包,一年一个大版本是PostgreSQL社区的传统,虽然发布时间通常为秋天,还有一段时间,但是已经迫不及待地想看看2017金秋将要发布的10.0版本已经装备了哪些核武器. 放心,还会有一波又一波的feature和增强搭上开往2017金秋的列车,本文提到的可能只是其中的某一节车厢沃,PGer是不是开始有一点振奋人心的感觉啦. 1. 并行计算专属动态共享内存区,(加速索引扫

[翻译]:SQL死锁-阻塞探测

原文:[翻译]:SQL死锁-阻塞探测 到了这篇,才是真正动手解决问题的时候,有了死锁之后就要分析死锁的原因,具体就是需要定位到具体的SQL语句上.那么如何发现产生死锁的问题本质呢?下面这篇讲的非常细了,还提到了不少实用的SQL,但对我个人来讲,前半部分基本就够用,可以指出死锁的原因,至于后面那些有兴趣可以多研究研究. As we already know, usually blocking happens due non-optimized queries. But how to detect

Lucene/Solr 4.0-ALPHA – What’s In A Name?

Lucene & Solr 4.0-ALPHA were released on July 3, 2012. This is a huge milestone for the project, and the culmination of an idea that was spawned 2 years ago with the creation of the 4x branch. I've included the highlights from the release announcemen

MySQL 5.5.49 大内存优化配置文件优化详解_Mysql

一.配置文件说明 my-small.cnf my-medium.cnf my-large.cnf my-huge.cnf my-innodb-heavy-4G.cnf  二.详解 my-innodb-heavy-4G.cnf三.配置文件优化 注:环境说明,CentO5.5 x86_64+MySQL-5.5.32 相关软件下载:http://yunpan.cn/QtaCuLHLRKzRq 一.配置文件说明 Mysql-5.5.49是Mysql5.5系列中最后一个版本,也是最后一个有配置文件的版本,

ADO.NET最佳实践(中)

ado         使用DataReader可以在你的应用程序中做以下事情:         I.不需要缓存数据:         II.处理太大而不能存储的数据:         III.需要以只进.只读和快速方式一次性访问数据的.     G.使用一个自定义的强有力的DataSet类型的好处         通过创建一个继承于DataSet的子对象,你可以在运行期间执行类型检查和声明.当你有了一个确定的计划或者为你的DataSet有相关的结构,你就可以创建一个用行和列表述一个对象的Dat

SQL SERVER事务处理

server|事务处理 事务定义:事务是单个的工作单元.如果某一事务成功,则在该事务中进行的所有数据更改均会提交,成为数据库中的永久组成部分.如果事务遇到错误且必须取消或回滚,则所有数据更改均被清除.事务三种运行模式:自动提交事务每条单独的语句都是一个事务.显式事务每个事务均以 BEGIN TRANSACTION 语句显式开始,以 COMMIT 或 ROLLBACK 语句显式结束.隐性事务在前一个事务完成时新事务隐式启动,但每个事务仍以 COMMIT 或 ROLLBACK 语句显式完成.事务操作