Skip to main content

Traffic Manager (Day 7 of 31)

List of all posts from this series:

Short Description
Traffic Manager allow us to distributed traffic to different endpoints. Endpoints can be on different datacenters. From some perspectives we can look at Traffic Manager like a Load Balancer at global level. In this way we can deploy a solution to multiple datacenters and redirect traffic based on user location

Main Features
Used only as DNS Resolver
Traffic Manager is used only to resolve the endpoint address. Once the endpoint is resolved, the request will go directly to the endpoint and will not pass through traffic manager.
Traffic Manager DNS Name
Each Traffic Manager instance will has his own DNS name. We will register this DNS in behind our real DNS if we want to redirect traffic from our site ( through Traffic Manger.
Configuration Tools
We can configure it using Power Shell, REST API or Management Portal. All the features are available from each tool.
We can specify how long the name of the DNS that is resolved by Traffic Manager will be cached by our clients.
Load Balancing Method
There are 3 types of load balancing supported in this moment:

  • Performance – Based on performance and the load of each endpoint (based on latency)
  • Round Robin – Traffic is redirect to all endpoints in a balanced way (first request goes to endpoint 1, second to endpoint 2 and so on) 
  • Failover – When the first endpoint is down, traffic is redirected to the second endpoint (and so on). We can specify the failover order

Endpoints Weight
Each endpoint can have a specific weight that will be used by Traffic Manager for traffic distribution. Bigger values means that that endpoint can receive more traffic. It is used by Round Robin load balancing methods (this can be configured only from PowerShell or REST API).
Custom monitor endpoint
Traffic Manager allow us to specify what endpoint to monitor. We can use use HTTP/HTTPS endpoints. We can also specify a custom port and path. For all endpoints, the same monitor endpoint will be used.
A Traffic Manager profile represent all the configuration for a specific node.
Nested Profiles
Traffic Manager allow us to specify another traffic endpoint. In this way we can define complex failover profiles and we can manage different load balancing rules.
How does it works
Traffic Manager checks at a specific time interval if endpoint status. If 4 times in a row the endpoint is down, the endpoint will be marked as down and traffic will not be redirected anymore to that endpoint. Users that already know about that endpoint will still try to connect to that endpoint until the DNS cache expires (DNS TTL).
Real DNS
Traffic Manager can be used by your own domain DNS. Your DNS needs to point to Traffic Manager DNS.
Endpoints location
All endpoints needs to be from the same subscription. You cannot use it with external endpoints.
Redirect user base on location
Users will be redirected to the closer endpoint. In this way clients can reach the endpoint that is in the best shape and is the most close to them.
Automatic Failover
Traffic Manager is able automatically to switch to another endpoint when the original one is down.
Test new deployments
We can very easily add endpoint with different configuration or different version of our application and check the behavior of them (testing the surface with new features).
Reduce Application Downtime
Traffic Manager allow us to switch automatically to a healthy endpoint if the original one is down.
Distribute traffic on multiple locations
Being able to register multiple endpoint from different datacenters, the traffic will be distributed to the closest endpoint (based on response time or other configuration – depending on what load balancing method we seleted).

Not all Azure Services Supported
You cannot include in Traffic Manager services like Service Bus, SQL Azure or Storage. In general you don’t want to do something like this.
External Endpoints are not supported
You are not allowed to monitor external endpoints (from on-premises or from other Azure Subscriptions)
Monitor Configuration
You don’t have access to monitor configuration. Clients cannot configure how often the health of endpoints is checked.

Applicable Use Cases 
Next, you can find 3 use cases where I would use Traffic Manager.
Web Sites deployed in multiple data centers
If you have a web sites that is deployed in multiple data centers, that the load balancing of traffic can be made easily using Traffic Manager. If the load of a web sites increase or is down the traffic will be redirected automatically to another endpoint.
Uniform load distribution
When you have a system that is distributes in different data centers and you have a custom rule to specify if an endpoint can accept new clients or not you can use Traffic Manager with success. You should implement the url path that is used to check the endpoint health to return a HTTP error code different from 200 OK if the current endpoint cannot accept new clients anymore.
Web sites failover
You can use traffic manager only as a failover mechanism for your web sites and configure the last failover endpoint from Traffic Manager to return only a simple HTTP page. In this way even if your system is down clients will be able to see something ‘nice’.

Code Sample 
 There is no custom code that you need to write when using Traffic Manager

Pros and Cons 

  • Simple to use
  • Different load balancing methods


  • Cannot specify external endpoints
  • Cannot specify endpoints from different subscriptions
  • One point of failure if Traffic is down

When you calculate the cost of using Traffic Manager in your system you should take into account:
The number of DNS queries to traffic manager

Traffic Manager can be the feature that can make a real difference when you are working on a system that needs to be scalable, redundant and ready to face any kind of out stage. Yes, if Traffic Manager is down your system will be down, but Traffic Manager is running on all datacenters around the globe.


Popular posts from this blog

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 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.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…

GET call of REST API that contains '/'-slash character in the value of a parameter

Let’s assume that we have the following scenario: I have a public HTTP endpoint and I need to post some content using GET command. One of the parameters contains special characters like “\” and “/”. If the endpoint is an ApiController than you may have problems if you encode the parameter using the http encoder.
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = baseUrl; Task<HttpResponseMessage> response = httpClient.GetAsync(string.Format("api/foo/{0}", "qwert/qwerqwer"))); response.Wait(); response.Result.EnsureSuccessStatusCode(); } One possible solution would be to encode the query parameter using UrlTokenEncode method of HttpServerUtility class and GetBytes method ofUTF8. In this way you would get the array of bytes of the parameter and encode them as a url token.
The following code show to you how you could write the encode and decode methods.