Application Design: Single vs. Multiple Hits to the DB

Posted by shyneman on Stack Overflow See other posts from Stack Overflow or by shyneman
Published on 2010-04-21T22:28:24Z Indexed on 2010/04/21 22:33 UTC
Read the original article Hit count: 277

I'm building a service that performs a set of configured activities based on the type of request that it receives. Each activity involves going to the database and retrieving/updating some kind of information. The logic for each activity can be generalized and re-used across different request types. The activities may need to participate in a transaction for the duration of the servicing the request.

One option, I'm considering is having each activity maintain its own access to DAL/database. This fully encapsulates the activity into a stand-alone re-usable piece, but hitting the database multiple times for one request doesn't seem like a viable option. I don't really know how to easily implement the concept of a transaction across the multiple activities here either.

The second option is to encapsulate ALL the activities into one big activity and hit the database once. But this does not allow re-use and configuration of these activities for different requests.

Does anyone have any suggestions and input about what should be the best way to approach my problem? Thanks for any help.

© Stack Overflow or respective owner

Related posts about design-patterns

Related posts about design