Data Access Principle

Hello everyone.  In this post I will be explaining certain guidelines/principles that can be applied to data access in software applications and architecture.

Acquire Late & Release Early

Shorten the holding duration of shared/limited resources such as network and database connections by using a principle “acquire late & release early”. Re-acquiring and releasing network and database connection resources from the operating system can be expensive, so a simple recycling plan to support this principle enables you to optimize the use of shared resources across requests. Most of the modern data access tools makes these jobs easy. Use language constructs, such as using statement, finally blocks, etc., to make sure that resources are released even if any exception.


Data which would change less often and be read frequently is ideal for caching. That means, the same data has been requested very frequently (again & again) by the application which is optimal for caching. So caching such data helps to reduce the load to the data source and improve the performance.

KISS: Keep It Simple, SuperStar :)

Keep It Simple principle doesn't mean to avoid complex design patterns or architectural patterns, you should bring these patterns to bear in order to solve a specific problem. Maintain the code as simple as possible to test easily and flexible to change during new requirements or pain points.

Command Query Responsibility Segregation (CQRS)

One other pattern which would talk about reading the data is more frequent than writing, CQRS. Below are some basic CQRS ground rules:
  • No business logic execution while reading the data, only during writing.
  • Context based DB querying
  • Aggregated data should be pre-calculated.
  • Write actions should only return status message (success or failure).
  • Write actions mostly process one row at a time during create or update.

Sharing Connection Pool

Using a trusted subsystem model and fixed identity to connect and access downstream systems and databases. This allows the connection to be efficiently pooled.
I hope you enjoy this post, If you found it helpful, then please like this post and provide feedback that really motivates me to create more useful stuff for you guys. Thanks! 

Next Recommended Reading SOLID Principles