From Monoliths to Microservices using CQRS and Event Sourcing Download
In a Microservices architecture state is distributed across many applications and databases. Keeping all the microservices consistent is a non trivial task and here is where CQRS and Event Sourcing really shine.
In this workshop we will move from a terrible Monolith to a nice Microservices app using CQRS/ES as the middle man. The recipe to Microservices that we will follow here will be:
- Start with an ugly Monolith.
- Add some CQRS and ES to the Monolith using Spring Streams and Apache Kafka.
- Break your CQRS Monolith into small microservices using Spring Cloud.
You must have a working installation of GIT in your machine (Git Downloads)[https://git-scm.com/downloads]. You can test that it works by running the following command:
$ git clone https://github.com/manuel-alvarez-alvarez/microservices-workshop.git
By the way, it will clone the main repository for the workshop (two birds one stone).
Make sure you have a working installation of the JDK 8 in your machine (Java SE Development Kit 8 Downloads). You can test it by running the following command in a console:
$ javac -version
You must have a working installation of Docker as well, the community verison will work just fine (Download Docker Community Edition). You can test it by running the following command in a console:
$ docker run docker/whalesay cowsay Ready to rock
You should see something like this:
_______________
< Ready to rock >
---------------
\
\
\
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\______/
In order to prevent downloading too much data the day of the conference I recomment you to prefetch some of the docker images we are going to use:
$ docker pull openjdk:8-alpine
$ docker pull wurstmeister/zookeeper:3.4.6
$ docker pull wurstmeister/kafka:0.10.2.1
Remember to install docker-compose
if it's not installed by default (Install Docker Compose). . You can test it by running the following command in a console:
$ docker-compose -v
Information. In a linux machine docker commands require
sudo
but you can manage it as non-root user following this guide.
Disclaimer. All resemblance with reality is pure fiction, nothing shown here is accurate from a physics point of view.
The purpose of this workshop is to build a particle detector that will try to find evidence of the theoretical particle called Chameleon. The current Standard Model includes the following particles:
The workshop will provide you an accelerator that will send snapshots every 5 seconds to a kakfa instance containing the lists of detected particles in the different experiments. For each deteced particle you will find the following information:
- The experiment where it was detected
- The spin of the particle
- The charge of the particle
- The mass in MeV/c2 (it's always an exact number, e.g. for an electron it will always be 0.511MeV/c2 and for the tau neutrino it will be 15.5 MeV/c2)
The tool we are about to build should:
- Detect collisions inside snapshots. A collision happens when three or more particles are detected in the same experiment
- Analize each one of the collisions and get the type of the particles to find the elusive chameleons
As stated before, we are going to follow the next steps in the workshop:
- Build a monolith in order to get used to the domain and some technologies we will use later
- Convert the monolith ot a CQRS/ES application
- Break the CQRS/ES application into different microservices
In order to do it there are several branches (the ones with the suffix _start are the starting point for the step, and the ones with _end contain my very own lousy solution).
- Monolith
git checkout monolith_start
git checkout monolith_end
- CQRS/ES
git checkout cqrs_start
git checkout cqrs_end
- Microservices
git checkout microservices_start
git checkout microservices_end
So let's start buidling the Monolith
$ git checkout monolith_start