Skip to main content

Should we trust a services for our communication channel or should we use our own channel and protocol?

Nowadays there are a lot of mechanism that can be used to connect devices from the field to our own system and infrastructure. If we are looking at the services that are offered by cloud providers, we will discover that each cloud provider one or more solution that can be used at a messaging or transport platform between our devices and backed.
For example, if we take Microsoft Azure, we have Storage Queues and Service Bus ‘Suite’ (that contains Topics, Queues, Relay and Event Hub). Looking at an offered like this, we ask our self what service should be used. In the end, all this services are extraordinary and can bring value to our solution.

In this post we will debate about a simple question that I heard a lot of times in the last 2 years in different meetings and/or project:
Should we trust a services for our communication channel or should we use our own channel and protocol? 

Before jumping into the discussion let’s elaborate the question a little more. The communication between two different endpoint (device and backed) can be done over HTTP(s) or TCP. This can be done by defining our own protocol and contracts OR we can rely on an external provider that would offer all the infrastructure that we need.

In the seccond case, we have control to the content that is send over the wire, but a part of the contract is defined by the external provider that created the communication channel.
Let’s take for example a messaging system like Azure Service Bus Topic. Microsoft Azure provides us a REST API that can be used to send messages over the wire. Amazon SNSis another services provided by AWS that offers us something similar.
All this services are great, work as expected, but what is happening if we create a system that will be develop in 2 or 3 years, will be in a testing phase for 1 year and will need to run for 10 years… We need to be able to provide a robust solution that can run for ~14 years without having to change it too much.
Why we need something like this. Because is pretty hard and complex to change/modify the communication channel. In a regulatory field like banking or life science this will required a lot of time and effort. On top of this, all the time we will have some machines or devices where the update was not installed successfully and we need human intervention – extra costs.

In this moment there is no cloud providers that will guaranty to you that the current service API will not be change (or braking change) in the next 2 or 5 years. In 5 years for example they could be at v8 and v1 will not be supported anymore. Or the authentication mechanism that is used will be outdated and will be discontinue.
This is a risk that appears when we need SaaS (Software as a Services). In this cases we don’t have any kind of control to the service that we consume. For example Microsoft will announce us with at least year before a breaking change will be made to the API.
The good part about this is that almost all cloud providers in this moment are backward compatibility. All of them are supporting the old version of their APIs even if are deprecated or without the last features that were added in the last period of time.
On the other hand, working with a REST API or system hosted by us will give us the full control of what kind of API we expose, what is the contract and so on. Even if we are hosting the machines that exposes the API in cloud, we fully manage the API and control this. In this way we can support the old API as long as needed.
A solution like this will come automatically with extra costs – development, maintenance and support.

A decision between this two solutions is pretty hard to take and is not simple. We need to take into account what kind of clients will access our endpoints, what is the costs of a custom solution and for how our solution will be used. Of course we need to think about how easy a change can be pushed into the system.
In the last months, we had to take a decision like this. We took into consideration the fallowing parameters:

  • For how long the solution should run without major changes: long time (8-10 years)
  • How easy a major change can be pushed into the system: very hard
  • In a case of an update fail how critical is to be able to reconnect to the device: high
  • How expensive is an API change: high
  • Are we working in a regulatory field: yes
  • Is there a high risk after an update to lose the connection with the devices: yes

Based on this risks and the information that we have in this moment we decided to expose our own API and manage all the communication by ourselves. We decided to expose a REST API to the public endpoint. Of course behind this API we have the messaging systems that handles all the communication. The REST API is like a wrapper over the messaging system as SaaS. In this way we can fully manage and control the contracts between backend and devices. It is more simple to update a components that is deployed on 10 or 100 servers in comparison with a client application that is deployed on 500.000 devices.


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.