Aggregate design for a fuel tank with deliveries and fill level readings

So I’ve got a rather simple, mostly crud application I want to use DDD with, to learn/practice it. I wonder about aggregate design regarding a fuel tank entity. Each tank stores fill level readings (date, fill level), usually one each year, and gets several deliveries of fuel per year (date, amount, cost).
Looking at invariants, the two collections are independent from each other, and I can only see one business rule for the fill level readings: there must only be one reading for any given date.
Regarding usage patterns, the two collections are edited independently as well, because a delivery rarely happens on the same day that readings are taken. When reading a tank to display it, however, the most recent values of both collections are also needed.

What does that mean for aggregate design? I roughly see three options:

  1. One big tank aggregate containing both collections. I can maintain the invariant, but always need to load both collections even when only editing one. (Then again, they’re small enough that their size shouldn’t be an issue in my example, after 20 years a tank would roughly have 60 deliveries.)
  2. One tank aggregate, one aggregate for the tank level collection, one for the deliveries collection. The invariant can be maintained within the collection aggregate, and i only need to load the collection that actually gets modified.
  3. One tank aggregate, but each tank level and delivery would be their won aggregate, so no collection aggregates. The invariant cannot be maintained in the model anymore, but it’s a simple unique constraint so i could put that into the db layer. I only need to load and save the single values i edit, no more collections.

Given this simple albeit maybe a little vague example, do any of you with experience in DDD have a preference for an aggregate design or even a different design idea altogether?

4

I wonder about aggregate design regarding a fuel tank entity.

OK, so one of the things that you have to have clear in your head, is where the “book of record” lies. If you are dealing with a collection of readings from a physical fuel tank, then the book of record is outside of your model (you can’t add fuel to the tank by changing numbers in your digital representation).

Truth is what’s actually in the tank; the readings from the sensors give you some approximation of that truth (which may or may not be reliable, depending on the quality of the sensors), your inputs are digital representations of those readings (hopefully without too many transcription errors), and your database is “just” a collection of cached copies of those digital representations.

In this sort of situation, your “aggregates” turn out not to be very interesting, because there’s not much for them to do (other than perhaps check if some message has already been written down).

Aggregates are a lot more interesting when you have processes. For instance, we might have a process that is responsible for deciding when to order more fuel from the vendor. So when new information from one of the fuel tank sensors arrives, we might load stored information about the deciding, integrate the new sensor data, and update our decisions about when to schedule an order.

In very rough terms, the aggregate is interesting because it is writing down things other than just the facts it was told and what it writes down next depends (in part) on what it has written down before — i.e. its own internal state, over which it is the sole authority.

CRUD tends to suggest that you are designing a database, so don’t be in a hurry to implement a bunch of patterns that are more appropriate to a service.

For more on the book of record problem, search for discussions of modeling warehouse systems.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật