Our software engineer’s curious case of the QR code, Christmas Day, and 20 million downloads

Duncan Robertson has a knack. A skill that you cannot bottle or create. In the age of viral content, there is no exact science to creating something that explodes with popularity. You just have to be saying the right thing, in the right place, at the right time.

Duncan’s done this not once, but twice. To this date, his blog on Devise authentication strategies is still one of the highest ranking pieces of Kyan content, appearing in the top five pages of our marketing dashboard month-on-month. With over 30,000 impressions in the last 16 months alone, it’s really struck a chord with engineers and developers the world over.

But going back even further, to a time before Duncan joined Kyan, he created a gem whilst working at the BBC. A gem which at the time of writing this, is just shy of 20 million downloads. For comparison, most other gems on the Ruby Gems site have, on average, a few thousand downloads.

Keen to find out more about Duncan’s work and how this gem came to be, we jumped on Zoom for a chat.

 

 

Hi, Duncan. So to kick things off, can you give us some background on your QR code gem, and what had prompted you to start developing it?

It was 2009 and I was working for the BBC, specifically on a project called BBC Programmes. The idea was to create a permanent record of everything the BBC has ever broadcast – a record that is being constantly updated.

The BBC were, as always, creating lots of publicity material for the programmes they were creating. They wanted to point people to a programme website, but the wider team found that they were putting URLs onto posters and it was proving quite difficult for people to put them into their phones at the time (the first iPhone had just come out). So we had this idea.

There was about five of us working on the project, we were all quite future-thinking, and we all wanted to do what was the best at the time. Around the same time, we were seeing these things called QR codes gaining popularity in Japan. I'd read about them and I thought they were interesting.

The reason that they’re used in place of more traditional barcodes is their better approach to error handling. You can pretty much tear one in half and still read it – that's by design. So with the challenge around promotional materials for this website, we decided to pursue the idea of using QR codes – which was quite a big deal at the time. Back then they weren’t as commonplace as they are today. 

 

 

The QR code technology was owned and trademarked by a company called Denso Wave, and with it not being open source, you couldn’t easily get hold of it. But I found a JavaScript library by a Japanese developer, and it could generate QR codes.

At this time I was fairly new to Ruby, only having used it for a few years. And I thought, well, this might be a good way for me to learn how to build a Ruby gem by converting this JavaScript library into Ruby. It seemed a good idea as we were using Ruby on Rails inside the BBC.

So I took a stab at it and managed to get it working. And as I was working through, I also was doing some experiments. Writing out these QR codes, I realised that with the error correction, you could write stuff onto these QR codes and it wouldn't affect its readability. The BBC logo seemed a good fit for a QR code in that it's quite blocky. I found out that I could draw the QR code and then draw the BBC logo into the middle of it. And it worked. We added that to the BBC site and that got lots of press and lots of people excited.

You can read more about that here.

 

Duncan is a Senior Software Engineer and has been with Kyan since October 2012.

 

And once the press coverage died down, how was the gem itself received?

The Ruby library was used a fair bit, but it didn't really get a huge take up initially because it was still fairly new. But I thought it was a good project to keep managing, and as it evolved, people began to help me because Ruby was quite new at the time, and there were a number gotchas in Ruby around encoding things.

People would send me PR requests and say “Look, you could do this… it could be more efficient.” And that was great. As more features were added it really gained popularity, particularly because you could do cool things like make it into an image. By this point, I had just had my son, so I didn't have much time to look at it. So I asked the community if there was anyone out there who could manage it for a bit.

A developer from Sweden volunteered and he managed all future contributions to the library. He was the gatekeeper. And that was fine, and the QR code library carried on, but then about five years ago, I decided to take a look at it, having a bit more time.

 

 

There were dozens and dozens of new features, all kinds of things. I felt it had become bloated. It was called ‘QR Code’ because that's all it did. It generated a QR code and that was it. I didn't want it to do anything else, and if people did want it to do bigger or better things, then other gems could be created for that.

He'd let so many new features in that you could do all sorts… you could create QR code and turn into an image, a CSV, anything you like. The problem here was that I didn’t want to manage something that was so far from its original intention. Almost all new requests and issues were about the presentation and not the QR code generation itself.

This was where I learned just how much work is involved in creating a gem. It’s not just writing code, it’s managing people's expectations.

And how is the gem doing now?

In recent years, and exacerbated by to a lesser extent COVID, QR codes are everywhere. It went from having a couple of million downloads (that I thought was a lot) to almost 20 million, which is pretty mind blowing and slightly terrifying at the same time. But it's included in lots of popular gems now, mostly to aid 2FA authentication. And every website needs authentication. So chances are it's pulling in my library. So yeah, it's just gone a bit crazy but fortunately and because of that, it's very stable, and most if not all of the bugs have been ironed out.

 

 

I’ve heard through the grapevine that you had people messaging you on Christmas Day asking for a fix. What was that all about?

They've just recently brought out Ruby 3.0, which was being worked on for a while. And I've known it's been worked on for a while, but I haven't really thought about it in regards to my gem, which I guess I should have. On Christmas Day when Ruby 3.0 was released, I received loads of emails and messages of people saying “Your gem doesn't work on Ruby 3.0!”

It was a small thing. When you have a gem, you have to put the minimum version of various things that it will work with it. And I inadvertently said that it would work with any version up to a certain ‘point something’. I hadn't added the ‘three point something’. So obviously, as soon as Ruby 3.0 came out, it just didn't work and wouldn't install. It all went a bit crazy, and part of me thought “I’d rather not be doing anything on Christmas Day”, but I realised it was only a couple of lines of code, so I just did it later on in the day, and resolved the issue.

I guess there's a message in here about seeing the value in something early – you saw the value in the QR code very early on and you stuck with it.

When I created the gem, it didn't have to be fancy. It did the lowest common denominator thing. Which you hear about a lot in product design. And that's what I wanted for this gem.

If you want to design a really good product, remove all of the crap and just do the one thing that it does well.

 

You can check out Duncan's gem, plus some other useful pages via the links below:

rubygems.org/gems/rqrcode
github.com/bbc/BBC-QRCode-Generator
derivadow.com/2008/01/21/qr-codes-for-bbc-programmes-and-some-other-stuff/

Previously from Duncan:

Building our own office Jukebox using Mopidy, Node.js and React

 

We are Kyan, a technology agency powered by people.