CQRS and Event Sourcing at Hull Developers

Hull Devs is going from strength to strength. Hot on the heels of the talk last month we have another great talk, this time from Mathew McLoughlin who told us all about CQRS and Event Sourcing. At the start of the evening I had no idea what any of this was about. But by the end of the evening I was up to speed. 

CQRS stands for Command Query Responsibility Separation. But knowing that doesn't really help you understand it at the start. The Event side of things is a much better place to begin.

If you are implementing something complicated (Mat used hospital admissions as an example) you could do this by having a record for each item in your system. You could fill a patient object full of things like like name, age, whether the patient is in the hospital, their ward number etc etc. Your system could then update these records each time the patient changes state.

This would store the data, but if you work this way a lot of information gets lost. If you want to know which wards a patient has been treated in, then a system structured like this will not be able to tell you. Furthermore, you're not really capturing what is going on, which is that people are arriving in the system and stuff is happening to them. Instead you're forcing users to update small parts of a large data object (the patient record) each time. 

Rather than looking for the data you need to store, better to look for significant events in the trajectory of your objects, and build a system that captures these events. When a patient arrives, moves wards, gets test results and finally goes home, you record these events and your system can then then "play through" them to build a picture of the current state of your patient. It's a very nice way to work. Want to find out the state of your hospital last week? Just run the events to that point and stop. This reminded me a bit of "block chain" currencies where the movement of a lump of money is traced from person to person as it is used to pay for things.  

Mat suggested "Event Storming" meetings with the customer to identify events  and what effect they have on object state. This involves lots of paper, post-it notes and the development of a common language between customer and developer. And sounds like fun. 

OK, but what about CQRS? Well, events are a great way to get stuff into a system, but if you want to view the state of your data you have to do a bit of work. The "Command Query Responsibility Separation" part really means that "projections" of the data in response to queries should just consume events and use them to build the view of the data. The storage of the events should be the responsibility of a totally separate process. This makes the design of the system much easier. The only downside is that your view of your system may be a tiny bit behind the times, as your projection updates in response to events, but in a modern implementation this should not be a problem.

It was a great talk, very interesting. Mat has built some C# that demonstrates this which you can find here. I'm looking forward to the next one. 

Thank you, Windows 10

I'm rather liking the Windows 10 Creator's Edition Fall Update Feature Release 1709 for x64 based Systems (KB4041994).

It's full of little changes that just make everything that bit better. Like the way that the Onedrive sync status is now showed in a separate column, rather than on top of the file icon so that I couldn't tell what type of document I was looking at. 

On tip though, after the upgrade I was a bit worried that my system disk had suddenly got a lot smaller. I managed to free off 41 GBytes just by deleting previous Windows installations. 

Network your 3D Printer with Windows 10 IoT Core. If only.

I've installed Windows 10 Creator's Edition Fall Update. It's very nice. It has a lot of extra support for 3D printers. And I got all excited when I found out that there's an application for the Windows 10 IoT Core running on Raspberry Pi that lets you install your printer on the network and then print to it straight from Windows 10.

It doesn't work. At least, not for me. I've spent all afternoon creating SD card images, configuring them and then finding out that I always get assigned the same (wrong) printer device and then the driver fails to load. 

Oh well. 

Lora Networking Hardware

Had a rush of blood to the head today and ordered a complete Lora networking kit from Tindie. Only slightly more expensive than a video game and a lot more fun. I'm going to set up a test Lora network in Cottingham for folks to connect their sensors. It's only a single channel gateway (hey - I'm not made of money) but it should be good for up to fifty sensors or so. . 

Then we can work out what to use it for......

Plenty of Hardware at c4di

We had a great meeting at the Hardware meetup this week. We had digital video, DC motor control, Lora networking and transistor insights. And some new faces. If you want to come along you can sign up here

This is what I was working on. I had another Lora node receiving the messages. When it works properly I'm going to take the plastic cover off the display.....

Remote Harmony

Today I spent a little while sorting out the remote control for the telly. I bought this fancy Harmony Remote a while ago in a second hand shop and I think it has turned out to be quite a bargain. I've used Harmony remote controls for a very long time and I've round that they work very well, within the limitations of a totally open loop control system, where the remote just pumps out an infra-red message and has no way of knowing if it has been received or not.

Anyhoo, configuring the remotes is something I don't do often enough to be able to remember all the steps involved. But I do know that I'll have to download a program and then plug the remote control into the computer. I'm using a version of Windows that is several on from the one for which the program was created. I'm installing a USB driver that was written ages ago. I'm using TVs and devices that are comparatively recent. And yet it all worked. The Logitech servers even remembered the settings from last time (because I'd put my Logitech username and password into Password Padlock). Now I can turn on the TV with a single touch.Very impressive.

Broken Device Dilemma

Here;s the thing. Something I hardly use has broken. Do I:

  1. Take it as a sign that I don't really need this device in my life any more and move on.
  2. Take it as an opportunity to investigate the problem and try to get the thing working again, even though I'll hardly ever use it when it is fixed.

I think you know the answer to this question. I've ordered a replacement cable, just in case that is the cause of the problem....

The Lure of Lora

I was on AliExpress the other day, always an expensive experience, and I happened upon some boards from Heltec that offer an ESP32 (the upgrade of the ESP8266), a tiny OLED display and, most interesting, a connection to the Lora network. I've been meaning to spend some time playing with Lora for a while. It offers low power networking with a range that can go up into kilometres. At first I ordered one, and then it occurred to me that a network with only one node isn't really a network, so I got a couple more. 

They arrived on Friday the 13th last week and, much to my surprise given the date, they worked first time. I downloaded the sample programs, added them to my Arduino IDE installation and in no time at all I had two of the devices talking to each other.

Later on I discovered that I have been a little unlucky/stupid in that I've bought versions that work on the 433 MHz radio band, which is not the frequency that works the best for these devices. For the UK I should have bought the version that supports the 868 Mhz band that is used in Europe

Never mind. I can still use them, but I'll get more interference because this band is used by radio amateurs, car keys and building alarms etc. I'm looking forward to finding out more about how the network can be used. 

Jurassic Kingdom Tour

Today finds us at the Jurassic Kingdom Tour in Leeds. Apparently they are going all around the country setting up their dinosaurs in different venues. I bet they look awesome on the back of lorries as they zoom down the motorway. There were lots of dinosaurs of various sizes, most of them moving around a bit and making sounds. Some exhibits were a bit spoilt by plaques stating that "actually this combination of dinosaurs could never happen" but at least they didn't have any cave men fighting with them, which even I know would be quite beyond the pale. 

It was great fun and they also had someone selling 21st century donuts. Which was really nice. 

Farewell Windows Phone

This is still my favourite my favourite ever phone. I got it nearly four years ago. Four years. That's several phone lifetimes ago. It has wireless charging and a fantastic OLED screen. Just like the phone that Apple are touting as revolutionary but haven't started selling just yet.

I found my Windows Phone far easier to use than anything else. It was as if a bunch of people had looked at iPhone and Android and asked "I wonder if we can do this better". Turns out that they could, but nobody cared. And now Microsoft have announced that they don't see mobile devices as a priority any more. Oh well.  

I've always seen things like phones and whatnot as pendulums swinging around. Microsoft had the mobile space to itself for quite a few years, then the pendulum swung to Apple and Android. Perhaps when Apple manage to properly drop the ball with the iPhone and people get annoyed with buggy Android devices that never get patched we might see a return to Microsoft. 

Until then I'll get my wonderful Windows Phone out every now and then, play with it and wonder at what might have been. 

Building shelves

Today I spent a while building some Ikea bookcases (it's always like this when I finish writing something - I have a frenzy of DIY followed by an abrupt return to usual levels of torpor).

I've a lot of respect for Ikea stuff. I get the impression that they have really thought about process whenever they put together their kits. I guess it is really Lego for grown-ups. Or perhaps Lego for people who want to think they are grown up every now and then. 

Sofa so good

If you've ever wondered whether an Ikea Vilasund sofa bed will fit in the back of a BMW i3 it turns out that the answer is yes. But only just. However, beware. It turns out that buying a sofa can be just the start of a chain reaction of effort. At least it was for me. 

  1. Dismantle old sofa.
  2. Take old sofa to tip.
  3. Move large sofa out of way.
  4. Build Vilasund sofa in place of large sofa.
  5. Empty other room.
  6. Remove carpet from other room.
  7. start laying laminate flooring in other room.
  8. Find out you've not bought enough flooring.
  9. Buy more flooring. 
  10. Lay it. 
  11. Find out that you've still not bought enough flooring. Question arithmetic skills where area calculations are concerned. 
  12. Buy more flooring. 
  13. Finally complete the floor.
  14. Put large sofa in other room. 
  15. Take more rubbish to tip.
  16. Rebuild other room.
  17. Buy nice rug and fit same.

We've finished now. By a process of considerable effort and expenditure we've just about got back to where we started.

Science Superheroes on the Stage

Today was the day that we all headed for London to do our talks for the Secret Science of Superheroes (in the shops now). We all wrote the book last year at a book sprint in Manchester. We wrote a chapter each. And today chapter writers had five minutes to tell the assembled multitude what they had written. I was on last, which was probably for the best...

Anyhoo, a great time was had, lovely audience. Before the talk we got to spend some time in the Lord Mayor's Chambers in South Kensington, which was most impressive. Then after our talk we had a splendid meal at the Elephant and Castle and then staggered back to the hotel and collapsed for the night. 

I think we'll find some culture tomorrow.