Resource
- https://martinfowler.com/articles/dblogic.html
Digest
Where to implement logic :
- SQL - Database Side
- Code - In-Memory
- Transaction Script (Function alike)
- Domain Object
Comparasion
Performance
- Most of the time you should focus on writing maintainable code, then use a profiler to identify hot spots and then replace only those hot spots with faster but less clear code.
- The main reason is in most systems only a very small proportion of the code is actually performance critical, and it's much easier to improve the performance of well factored maintainable code.
- The complex SQL does the selection and summing of costs in the database and only has to schlep a handful of values back to the client, while the in-memory approach needs to schlep five thousand rows of data back to the client.
Tuning
- [In-Memory Tuning] Firstly it's worth remembering that in-memory code can often by boosted by more intelligent queries. It's always worth looking to see if you are calling the database multiple times, and if there's a way to do it with a single call instead.
- [Database Side] You may find that locking issues outweigh anything you can get by faster individual queries.
- Doing things in-memory as a default, and using things like complex queries for hot spots only when they have to.