If you do not know Polly, you are missing out! I did not know about it until a couple of days ago and you properly never heard about it either, as this wonderful little library only has 63 downloads on NuGet at the time of writing.
Polly is an easy to use retry and circuit breaker pattern implementation for .Net – let me show you.
Start by specifying the policy – what should happen when an exception thrown:
var policy = Policy
.Handle<SqlException(e => e.Number == 1205) // Handling deadlock victim
.Retry(3, (exception, retyCount, context) =>
The above policy specifies a SqlExeption with number 1205 or OtherException should be retried three times – if it still fails log and bobble the original exception up the call stack.
var result = policy.Execute(() => FetchData(p1, p2));
It is also possible to specify the time between retries – e.g. exponential back off:
var policy = Policy
.WaitAndRetry(5, retryAttempt =>
Or the circuit breaker safeguarding against the same error occurs again and again if an external system is temporarily unavailable:
var policy = Policy
Go get it – I’m already using it
Do you need access to the bare HTTP request in ASP.NET Web API to access custom header etc.? Then add the HttpRequestMessage:
public class CalculatorController : ApiController
public int Add(HttpRequestMessage requestMessage, int x, int y)
var accessToken = requestMessage.Headers.Authorization.Parameter;
// use the HTTP header
return x + y;
The HttpRequestMessage is automatically bound to the controller action, so you can still execute the action like http://localhost/calculator/add?x=3&y=2
Simple and easy.
I followed a couple of sessions the continuous delivery by Sam Newman, Michael T. Nygard (author of Release It) and Jez Humble (author of Continuous Delivery).
Continuous Integration is a prerequisite of Continuous Delivery, but many still don’t use apply Continuous Integration to their solution, with daily incremental check-ins, automated build and unit tests.
To simplify Continuous Delivery, everything must be automated. To ease the task of automation, things must be simplified. To simplify, start by decomposing the system into manageable pieces, so each can be deployed separately. How?
Decompose the system into disconnected services makes it easier to deploy a subset of the system. This limits the impact of a deployment. It even makes it possible to mitigate the risk further by making small incremental changes by only deploying one subsystem at the time.
These services have to be structured as application silos and share nothing, not even the database schema.
By automating and decomposing your system into disconnected application silo services you too can do Continuous Delivery.
I’m looking forward to the last day of the conference tomorrow.
The day started with a keynote from @Falkvinge from the Pirate Party. I wasn’t expecting much from this keynote, but I was pleasantly surprised. First of all, I assumed that I knew quite a bit about the Pirate Party – I was wrong! Facts: the Pirate Party is present in 150 countries and has 2 European Union parliament members. These guys are serious and not just a protest party wanting to legalize sharing copyrighted material. They are fighting the problems with limiting access to knowledge and ideas. They are emphasizing that exclusive right like patents, copyright and subsidizing are counterproductive. That’s so true! @Falkvinge disrupted my brain – that’s great, because that is why I’m here!
Next up was great presentation of graph databases by Jim Webber – fast speaking provocative British architect from Neo4J. He (re)spiked my interest in ‘other’ databases and stressed that each type of database like relational, object, key-value stores, document, graph etc. databases each fit their problem domain. So you shouldn’t just pick RavenDB because it is the new hot think in .Net sphere (or because Ayende aka Oren Eini says so). I will definitely take a look Net4J with the .Net client library Neo4jClient . Another great point from Jim Webber was; ACID does scale (though many claims otherwise), but he stressed it was distributed ACID with 2PC that doesn’t scale.
From then on I attended a couple of unfortunate sessions (not worth mentioning). Now it is time for the conference party where the beer is sponsored by Atlassian.
Soon I’ll be joining a bunch of great people from the Danish developer community and abroad at this year GOTO Conference in Aarhus next week.
I’ve been looking at the conference schedule trying to create my schedule… the line-up of international fame speakers are impressive, but I’ll go for the odd sessions to expand my horizon. During breaks I’ll discuss and share ideas with my fellow attendees – I might even skip sessions for interesting discussions in the hallways.
Here is my tentative schedule: