Månadsarkiv: maj 2016

Event storming

Detta inlägg finns även att läsa på HRM Softwares teknikblogg!

Lately I’ve spent some time catching up on what’s happening in the Domain-Driven Design (DDD) community through watching sessions recorded at the Domain-Driven Design Europe 2016 conference. The session I watched yesterday was about something called event storming – a concept that was new to me but so simple and seemingly powerful that it got me quite worked up. The purpose of this blog post is not to go into details of how event storming works, but rather to convey my initial thoughts of why the idea is worth thinking about.

When running an event storming workshop you only need a few basic things:

  • post-it notes with different colors
  • a lot of space to place the post-it notes on (e.g. a large whiteboard or a paper roll)
  • the right people

The right people are key in event storming and should involve a moderator, developers, domain experts and other people involved that can contribute when storming away at the problem at hand.

Domain events

With all these smart people gathered in a room, you start with identifying a few core domain events. A domain event is formulated as something important that can happened in the domain under analysis, e.g. ”ticket purchased” or ”seat reserved”. As you can see, domain events are always expressed in past tense. Each domain event is written down on a post-it note with a specific color – the resources I’ve found online so far suggests orange stickers by convention – and placed on the whiteboard from left to right in order of occurrence in the business process we are analysing. This means that we get a visual representation of the business process flow to see when the various domain events occur.

Commands

During the identification of domain events we also need to ask ourselves how they are triggered. For instance, the domain event ”ticket purchased” might be a consequence of a user placing an order via a web application. The act of placing an order is, in event storming terms, a command. A command is something that generate domain events and is expressed through blue post-it stickies. Commands are formulated in present tense, e.g. ”purchase ticket”, and placed on the whiteboard just before the domain event(s) that are generated as a result of the command. For example, a ”purchase ticket” command should probably be placed just before the ”ticket purchased” domain event to signal that they belong together.

The flow of the workshop

With the two core concepts of commands and domain events, the participants of the workshop keep exploring the problem area to gradually refine and expand it. As the notion of event storminig stems from DDD, we take extra care to capture the ”ubiquitous language”, i.e. we want to make sure we are naming things so that it makes sense for the business problem we are trying to solve. Participants in the workshop are encouraged to question things, no matter how trivial they may sound. Is ”ticket” really the correct word? Is it to general?

It is during the ongoing discussion, with post-its being replaced and moved around, we hope to nail the complexity of the domain problem. Suddenly, a domain expert states that there should be a way to reserve tickets. And by the way, you should be able to get a refund if you cancel your ticket purchase within a given amount of time. The complexity of the problem gradually reveals itself, captured in a process time flow and grouped by commands and domain events on a whiteboard covered with colored post-it stickies.

What do we get out of this?

It should be noted once again that I’ve not actually tried this workshop format, but in my mind it really makes sense. The idea is super simple and the potential outcome of it is interesting in several ways. First and foremost, we can express the components of a problem we are trying to solve (and how they relate to each other) with terminology that comes directly from the domain experts. Another neat thing is that commands and domain events map really well to implementation. They are a natural fit for CQRS and event sourcing, but when you think about it, commands and domain events can be mapped pretty well to any kind implementation technique. Something triggers an action (command) that produces some kind of result (domain event).

Final notes

Event storming include more stickies for e.g. highlighting actors, UIs and domain models. Moreover, as we are in the DDD world, we can map related commands and events to a particular aggregate and express that directly on the whiteboard by simply grouping them together. The same goes for bounded contexts; to group aggregates into a bounded context you just draw a line around the involves post-it stickers with a whiteboard marker.

For those of you versed in DDD, we can start drawing a context map from here, but that’s the topic of a blog post for a later time.

This blog post was authored by Martin Moberg.

Trash Friend

Detta inlägg finns även att läsa på HRM Softwares teknikblogg!

Last week me and some colleagues took part in a hackathon here in Växjö. This hackathon was one of many events that took place during something called Digitala veckan, an entire week packed with IT-related events around the Linneaus university region. For those of you new to the concept, a hackathon is basically a competition in which programmers hacks away at a problem in a limited amount of time. In this particular hackathon, the challenge was to combine open data sources on the web and produce something useful for making our environment better. While HRM had two teams enlisted in the competition, this blog post is about our contribution. Say hello to Trash Friend.

The rationale for Trash Friend came to us while struggling hard figuring out what to do. We had been provided a list of example open data sources in-line with the overall environmental theme, but the data sources were admittedly not all that great and not always up to date. Moreover, our friends in the other HRM team were hacking away like crazy right from the start with a pretty neat idea, which made at least me feel a bit stressed out. We did come up with a few kick ass ideas right from the start too, but the open data sources were not fitting in nicely in any of those. What to do?

Figuring out what to do

After some headache we finally settled on an idea that were nicely motivated by another colleague of ours during a coffee break. One of the provided open data sources contain information about cars entering one of the recycling stations in Norremark, Växjö, and while brainstorming he said something like:

”They should have a webcam over at that recycling station. The queues can be terrible over there and you never know until you actually get there.”

Now, we did not have access to a webcam or any live data, but we did have access to the data set I just mentioned, which contained statistics over the course of a few months. It included data such as the time of visitors entering the station, the length of the cars (!) and the speed of the cars passing through the sensor. The latter two were not that useful for us, but the time of entry had some potential. Although there were no information about when cars left the recycling station, you could take a wild guess and say that the average time for a visitor staying at the recycling station is, say, fifteen minutes. Not that we actually had any coverage for that estimation, but for a hackathon such as this that estimation was perfectly fine.

With the time of entry and an estimation of how long visitors were hanging out at the recycling station, we could take a particular point in time, for example at three o’clock Friday afternoon, and calculate the expected number of visitors at that time. The algorithm we used to calculate that approximation was to historically look at the visitors to the station at that time on that particular weekday. From all of these occurrences we simply came up with an average to make the approximation somewhat reliable, that is, taking all Friday afternoons at three o’clock into account.

The idea

So, the idea we had was to make recycling easier for citizens and to relieve them from long queues at the recycling station. Such a tool has the potential to be beneficial in several ways:

  • Avoid a high load of visitors; if a citizen has a way to find out that the queue to the recycling station is long s/he can decide to wait before deciding to pay a visit.
  • Reduce the emission level at the station; cars in queue means that there will be more emissions, which leads to our next point.
  • Improve the work environment for employees at the station; less emissions and less visitors at peak hours.

There are probably more points to such a list, but let us settle for those and head over to implementation details.

Implementation

With the algorithm in place for calculating the number of visitors at the recycling station at a given point in time, we had one more crucial nut to crack – the information had to be super-easy to get a hold of. Would a web site do? For some cases yes, but remembering the URL of that particular site you tend to visit occasionally would not cut it. We wanted something that was just there when you needed it. Perhaps a notification could pop up in your smart phone when things are looking okay at the recycling station? Notifications are nice and all, but how could we possibly know when the citizen wants to recycle their trash? No, we needed something accessible that the citizen could consult when needed. And for this purpose a widget felt just right.

We finally settled on an architecture that involved three central components, described in more detail below.

RESTful web service

As the recycling central station data was encoded in a csv-file, we decided to crunch it and expose it in a format more suitable for our needs (i.e. JSON) via a simple RESTful web service. The technologies we chose for these tasks were Java and Spring Boot. With Spring Boot we had a RESTful web service up and running in no time, which was perfect for the time pressure we had during the hackathon. Aside from the recycling station data, service we build also included weather data. The weather data was fetched from an open weather data API and adjusted to the needs of the widget to inform the citizen about the weather conditions at the station. I mean, it is no fun to recycle your trash when it is raining.

Trash Friend Widget

The widget was developed for Android using Android Studio. This was the first time for me developing a widget, but after a while I got a hang of it and the result came out quite okay for a UI novice like me. As seen in the screenshot below, the widget presents a colored cycle to the far left. This icon indicates the status on the recycling station with one of the three colors red, yellow and green. A red circle tells you that you should wait your visit to the station for a later time, a yellow circle means that you probably will be in queue for a little while and, finally, a green circle means thumbs up, you should stop what you are doing and head over there right away.

The Trash Friend Widget

For a more concrete approximation (if there is such a thing) the text to the far right tells you the approximated number of visitors at the station at the present time. Finally, the weather icon show the weather conditions over at the station at the present moment. The information in the widget is updated every 30 minutes, which in my mind is acceptable as we are not dealing with live data (at least regarding visitor data).

But what if the queues are terrible right now? When should I go? To answer this question, the user simply taps the widget to launch the Trash Friend web application.

Trash Friend web application

The purpose of the Trash Friend web application is to answer questions just like the ones asked in the closing sentences of the previous section. When the widget is tapped, the default browser in your mobile phone fires up with an overview of the expected load of visitors at specific times throughout the current day (see figure below).

The Trash Friend web application

One can easily switch to a weekly overview by tapping the button ”Veckoöversikt” in order to see how the situation at the recycling station is expected to be later on during the week. This web application was developed using the Ionic Framework to make it mobile friendly right from the start.

Summing up

So there you have it. In just a couple of hours we went from frustrated to pretty satisfied with what we had produced. And while we did not win the hackathon (due to stiff competition of course ;)) we pulled through and produced something that, if polished a bit, at least in my mind would be a valuable tool for citizens living near this large recycling station. If all recycling stations in Växjö would start to gather entry data it would be quite easy to improve the design to let citizens select their station to track in their widget. In Android, the way to configure widgets is to flip them over and adjust its settings. Imagine if available stations were available in a list in which you could select the station to track? A tap on the widget would then, naturally, direct the browser to the statistics at that particular station.

That’s all for this time, keep hacking! 🙂 By the way, the code we wrote is MIT licensed and available on GitHub.