Design guidelines for concurrent DB connection in SOA

SQL Server Concurrency Control Interview Questions 

Quick overview of SOA

A service-oriented architecture (SOA) is an architectural pattern in computer software design in which application components provide services to other components via a communications protocol, typically over a network. Service-orientation is a way of thinking in terms of services and service-based development and the outcomes of services.

The Problem
In the current technology world, SOA is becoming more and more common and issues related to concurrency is inevitable if the system design is not proper. With increasing concurrent user requests, the system should be capable of establishing multiple database connections without any deadlock or race condition.

Solution/The Design guidelines
Some design guidelines I recommend and follow while architecting a system that should be able to establish simultaneous database connections.

1. Don't make your connection static/shared.

     Static is evil, if not handled cautiously. If the connection is declared as static, multiple  requests  will be accessing the same connection object and the ends up in deadlock and race condition. System will throw unexpected errors like 
 'Not allowed to change the 'ConnectionString' property. The connection's current state is open.'
2. Always use using statement for DB connection object. Using will act as try catch finally block and closes and disposes the connection object, and this connection object is moved to connection pool that is manged by CLR.

3. Make sure to write unit test cases to test the concurrent connections before pushing to QA.

Read more on this and common issues:
1. how-to-test-concurrency-scenarios-in-net
2. Executereader-requires-an-open-and-available-connection-the-connections-
3. how-can-i-solve-a-connection-pool-problem-between-asp-net-and-sql-server
4. Dispose-the-connection-or-close-the-connection



Comments

Popular posts from this blog

Consume Antimalware Scan Interface (AMSI) from C#

Munnar Diaries [Part 1] - Backpacking to Munnar and spectacular Vattavada village

Missing her badly. Need to date her once more at least.. ;)