Code Samples

Download Code

Ten example applications that demonstrate the implementation of some of the patterns in this guide are available for you to download and run on your own computer or in your own Microsoft Azure subscription. To obtain and run the applications:

  1. Go to the Cloud Design Patterns - Sample Code page on the Microsoft Download Center. Download the "Cloud Design Patterns" file.
  2. In Windows Explorer open the Properties for the zip file and choose Unblock.
  3. Copy the files from the zip file to a folder near the root of your disk, such as C:\PatternsGuide. Do not unzip the files into your user profile folders (such as Documents or Downloads) because this will result in over-length file names.
  4. Open the file Readme.htm in your browser. It contains information about configuring your system and the examples, running the examples locally in the Azure emulator or deploying them to Azure, and understanding what the examples show.

The example applications for use in conjunction with this guide are shown in the following table.




Competing Consumers

MessagingPerformance & Scalability

This example contains two components: the Sender worker role is responsible for sending messages to a Service Bus queue, and the Receiver worker role retrieves messages from the queue and processes them. The Receiver worker role is configured to run with two instances to simulate competition between consumers.

Compute Resource Consolidation

Design and Implementation

This example shows how you can consolidate several separate and distinct tasks into a single worker role. There are no additional requirements for running this example.

External Configuration Store

Design and Implementation

Management and Monitoring

This example shows a mechanism for storing configuration settings in an external store instead of using configuration files. In this example, settings are stored in Azure Blob Storage. The blob containing the configuration information is monitored by an instance of the ExternalConfigurationManager class. When the ExternalConfigurationManager object detects a change in the configuration store, it notifies the application of the change.

Health Endpoint Monitoring

AvailabilityManagement and Monitoring

This example shows how you can set up a web endpoint that checks the health of dependent services by returning appropriate status codes. The endpoints are designed to be consumed by a watchdog monitoring service such as Azure endpoint monitoring, but you can open and invoke the endpoint operations from a browser to see the results. You can also deploy and configure your own endpoint monitoring tool of choice to send requests to the service operations and analyze the responses received.

Leader Election

Design and ImplementationResiliency

This example shows how a worker role instance can become a leader among a group of peer instances. The leader can then perform tasks that coordinate and control the other instances; these tasks should be performed by only one instance of the worker role. The leader is elected by acquiring a blob lease.

Pipes and Filters

MessagingDesign and Implementation

This example contains two filters that could perform some part of the overall processing for a task. The two filters are combined into a pipeline; the output of one filter is passed as the input to the next. The filters are implemented as separate worker roles and a Azure Service Bus queue provides the infrastructure that acts as the pipe.

Priority Queue

MessagingPerformance & Scalability

This example shows how you can implement priority queues by using Service Bus Topics and Subscriptions. A worker role is responsible for sending messages to a topic. It assigns a priority to each one. The receiving worker roles read messages from subscriptions that have the corresponding priority. In the example, The PriorityQueue.High worker role runs with two instances, whereas the PriorityQueue.Low worker runs only with one. This ensures that high priority messages are read from the queue more quickly than low priority messages.

Runtime Reconfiguration

Design and ImplementationManagement and Monitoring

This example shows how a change in the settings of a Cloud Service can be applied without restarting the web or worker role.

Static Content Hosting

Data ManagementDesign and ImplementationPerformance & Scalability

This example shows how to reference static content from a publicly accessible storage service. The example contains a Azure web role, which hosts a web application that references JavaScript files and images deployed to a Azure storage account. This type of content is typically deployed to the storage account as part of the application deployment process. However, to simplify the example, these files are deployed to the storage account when the application starts up.

Valet Key

Data ManagementSecurity

This example shows how a client application can obtain a shared access signature with the necessary permissions to write directly to blob storage. For simplicity, this sample focuses on the mechanism to obtain and consume a valet key and does not show how to implement authentication or secure communications.


The samples provided for this guide are simplified to focus on and demonstrate the essential features of each pattern. They are not designed to be used in production scenarios.

Next Topic | Previous Topic | Home | Community

patterns & practices Developer Center