Select Page
“Event sourcing” a briljant way to “go back to the future”

“Event sourcing” a briljant way to “go back to the future”

What is event sourcing?

Instead of storing just the current state of the data in a domain, use an append-only store to record the full series of actions taken on that data. The store acts as the system of record and can be used to materialize the domain objects. This can simplify tasks in complex domains, by avoiding the need to synchronize the data model and the business domain, while improving performance, scalability, and responsiveness. It can also give consistency for transactional data, and support full audit trails and history that can enable compensating actions. “Source: Microsoft docs”

Difficult words, isn’t it ? So how do i understand that as a junior. Event sourcing is recording the state from an object, the state in the universe as u can understand. So what can you do with that recording, its like what happened is happened, it’s recorded and can be found back in the history. A blockchain in cryptocurrency is an example ( Read my next post about cryptocurrency). Actually every accountancy is an example, also a shopingcart (digital) like showed in the image bellow.

u see what happened? I’ll explain, if you have a shopping cart see it as a stream. So we are gonna add some events on the stream. Like “Added 2 socks” this is an event that will be added to the stream. On that stream u will have consumers, consumers that are gonna read every event on the stream. If the event does have an effect on his job or task, then it will trigger a handler. Like the stock manager knows now that there are going to be 2 socks sold. Idem about the next event that has “Added 4 shirts” now he know’s that there are 4 shirts to be sold. The next event will remove 2 socks that you added earlier, you don’t delete the event cause the event has happened. You just counter it, the next event is “shipping information added” here will the shipping manager know where to send the bought stuff to. Like i told earlier is that you will have consumers. Let’s talk a bit more about that.

Consumers are reading the stream. What can an example be like here above u have like the stock manager and the shipping manager. Every consumer has a handler on a specific event. Like the stock manager only want’s to know what happens with his stock and he doesn’t care about the “shipping info”, the shipping manager doesn’t care what the customer does with the cart but he wants to know where to send it to and what to send.

Lets use an example in coding. So you make a producer and a consumer, the producer will add events on an eventstream and a consumer will read it. Don’t you get it ? Let me show it.

As you can see there are consumers and producers. What i didn’t add to this picture is the possibility that a consumer also can be a producer. Cause everyone that want’s to write an event on the stream can do that as a producer.

event sourcing is mostly used in CQRS desing pattern.

Why can it be handy?

Let’s take the shopping cart example back. If a costumer leaves his shopping cart but did not finish it. You can recover he’s cart the next moment that he visits the shop again. Another example if you work in an accountancy you can follow perfectly what happened and react to any mistakes that his happened along the stream. Another example, what if your database drops or you make a huge mistake and your back-ups are gone? Then can event sourcing be your solution, cause u can replay every message on your streams from the begin of the stream to the end of your stream and it will trigger all your actions again, so it will rebuild your database again. You can debug in time, you even can go back in time of the event stream of course. You can query over time and see events or replaying them, it can make you a time manager.

Why can it be a pain in the ass ?

It’s not easy to implement and control, you need to change your mind of thinking to the right solution. You don’t have 1 big flow. consistency is hard to hold.


What are great event sourcing tools?


Apache Kafka

event hubs

AggregateSource (on github)




Started a project

Started a project

A colleague of my started a project with a mate, it’s about a trading bot for bitcoins. simple intelligence behind for the sharing, Buy when low Sell when High. I also wanna work on it and did some changes in it, wanna make nice interface en more choices for using all the currency’s So i make this project open-source just to make it better and smarter, feel free to join in. The github repository is : Any Questions ? just ask.

a starting sample app

a starting sample app

So after a few introduction posts its time for me to trying to put here some real work.
So to my opinion is it very handy to make yourself a starting template where you launch every app from.

I hear you think… Why in the “damn god” would i do that? Simple if you make a few apps and use the same language gonna take for example Angular 2,
and you start from a sample app or starting template. Then it is time-saving, cause after all there are some generic components that you use every time like:

  • home Component
  • navigation
  • loadingscreen
  • footer
  • CRUD services
  • base css -> bootstrap
  • some handy npm packages
  •  …

so actually the only stuff you need to do then is

  •  npm install
  •  change the app name

and there you go !! A fresh app to create and you saved in the beginning of you programming career a lot of time. Even later it is.
so if you think about it? You’ll see that it is very handy to use those starting things. But hey its still my opinion of course.