Skip to main content

Azure CDN (Day 2 of 31)

List of all posts from this series: http://vunvulearadu.blogspot.ro/2014/11/azure-blog-post-marathon-is-ready-to.html

The service that I selected for today is CDN. For those who do not know, CDN comes from Content Delivery (Distribution) Network. The main goal of a CDN is to server end-users that need high availability and high performance. It is a cache system, similar with Reverse Proxy, but for static content.

Short Description
The content that can be cached on current CDNs is any kind of static content of content that is already stored on Azure blobs. For example it is very easily to use CDNs for pictures that are stored on Azure blobs.
First question that a person ask when you say about a CDN service is where are the nodes of this service. For any CDN customer it is very important to have a CDN network that is very close to their end-users and can cope with high traffic. I’m happy to say that the current CDN network is spread world-wide in the most important internet nodes. I expect in future to see more CDN nodes added to it.
Below you can find a picture with the current location of CDN nodes that Azure CDN has. And YES, the nodes are not only Azure Data Centers.
The Azure CDN works as a normal CDN. Content is requested to CDN. If the content is found on CDN node that it is served from there, otherwise the service that has the resource is called and content is cached on CDN.

Main Features
The static content that is cached, does not mean only images. You can also use CDN for content like static pages with query strings. Content can be accessed using HTTP or HTTPS.
We have the possibility to specify how long an item to be stored on CDN (expiration time)

Limitations
When you cache items with query string, don’t forget that URL with parameters are stored as string literals. This mean that ‘http://[path]?name=Radu&status=Ok’ and ‘‘http://[path]? status=Ok&name=Radu’  are different content from CDN perspective.
When you are using CDN in combination with blobs it is recommended that the size of blobs to be less than 10GB.
Custom domain are supported only for HTTP. When you want to use CDN over HTTPS, you need to use a certificate provider by CND – custom certificates are not supported in this moment. Also, custom CNAME are not supported also. Because of this you need to use the CDN name.
When HTTPS is used over CDN, the content can be also retrieved over HTTP.

Applicable Use Cases
Below, I will present 4 use cases when I would use Azure CDN.

Newsletters
I would use Azure CDN for all the content related to newsletters (html, images and so on). Why? Because this is a static content that reach a lot of people around the world in a very short period of time.

Image Sharing
If you have a web application used by users to share images than Azure CDN can be used with success to reduce the load of your backend.

SPA Application
A real SPA application contains only HTML/CSS/JavaScript and some content. All this content ca be stored on CNDs, you don’t need to serve JavaScript files from your own machines. You can use Azure Blobs and Azure CDN with success.

Updates
If you have updates for different systems, that are public available, than this is the perfect place to send them to end-clients, without a high load on your back-end infrastructure.


Code Sample
How to use CDNs in combination with Azure Blobs
I was impresses to discover how easily you can use CDN service using Blobs. Once you activate CDN service you need to do only two small steps:
  • Make the blob container public (to be accessible by anybody)
  • Configure CDN to cache the blob content
  • Use CDN URL format or Blob URL format
Sample:
CND URL: http://[myCDNServiceName].vo.msecnd.net/[containerName]/[resourceName] 
Azure Blob URL: http://[myAccount].blob.core.windows.net/[contanerName/[resourceName]

How to use CDNs in combination with a standard service
To be able to do this you need to have port 80 open for HTTP requests. On top of this you will need to create a folder called ‘cdn’ under service path where you need to put all the content that you want to cache or you can deliver it to CDN directly. As for blobs, you will need to specify to CDN what the service path.
Once this was done, you can access content through CDN path
http://[myCNDServiceName].vo.msecdn.net/hello.jpg
http://myWebSite.cloudapp.net/cnd/hello.jpg

How to specify the expiration time for content
If you want to cache content from a cloud service, than you have two option.
First option is to use a web.config file where you can add the static content node. The second option available is to set in HTTP response the expiration heather. This can be done from ISS or from code. Below you can find the content used for this.
Response.Cache.SetExpires(DateTime.Now.AddHours(8));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetLastModified(DateTime.Now);
For blob content that is cached, things are pretty different. By default the content will be stored on CDN for 7 days. If you want to specify the expiration time you need to set ‘x-ms-blob-cache-control’ property in the moment when you add or update blob content (Put Blob, Put Block Blob, Set Blob Properties).x-ms-blob-cache-control: public, max-age=259200 This can be done using code also:
blob.SetCacheControl("public, max-age=259200"); Don’t forget that the value is expressed in seconds.

Pros and Cons
Pros
Easy to use.
Salable.
World wide distributed
HTTP and HTTPS support
Expiration date configurable
Can automatic redirect users to the proper CDN based on their location


Cons
You don’t have the ability to specify the data center that is served for users. When because of the legal part you can store content only in specific regions than you may have some issues.
Only anonymous access supported.
No support for SAS (Shared Access Signature) in combination with CDNs.

Pricing
You need to pay only for outbound traffic. You don’t pay for storage that is used on CDN nodes.

Conclusion
Azure CDN can be a very good option for you. The price is very attractive and can be very easily integrated on existing system. It works very well with systems hosted on Microsoft Azure.
It can be a great option when you need a low latency and massive scalable CDN service for your systems.

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see