'BLL / DAL separation vs performance
I often end up in situations where clean design goes in opposite direction of performance.
Say you have a clear separation between your business logic and your data access layer. What if you need to filter data coming from the data access layer, based on some business rule? Of course, implementing the filter in the DAL (say, in a SQL query, ORM, etc.) would perform best, but this would break the separation between the BLL and the DAL.
Say you have a CustomerService dealing with all the business logic related to Customers, and using a CustomerRepository to persist data. One of the rules in the business logic is to identify "active customers" with a simple logic like "has placed an order within the last X days".
If we look into performance, we could join the Customer table with the Order table and apply a proper WHERE clause. But this way we'd end up having a business rule defined in the DAL, not in the BLL.
On the other hand, if we want to strictly define the rule in the BLL, we'd need to first gather all Customers from the DAL, then apply the filter based on the business rule. But this way we are sacrificing performance (and this would degrade over time as we know that the data in the database will grow over time). This would become even worse if we'd want to implement pagination in the DAL.
Would you like to share your thoughts about this scenario? What would be the best implementation in your opinion?
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|