This post is part of a series of posts that aims to capture a number of emerging design patterns for the Windows Azure Platform. This series will begin by tackling emerging design patterns for Windows Azure Table storage.
The Transactional Master-Item Record Pattern ensures that modifications to a master record and its item records are performed in a transactional way.
Example
Changes to an expense record with expense line items is an set of data that needs to be managed in a transaction way.
Challenge
Storing the Expense entity and Expense Item entity in separate tables can be made to be transactional by using another mechanism, such as a queue and a worker role, to provide eventual consistency.
The above approach is explained in more detail in the WAAG - Part 1 - Release Candidate, “Example from 05 Week 2” document (http://wag.codeplex.com/releases/view/45438).
Solution
Store both record types, Expense and Expense Item, in the same table and ensure that the same partition key is used for an expense and its associated expense items. This allows the transaction consistency to be managed by the Windows Azure Table entity group transaction feature.
The RowKey can be left blank for the master expense entity with the expense item entities using the RowKey as its unique identifier.
Summary
Motivation:
To ensure that modifications to a master record and its item records are performed in a transactional way.
Implementation:
Multiple entity types stored in single table with the same partition key can utilise the Windows Azure Table entity group transaction feature that provides batch transactions on entities.
Uses:
When a transactional operation is required.
Reference
Windows Azure Tables and Queues Deep Dive
Also See
Table Name Key Pattern
Hash Partitioning Pattern
Transactional Master-Item Record Pattern
Chronological Query Pattern
Starts With Query Pattern