I avoid using massive operations as possible as I can when applying rich domain model.
Some batch could be replaced with events. For example, I need a daily order count report.
The batch solution:
A scheduling task which is triggered at the end of the day collects data from orders placed today.
Or use events
The PlaceOrderService publishes a OrderPlacedEvent when a new order is placed. And a eventHandler receives the event and inserts to T_ORDER_COUNT_ENTRY
|TODAY |ORDER_ID|
|2012-04-01|123 |
|2012-04-01|124 |
The we could use SQL count() to calculate the daily order count report.
Some other batch could run parallelly. For example, My orders should be canceled automatically if unpaid in 30 mins.
The original batch solution is fetch all orders satisfied one by one and invokes their cancel().
The current solution is fetch all orders satisfied one by one and sends a OrderIsOverdue message. Message handlers receive the message containing an orderId and retrieve the order then cancel.
I think this is useful when the cancel operation takes far more time than sends a message . More message handler could be added to improve the thoughput if the hardware resources can afford it.