Hot aggregate detection using F#

Last week, I wrote about splitting a hot aggregate. Discovering that specific hot aggregate was easy; it would cause transactional failures from time to time. Long-lived hot aggregates often are an indication of a missing concept and an opportunity for teasing things apart. Last week, I took one long-lived hot aggregate and pulled smaller short-lived hot aggregates out, identifying two missing concepts. Hunting for more hot aggregates, I could visualize event streams and use my eyes to detect bursts of activity, or I could have a little function analyze the event streams for me. ...

November 16, 2014 · 2 min · Jef Claes

Programmatically force create a new LocalDB database

I have spent the last week working in an integration test suite that seemed to be taking ages to run its first test. I ran a profiler on the setup, and noticed a few things that were cheap to improve. The first one was how a new LocalDB database was being created. An empty database file was included into the project. When running the setup, this file would replace the existing test database. However, when there were open connections to the test database - SQL Server Management Studio for example - replacing it would fail. To avoid this, the SQL server process was being killed before copying the file, waiting for it to come back up. ...

October 26, 2014 · 2 min · Jef Claes

Print out the maximum depth of recursion allowed

Karl Seguin tweeted the following earlier this week: “An interview question I sometimes ask: Write code that prints out the maximum depth of recursion allowed.” This question is interesting for a couple of reasons. First, it’s a shorter FizzBuzz; can the candidate open an IDE, write a few lines of code, compile and run them? And second, does he know what recursion is? Now let’s say, the interviewee knows how to write code and is familiar with the concept of recursion. If he had to do this exercise in C#, he might come up with something along these lines. ...

October 19, 2014 · 2 min · Jef Claes

Read an Event Store stream as a sequence of slices using F#

I’m slowly working on some ideas I’ve been playing around with whole Summer. Since that’s taking me to unknown territory, I guess I’ll be putting out more technical bits here in the next few weeks. Using the Event Store, I tried to read all events of a specific event type. This stream turned out to be a tad too large to be sent over the wire in one piece, leading to a PackageFramingException: Package size is out of bounds. ...

October 5, 2014 · 2 min · Jef Claes

Glueing the browser and POS devices together

I have been occupied building a modest Point of Sale system over these last few weeks. Looking at implementing the client, there were two constraints; it needed to run on Windows and it should be able to talk to devices such as a ticket printer and a card reader. Although we could use any Windows client framework, we like building things in the browser better for a number of reasons; platform-independence, familiar user experience, JavaScript’s asynchronous programming model and its incredible rich ecosystem. Having to talk to devices ruled out leveraging the browser to deliver our application though - or didn’t it? ...

May 4, 2014 · 3 min · Jef Claes

Rebinding a knockout view model

As you might have noticed reading my last two posts, I have been doing a bit of front-end work using knockout.js. Here is something that had me scratching my head for a little while.. In one of our pages we’re subscribing to a specific event. As soon as that event arrives, we need to reinitialize the model that is bound to our container element. Going through snippets earlier, I remembered seeing the cleanNode function being used a few times - which I thought would remove all knockout data and event handlers from an element. I used this function to clean the element the view model was bound to, for then to reapply the bindings to that same element. ...

April 6, 2014 · 2 min · Jef Claes

Sending commands from a knockout.js view model

While I got to use angular.js for a good while last year, I found myself returning to knockout.js for the current application I’m working on. Where angular.js is a heavy, intrusive, opinionated, but also very complete framework, knockout.js is a small and lightweight library giving you not much more than a dynamic model binder. So instead of blindly following the angular-way, I’ll have to introduce my own set of abstractions and plumbing again; I assume that I’ll end up with a lot less. ...

March 23, 2014 · 3 min · Jef Claes

Building a live dashboard with some knockout

Last week, we added a dashboard to our back office application that shows some actionable data about what’s going on in our system. Although we have infrastructure in place to push changes to the browser, it seemed more reasonable to have the browser fetch fresh data every few minutes. We split the dashboard up in a few functional cohesive widgets. On the server, we built a view-optimized read model for each widget. On the client, we wrote a generic view model that would fetch the raw read models periodically. ...

March 16, 2014 · 1 min · Jef Claes

Alternatives to Udi's domain events

Almost four years ago Udi Dahan introduced an elegant technique that allows you to have your domain model dispatch events without injecting a dispatcher into the model - keeping your model focused on the business at hand. This works by having a static DomainEvents class which dispatches raised events. This customer aggregate raises an event when a customer moves to a new address. public class Customer { private readonly string _id; private Address _address; private Name _name; public Customer(string id, Name name, Address address) { Guard.ForNullOrEmpty(id, "id"); Guard.ForNull(name, "name"); Guard.ForNull(address, "address"); _id = id; _name = name; _address = address; } public void Move(Address newAddress) { Guard.ForNull(newAddress, "newAddress"); _address = newAddress; DomainEvents.Raise(new CustomerMoved(_id)); } } By having a dispatcher implementation that records the events instead of dispatching them, we can test whether the aggregate raised the correct domain event. ...

March 2, 2014 · 2 min · Jef Claes

Reading an EventStore stream using JavaScript

Over Christmas break, I set out three days to play with the EventStore. One of the things I wanted to do was visualize the timeline of a stream in the browser. Since the EventStore exposes its event streams over atom in JSON, I could directly consume them from JavaScript. An event stream can contain quite a few events. Since caching parts of that stream benefits all components in the system, the atom feed is split in multiple pages - where all full pages are cacheable. Thus if you want to read the entire event stream, you should work your way through all pages. What confused me at first, but what actually is quite logical, is that the last entry on the last page contains the first event. If you want to read the entire stream, you need to start at the last page, and work your way forward following the link to the previous page until there are no pages left to read. ...

February 9, 2014 · 3 min · Jef Claes