Spinning the wheel: manipulating the odds

The previous post defined a basic set of data structures and functions to spin a wheel of fortune in F#. There was very little mystery to that implementation though. The physical wheel had four pockets and spinning the wheel would land you a win one out of four spins. As a casino, it’s impossible to come up with an interesting payout using this model. To juice up the pot, casinos started adding more pockets to the wheel of fortune. This meant that the odds were lower, but the possible gain was higher. More pockets also allowed casinos to play with alternative payouts, such as multiple smaller pots instead of one big one. ...

December 11, 2014 · 2 min · Jef Claes

Spinning the wheel

In this post, I’ll define a basic set of data structures and functions to spin a wheel of fortune. In the next post, I’ll show you the simple model casinos use to build a bigger, more attractive pot, without touching the physical wheel and without losing money. Finally, I’ll show you how casinos tweak that model to bend the odds and create near misses. Let’s say we have a physical wheel with four pockets, which are labeled either miss or win. ...

December 9, 2014 · 2 min · Jef Claes

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

Splitting hot aggregates

When you visit a real casino, the constant busy-ness is overwhelming; players spamming buttons, pulling levers, spinning the wheel, gambling on the outcome of sports games, playing cards, feeding the machine, cashing out, breaking bills, ordering drinks or even buying a souvenir. A single player will easily generate a thousand transactions in one sitting. When you look at an online casino, this isn’t very different. In the system we inherited, the biggest and busiest aggregate by far is a user’s account. Basically every action that has money involved, leads to activity on this aggregate. This makes sense. An account is an important consistency boundary, if not the most important one. Casino’s can’t afford to have people spend more than their account’s worth. ...

November 9, 2014 · 4 min · Jef Claes

Thinking No Computers

The other day I happened to see a curious exchange in one of our businesses. The cashier swapped a torn, but carefully restored by taping it together again, Euro bill for a new one with the manager. Inquisitive, I asked the manager what he was planning to do with that Euro bill. “Once a month, I take all those ripped up or badly worn bills to the National Bank, and trade them for new ones. All you need is one piece of the bank note for them to give you a newly printed one.” ...

August 19, 2014 · 3 min · Jef Claes

Not about the UI and the database

When you ask an outsider which components an average application consists of, he will most likely be able to identify the user interface and the database. He will also recognize that there is something in between that takes the input from the user interface, applies some logic and persists the result in the database. In the past, trying to make sense of what goes on the middle, we started ...

June 1, 2014 · 2 min · Jef Claes

NCrafts Eventstorming slides

Me and Tom just finished doing our Event storming workshop at NCrafts Paris. Although we made a few mistakes along the way, feedback on the workshop was great. I hope to put something out about what we learned facilitating later this week. People talked, discovered and eventually learned a new domain in under two hours. The domain? Two minutes before the workshop we found a domain expert prepared to talk about his coupon start-up. ...

May 16, 2014 · 2 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

Strategic DDD in a nutshell

There are two big parts to Domain Driven Design; strategy and tactics. Strategy helps setting out a high-level grand design, while tactics enable us to execute on the strategy. Practicing strategic design, we generally first try to list all of the different parts that make our business a whole; these are sub-domains. When you look at a supermarket chain, you would find sub-domains like real estate management, advertising, suppliers, stock, sales, human resources, finance, security and so on. Sub-domains will often relate to existing structures like departments and functions. ...

February 23, 2014 · 4 min · Jef Claes

Repositories, where did we go wrong?

In essence, repositories are a simple abstraction over aggregate storage. A repository will insert, update, delete or fetch an aggregate from the underlying persistence mechanism. This abstraction avoids that databases, SQL statements, Object Mappers and the like leak into your domain. Next to that, swapping out repositories for an in-memory version makes testing easier. Recently, the use of repositories is being questioned again. Why would we wrap Object Mappers in yet another abstraction? Aren’t Object Mappers already an implementation of the repository pattern? In a recent project, we left out repositories. In that project we’re using RavenDB, which already has an expressive API, and which can be configured to use an in-memory database for testing. Even though LINQ and indexes help make simple queries expressive, a lot of cruft still leaks in, not doing the language any justice. In other projects, we did make use of repositories over our ORM. Partly because setting up in-memory tests without was awkward at best, but also because it removed constraints trying to capture the language. Next to testing and expressiveness, you should also consider how comfortable you feel gluing everything to a library or framework. When it comes to aggregate storage, having those repositories is a small price to pay to keep technicalities out. ...

January 26, 2014 · 3 min · Jef Claes