Quick revision
The short answer
We start by listing the invariants that truly must hold in one transaction, such as the order total matching its lines, and keep only those objects in the Order aggregate. Shipments and payments have their own lifecycles, so they become separate aggregates that reference the order by id; status history becomes an append-only log; and the aggregates stay in step through domain events with eventual consistency. For orders with 10,000 lines, line items can become their own aggregate with a summary kept on the order, and every one of these splits reduces both loading time and optimistic lock conflicts.
What to remember
In this answer, we redesigned an Order aggregate that held lines, payments, shipments and full status history. We kept only the invariants that truly need one transaction, the total matching the lines and no edits after confirmation, inside Order. Shipments and payments became separate aggregates referencing the order by id, history became an append-only log, and domain events with eventual consistency keep the pieces in step. For very large orders we considered making line items their own aggregate with a summary on the order, and we saw that smaller aggregates reduce both loading cost and optimistic lock conflicts.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We start by listing the invariants that truly must hold in one transaction, such as the order total matching its lines, and keep only those objects in the Order aggregate. Shipments and payments have their own lifecycles, so they become separate aggregates that reference the order by id; status history becomes an append-only log; and the aggregates stay in step through domain events with eventual consistency. For orders with 10,000 lines, line items can become their own aggregate with a summary kept on the order, and every one of these splits reduces both loading time and optimistic lock conflicts.
Why this question is asked
A large aggregate is one of the most common design problems in systems that adopted DDD early. It starts small and correct, then every new feature adds another collection, until saving a shipment status loads ten thousand order lines and fights with the payment service over the same version number. Interviewers ask this question to see whether we can redraw boundaries from the business rules rather than from the data model. In this answer, we will look at why the current design is slow and conflicts, find the real invariants, split out shipments and payments, move history to a log, connect the pieces with events, and decide what to do with very large line collections.
1Why the Current Aggregate Hurts
An aggregate is the unit we load, change and save as a whole, and its root carries the version used for optimistic locking. Our Order holds lines, payments, shipments and status history. So every change, even marking one parcel as delivered, loads the order and, depending on the mapping, some or all of its collections, then bumps the order's version.
That causes two separate problems. The first is cost: with 10,000 lines, loading and dirty-checking the aggregate takes real time and memory for a change that does not involve lines at all. The second is contention: the warehouse updating a shipment, the payment service recording a capture and a customer service agent changing an address all update the same version. Only one of them wins; the others get optimistic lock exceptions and retry, even though their changes have nothing to do with each other.
2Finding the Invariants That Need One Transaction
The way out is to ask, for each rule, whether it must be true at the exact moment of every commit, or whether it is fine if it becomes true a second later. Only the first kind needs one aggregate.
For an order, typical rules are: the total equals the sum of the lines; lines cannot be changed once the order is confirmed; the amount paid cannot exceed the total; everything paid must eventually be shipped or refunded. The first two involve only the order and its lines. The third involves payments and the total, but it can be checked by the payment aggregate against a total it was told about. The last one is a process rule that plays out over days, which is a clear sign it does not belong inside a single transaction.
| Rule | Must hold at every commit? | Where it lives |
|---|---|---|
| Total equals sum of lines | Yes | Order aggregate |
| No line changes after confirmation | Yes | Order aggregate |
| Paid amount not above order total | Yes, against a known total | Payment aggregate, total from an event |
| Every order is shipped or refunded | No, over days | Process: events and a saga |
| Status history is complete | No, append-only | Order event log |
3Splitting Out Shipments and Payments
Shipments and payments have their own lifecycles. A shipment is created, packed, handed to a carrier, delivered or returned. A payment is authorised, captured, partly refunded. These lifecycles are driven by different teams and systems, and their rules are mostly about themselves. So each becomes its own aggregate with its own root, repository and version, holding the order's id rather than an object reference.
Notice that marking a parcel delivered no longer touches the order at all. The warehouse and the payment service now update different rows with different versions, so they cannot conflict with each other or with order edits.
4Moving History to an Append-Only Log
A collection of status changes inside the order grows forever and is loaded for every change. But history is never modified, only appended to, and it has no invariant that requires reading the whole list before adding an entry. So it fits much better as an append-only table, order_status_history with order id, old status, new status, time and actor, written in the same transaction as the status change but never loaded as part of the aggregate.
Many teams write this log from the domain events the order publishes, which gives one record of what happened that can feed both the history screen and auditing. If the business needs full replay of an order's state, that is a step towards event sourcing, but a simple history table already removes the problem.
5Keeping Aggregates in Step With Domain Events
Once the pieces are separate aggregates, they communicate through domain events. When the order is confirmed, it publishes OrderConfirmed with the order id and the total. The payment side listens and authorises the amount; the fulfilment side creates shipments. When payment is captured, PaymentCaptured is published, and the order can move to PAID. Each step is its own transaction on one aggregate.
This is eventual consistency: for a short time, an order may be confirmed while its shipment does not exist yet. That is acceptable because the business already works this way. A warehouse never packed a parcel in the same instant the order was confirmed. Publishing the events reliably, for example through a transactional outbox, is what makes the delay safe.
8 messages in order. Play them, or step through them one at a time.
6What About 10,000 Line Items?
Lines and the total do share a true invariant, so for normal orders they stay together. For very large orders, typically bulk business orders, we have options. If the lines are mapped lazily and most changes do not touch them, a root field such as total and lineCount lets the order enforce rules without loading every line, and adding a line can be done with a targeted query.
If lines are edited often and concurrently, for example several buyers working on one large purchase order, we can make the line, or a group of lines such as a section, its own aggregate, and keep a summary on the order: line count and total, updated through events or a recalculation step. The cost is that the total is now eventually consistent, so confirmation must recheck it. The choice depends on how the business works with these orders, which is worth asking before building it.
Whatever we choose, the result is the same direction: smaller aggregates mean less data loaded per change and fewer transactions competing for the same version, so optimistic lock conflicts drop sharply.
7Follow-up questions
How do you migrate from the big aggregate without a big bang?
One part at a time. Shipments are usually first: create the Shipment aggregate over the existing table, stop mapping the collection on Order, and route warehouse updates to the new repository. Then payments, then history. Each step is a small release that can be measured for fewer conflicts.
Does splitting aggregates mean splitting services?
No. Shipment and Payment can stay in the same service and database as Order. Aggregate boundaries are about consistency and locking; service boundaries are a separate decision, though good aggregate boundaries make later service splits much easier.
How do you show a full order page with all the parts?
With a read model or a query that joins the tables for display. Reads do not need to go through aggregates, so the order page can show lines, payments, shipments and history together while each part is still changed through its own aggregate.
8Conclusion
In this answer, we redesigned an Order aggregate that held lines, payments, shipments and full status history. We kept only the invariants that truly need one transaction, the total matching the lines and no edits after confirmation, inside Order. Shipments and payments became separate aggregates referencing the order by id, history became an append-only log, and domain events with eventual consistency keep the pieces in step. For very large orders we considered making line items their own aggregate with a summary on the order, and we saw that smaller aggregates reduce both loading cost and optimistic lock conflicts.
Open with
I would start from the invariants, not the data model. I would ask which rules must hold at every single commit. For an order that is usually the total matching the sum of the lines and no line changes after confirmation, and those involve only the order and its lines.
Then, if they want more
Everything else has its own lifecycle. Shipments are created, packed, delivered or returned by the warehouse; payments are authorised, captured and refunded by the payment side. So I would make Shipment and Payment their own aggregates with their own versions, holding the order id instead of being collections on the order.
Then marking a parcel delivered no longer loads the order or bumps its version, which removes most of the conflicts. Status history I would move out of the aggregate into an append-only table, ideally written from the domain events the order publishes, because it is only ever appended to and never needs to be loaded for a change.
The aggregates then talk through events: OrderConfirmed starts payment authorisation and shipment creation, PaymentCaptured moves the order to paid, each in its own transaction, published reliably through an outbox. That is eventual consistency, which matches how the business works anyway.
For the orders with 10,000 lines, I would keep a total and line count on the root so most changes do not load the lines, and if lines are edited concurrently, make lines or sections their own aggregate with a summary on the order. Smaller aggregates mean less loading and far fewer optimistic lock failures.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "An Order aggregate includes its line items, payments, shipments and the full history of...": https://scrivio-interview-library.netlify.app/java/domain-driven-design/fc9c4bb772/