Top Azure Tips and Best Practices

Tom Dykstra and I have just published an Azure multi-tier tutorial with the complete source. It has many valuable programming tips and best practices you can’t find anywhere else. Learn how to use Windows Azure Storage tables, queues, and blobs in a multi-tier application that has ASP.NET MVC 4 and ASP.NET Web API on the front end. My favorite sections include:

  • Web sites versus web role in a cloud service.
  • How to design tables for efficient queries using the new Windows Azure Storage Client Library (SCL) 2.0. The new SCL offers huge performance benefits over the previous SCL.
  • How to handle concurrency exceptions in ASP.NET MVC using the SCL. There are a couple tricks to getting it right, but the sample shows it’s easy once you know these.
  • How to set the retry policy in SCL 2.0 code for a UI. The SCL 2.0 API automatically retries three times with exponentially increasing timeout limits, something you generally don’t want to do in a web page.
  • How to use batch deletes and batch queue fetches to save transaction costs.
  • Using nullable types on storage tables containing multiple types (and why it’s important).
  • How to optimally shut down web and worker roles. Windows Azure Cloud Service applications are restarted approximately twice per month for operating system updates. When a web application is going to be shut down, an OnStop event is raised. The web role boilerplate created by Visual Studio does not override the OnStop method, so the application will have only a few seconds to finish processing HTTP requests before it is shut down.
  • How to write effective OnStart methods. The boilerplate code generated by Visual Studio for the OnStart method uses several obsolete calls such as:
    • Trace.WriteLine("Working", "Information");
    • ServicePointManager.DefaultConnectionLimit = 12;
  • How to effectively use tracing and diagnostics.
  • Tips on cost savings.
  • Why you should care about affinity. (Currently affinity requires you to navigate to the old portal.)
  • Using GUIDs versus Time.Now.Ticks for row keys.
  • How to decrease project startup time by disabling the Azure Storage Emulator.

Comments

  • Anonymous
    December 29, 2012
    "Why you should care about affinity. (Currently affinity requires you to navigate to the old portal.)" You can manage affinities on the network tab on the new portal.

  • Anonymous
    January 12, 2013
    Thanks Rick. Appreciate the heads-up.