读写分离——查询需求常需扁平化多表 JOIN,与聚合模型不一致。引入 CQRS 可解除这种矛盾:
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Service public class OrderWriteService { public void submitOrder(SubmitOrderCommand cmd) { ... } }
@Service public class OrderReadService { public OrderDetailVO getOrderDetail(String orderId) { return orderReadDao.selectDetail(orderId); } }
|
事件溯源 (Event Sourcing) 是 CQRS 进阶版:存储所有事件序列而非当前状态。适用于审计要求极高的金融场景,但复杂度高,不要轻易使用。