Posts

5 Lessons from failure

Today I messed up. I'm a strong believer in sharing experiences of failure. If no one talks about the times they make mistakes, we're going to be doomed to repeat the same errors over and over again. So, here goes... Today I made a big mistake in a production application that resulted in 15 minutes of frantic database scripting and partial service interruption. I'm going to share what I did wrong, in part so that I focus on what I can do better next time but also because I don't want other people to make the same mistakes. Here's what happened. In our application we have some entities which use a natural key rather than a database generated primary key. This can make life easier when querying as you reduce the number of joins but still have referential integrity (with the cost of a bit of denormalisation). In the past, the whole DAL was hand coded SQL so it saved a considerable amount of developer time; we now use an ORM so we really don't care about the ...

Azure worker roles and recurring tasks

Image
In our application we have multiple web front ends communicating with one or more worker roles. This allows our worker roles to take the brunt of expensive operations. For example, some (very infrequent) actions require up to about 500 emails being sent (via Amazon SES). Before Azure (BA), we did everything on the web server - it wasn't common but sometimes users reported over a minute from clicking the button to the result being displayed. Our move to using workers responding to queue messages has massively sped this sort of thing up. Most actions on the worker are triggered by queue messages but we do have several things that just need to happen at set intervals (we use blob leases to prevent multiple workers doing the same thing). While implementing the "ExclusiveJobHost" and "BlobLease" classes, I noticed a common pattern that I ended up pulling out: public class RecurringAction { private ManualResetEvent exitSignal = new ManualResetEvent( false ...

Validating partition and row keys in Azure Table Storage

Microsoft Azure Table storage is a very flexible No-Sql store for structured data. Each entity in the table is uniquely identified by a partition key and a row key. A good choice of these is beyond the scope of this post. However, it can be useful to check that entity you want to add to the table has valid partition and row keys. Here's a simple class that encapsulates those rules: /// <summary> /// Encapsulates knowledge about valid values for keys in Microsoft Azure table storage. /// </summary> /// <remarks> /// Rules are found here http://msdn.microsoft.com/library/azure/dd179338.aspx /// </remarks> internal static class KeyValidator { /// <summary> /// Determines whether the specified key is valid. /// </summary> /// <param name="keyValue">The key.</param> /// <param name="errors">Any errors in the value supplied.</param> /// <returns><c>tru...

Issue tracking nirvana

Like most developers I've experimented with lots of different ways of managing bugs, feature requests, architectural notes and documentation. I always start a new project determined to use a really air tight system for logging bugs and feature requests. I also try to create a central, accessible store for documentation which is searchable and easy for everyone to use. You know what? It never worked. I used a desktop "help desk" style system that logged absolutely everything but had no simple overview so figuring out what status a ticket was in involved opening it and reading through the history. Discussions were often via email and the help desk system wasn't updated. I'd get so fed up with spending 30 minutes setting up a ticket in the system that I'd resort to "todo" lists scattered over my desk. I eventually moved on to OneNote and finally Trello for my own time management although the department was officially using the desktop app. I moved...

Strong passwords.... Or not

I absolutely hate password "strength" plugins - they're almost always terrible. I use a password manager so all my passwords are generated according to the rules of the website I'm on to be as strong as the site will allow (within reason). So I was on NPower trying to register, it told me up to 20 chars, mixed case and at least one number. I got my password manager to generate me a 20 character mixed case password with numbers. I forgot to tick the box for special characters. The results for strength of password were alarming:  . @InfoSecInsanity nearly chose a bad password for @npowerhq but thanks to the PW strength test "Strong" now #FAIL pic.twitter.com/aLyCU184Q6 — Robert Head (@RobHead89) August 29, 2014 So 20 random chars is the same strength as "Orange1"? Add a space to the end (or any special character) and it's suddenly stronger? Who writes these things anyway? Validating the strength of a password is really bloody ...

Trimming strings in action parameters in ASP.Net Web API

In standard MVC it's very easy to create a model binder to trim all of the strings passed into action methods. The approach I used for that was from here:  http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/ . It works well and it trims the properties of models too. The problem came when I tried to do the same thing for Web API. I added a similar StringTrimmingBinder and registered it as a service using the very non-discoverable API: var provider = new SimpleModelBinderProvider( typeof ( string ),  new StringTrimmingModelBinder()); GlobalConfiguration.Configuration.Services.Insert( typeof (ModelBinderProvider),  0,  provider); As a side note, I have no idea how you're supposed to find out how to register a model binder without opening up Bing and Googling it. Anyway, this worked great when the parameters to the action were actually strings but doesn't work with complex types as parameters. Now, I'v...

It's good to share... have a play icon

Image
I'm sure I'm not the only developer who has needed a really simple image and haven't wanted to bother a designer (or haven't had access to one). It can be really annoying searching for an icon and having to either pay for a set even though you only need one or having to adhere to strict licensing rules.  All I needed was a play button to overlay on a thumbnail. To save other people the bother, and as an uncharacteristically good deed: here's the play button image I made, free forever to abuse to your heart's content. You can  view or download it here .