Which tier in a webapp should create history records?

I have a 3-tiered web application with a web view layer, a business logic layer, and a database persistence layer. I am adding a feature that populates a history table with records if and only if the element being saved has changed (it compares the previous and current records and saves the history records if anything has changed).

I’m not sure if the logic of building the history records and saving them belongs in the business logic layer or the database persistence layer. The database persistence layer has a single saveElement method. The business logic layer has multiple places that call the database persistence’s saveElement method.

Advantage of placing the history logic in the database persistence layer:

-If the logic were placed in the business logic layer, there is a risk that some of the business logic layer callers would forget to call the method to create the history records. If the logic was placed in the database persistence layer, any saved record is guaranteed to have a history record created.
-The site has another history system for other information that is in the database layer and it would create consistency if both systems were located in the same place.

Advantage of placing the history logic in the business logic layer:

-There is a bit of complexity in building the history records and the database layer is mainly used for calling/running sql queries.

So is there any compelling reason to place this logic in either the business logic layer or the database layer? Or does it not matter where the logic is placed?

3

It depends.

Specifically, it depends on the logical level you would like to remember changes for. If “element changed” is a sensible history record, and you already have saveElement in the persistence layer, then extending saveElement to also log the change to a historical/archive record makes sense.

However, if you are trying to archive business-level events like “purchased inventory for project 4017” at a higher level than the elements you’re storing, you will need to do that in the business layer, because that’s where the intention of the activity is understood.

This is a classic layering issue: “where is the intention information available?” Often the straightforward answer (e.g. “we want to save history information and we already have a persistence layer, so that’s where it should go!”) is, if not incorrect, made dramatically less clear by higher layers decomposing their activities, and calling the persistence layer as more of a “save this!” workhorse. Higher level concepts are often unavailable by the time they filter down to persistence layers. At a minimum, then, you would need to adjust the API between the layers to allow the business layer to declare its intent (such as “for project X”) as it calls saveElement.

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

Which tier in a webapp should create history records?

I have a 3-tiered web application with a web view layer, a business logic layer, and a database persistence layer. I am adding a feature that populates a history table with records if and only if the element being saved has changed (it compares the previous and current records and saves the history records if anything has changed).

I’m not sure if the logic of building the history records and saving them belongs in the business logic layer or the database persistence layer. The database persistence layer has a single saveElement method. The business logic layer has multiple places that call the database persistence’s saveElement method.

Advantage of placing the history logic in the database persistence layer:

-If the logic were placed in the business logic layer, there is a risk that some of the business logic layer callers would forget to call the method to create the history records. If the logic was placed in the database persistence layer, any saved record is guaranteed to have a history record created.
-The site has another history system for other information that is in the database layer and it would create consistency if both systems were located in the same place.

Advantage of placing the history logic in the business logic layer:

-There is a bit of complexity in building the history records and the database layer is mainly used for calling/running sql queries.

So is there any compelling reason to place this logic in either the business logic layer or the database layer? Or does it not matter where the logic is placed?

3

It depends.

Specifically, it depends on the logical level you would like to remember changes for. If “element changed” is a sensible history record, and you already have saveElement in the persistence layer, then extending saveElement to also log the change to a historical/archive record makes sense.

However, if you are trying to archive business-level events like “purchased inventory for project 4017” at a higher level than the elements you’re storing, you will need to do that in the business layer, because that’s where the intention of the activity is understood.

This is a classic layering issue: “where is the intention information available?” Often the straightforward answer (e.g. “we want to save history information and we already have a persistence layer, so that’s where it should go!”) is, if not incorrect, made dramatically less clear by higher layers decomposing their activities, and calling the persistence layer as more of a “save this!” workhorse. Higher level concepts are often unavailable by the time they filter down to persistence layers. At a minimum, then, you would need to adjust the API between the layers to allow the business layer to declare its intent (such as “for project X”) as it calls saveElement.

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