DATABASE

SQL Azure: Building a Shard (part 1) - Designing the Shard Library Object

1/31/2011 5:20:42 PM
Let's build a shard library that can be used by applications that need to load and update data against multiple SQL Azure databases as quickly and transparently as possible. For the purpose of building an efficient shard library, you stipulate the following requirements for the shard:
  1. Adding new databases should be simple and transparent to the client code.

  2. Adding new databases shouldn't affect performance negatively.

  3. The library should function with SQL Server, SQL Azure, or both.

  4. The library should optionally cache results for fast retrieval.

  5. The library should support mass or selective reads and writes.

  6. Data returned by the library should be accepted as a data source for controls.

These requirements have very specific implications from a technology standpoint. 

Table 2. Technologies Used to Build the Shard
TechnologyRequirementComment
Configuration file1The configuration file stores the list of databases that make up the shard.
Multithreading2Using the TPL lets the library to spawn multiple threads to use computers with multiple CPUs, allowing parallel execution of SQL statements.
SqlClient3Using SqlCommand objects allows the shard to connect to both SQL Azure and SQL Server databases.
Caching4Caching lets the library store results temporarily to avoid unnecessary roundtrips.
Breadcrumbs5The library creates a virtual column for each record returned that stores a breadcrumb identifying the database a record it came from.
DataTable6The library returns a DataTable object that can be bound to objects easily.

1. Designing the Shard Library Object

The library accepts requests directly from client applications and can be viewed as an API. Note that you're using extension methods to make this API blend in with the existing SqlCommand class; this in turn minimizes the amount of code on the client and makes the application easier to read.

Figure 1 shows where the library fits in a typical application design. It also shows how the library hides the complexity of parallel processing and caching from the client application. Finally, the shard library abstracts the client code from dealing directly with multiple databases.

Figure 1. Shard library object diagram

A sample application is provided to demonstrate how to use the shard library. Although the application is very simple, it uses all the features of the shard for reference.

NOTE

Check http://EnzoSqlShard.Codeplex.com for the latest shard library. This shard library is made available as an open source project.

Other  
  •  SQL Azure: Designing for High Performance - General Performance Concepts
  •  SQL Server 2008 : Explaining Advanced Query Techniques - Creating and Altering Tables
  •  SQL Server 2008 : Explaining Advanced Query Techniques - Managing Internationalization Considerations
  •  Programming Microsoft SQL Server 2005 : Deployment (part 2) - Testing Your Stored Procedures
  •  Programming Microsoft SQL Server 2005 : Deployment (part 1) - Deploying Your Assembly
  •  Programming Microsoft SQL Server 2005 : CLR Stored Procedures and Server-Side Data Access
  •  SQL Server 2008 : Explaining Advanced Query Techniques - Controlling Execution Plans (part 3) - Using the Resource Governor
  •  SQL Server 2008 : Explaining Advanced Query Techniques - Controlling Execution Plans (part 2)
  •  SQL Server 2008 : Explaining Advanced Query Techniques - Controlling Execution Plans (part 1)
  •  Reporting Services with SQL Azure : Deploying the Report & Creating a Subreport
  •  Reporting Services with SQL Azure : Creating the Report Design
  •  SQL Server 2008 : Explaining Advanced Query Techniques - Applying Ranking Functions (part 2) - Using RANK, DENSE_RANK and NTILE
  •  SQL Server 2008 : Explaining Advanced Query Techniques - Applying Ranking Functions (part 1) - Using ROW_NUMBER
  •  SQL Server 2008 : Demystifying Data Types - Computed Columns
  •  Programming Microsoft SQL Server 2005: Overview of SQL CLR - Visual Studio/SQL Server Integration
  •  Programming Microsoft SQL Server 2005: DDL Triggers and Notifications
  •  Programming Microsoft SQL Server 2005: Enabling CLR Integration
  •  Reporting Services with SQL Azure : Creating the SQL Azure Data Source
  •  Reporting Services with SQL Azure : Starting a SQL Azure–Based Report
  •  SQL Server 2008 : Service Broker - Message Types
  •  
    Most View
    Active Directory Domain Services 2008 : Seize the Schema Master Role, Seize the Domain Naming Master Role
    10 Things To Try Right Now (Part 1)
    Windows Phone 7 : Working with Controls and Themes - Panorama and Pivot Controls
    Microsoft Tries To Flatten Competition With Surface (Part 4)
    SQL Server 2005 Native XML Web Services : Exposing SQL Programmability as Web Services (part 2) - Calling Native XML Web Service Endpoints from Client Applications
    Sony Vaio Duo 11 Review - A Nice Hybrid Laptop
    Ultrabook vs MacBook (Part 1)
    Basic Tips, Tricks And Tweaks For The Mighty Gmail
    Windows Server 2008: Active Directory Infrastructure - Deploying Read-Only Domain Controllers (RODCs)
    Planet Of The Apps – Travel (Part 2)
    Top 10
    ADO.NET Programming : Microsoft SQL Server (part 4) - Working with Typed Data Sets
    ADO.NET Programming : Microsoft SQL Server (part 3) - Using Stored Procedures with DataSet Objects
    ADO.NET Programming : Microsoft SQL Server (part 2) - Using SQL Server Stored Procedures
    ADO.NET Programming : Microsoft SQL Server (part 1) - Connecting to SQL Server, Creating Command Objects
    Windows Phone 8 In-Depth Review (Part 6)
    Windows Phone 8 In-Depth Review (Part 5)
    Windows Phone 8 In-Depth Review (Part 4)
    Windows Phone 8 In-Depth Review (Part 3)
    Windows Phone 8 In-Depth Review (Part 2)
    Windows Phone 8 In-Depth Review (Part 1)