Microservices and actors are a very trendy subject. You hear about them everywhere and it's the brand new thing. Except it's not.
These things have been coming back and forth in the industry for years, in different shapes and names. But they always rely on the same concepts of loose coupling and high cohesion, that we have been talking about for more than 30 years.
In this talk, we will see how events help you decouple your applications in smaller independent components, which do one thing and do it well. We will see that buying an expensive ESB from a major software vendor is not the solution to make your code more robust. We will see how a practical approach to messages and events can easily transform your application into something easier to understand, maintain and evolve.
We will also see how events can ease the pain when it comes to defining a ubiquitous language, used by both business and technical people, that allows better understanding of your problem domain and can even sometimes help you discover business insights and generate new business opportunities.
2. voxxeddays.com/luxembourg/ #voxxeddaysLU
Who is this guy ?
What does he do ?
How does he dare stand in front
of us today and speak about
such grave things as system
architectures and monoliths and
coupling ?
Letâs speak about you instead
6. voxxeddays.com/luxembourg/ #voxxeddaysLU
Go buy yourselves an
Enterprise
Service
Bus
and all your problems will be solved
The next step of evolution
Expensive
Shit
Ball
Any idea what SOA means in Dutch ?
8. voxxeddays.com/luxembourg/ #voxxeddaysLU
The new big idea : ÂľServices
There must a
better way
ÂľServices
==
SOA done properly
Source : http://martinfowler.com/articles/microservices.html
small
11. voxxeddays.com/luxembourg/ #voxxeddaysLU
Bounded context
Explicitly define the context within which a model applies.
Explicitly set boundaries in terms of
⢠team organization
⢠usage within specific parts of the application,
⢠and physical manifestations such as code bases and database schemas.
Standardize a single development process within the context, which need
not be used elsewhere.
Model expressions, like any other phrase, only have meaning in context.
Source : Domain-Driven Design: Tackling Complexity in the Heart of Software by Eric Evans - Chapter 14 : Maintaing model integrity
13. voxxeddays.com/luxembourg/ #voxxeddaysLU
Aggregates
⢠Transactional consistency boundaries
⢠Aggregate root is the gatekeeper of the aggregate
ď it enforces business rules
ď it cannot be blindsided
Source : Modeling Aggregates with DDD and Entity Framework by Vaughn Vernon
14. voxxeddays.com/luxembourg/ #voxxeddaysLU
Ubiquitous language
Breaking the language barrier between business
and tech people by sharing the same language
Itâs all about communication and learning
Breaking silos starts with communication
ď Language is ubiquitous in a context
16. voxxeddays.com/luxembourg/ #voxxeddaysLU
You applied Stategic Design and now have several pristine Domain
Models in context
You system is devided into well defined Bounded Countexts and your
contexts do not leak
Your domain logic and business rules are explicitly expressed in your
code though well designed Aggregates
All is for the best
But
⢠How do you write reports ?
⢠Should you load 200 000 aggregates to compute statistics ?
18. voxxeddays.com/luxembourg/ #voxxeddaysLU
Command / Query Responsibility Segragation
Event Centric: Finding Simplicity in Complex Systems by Greg Young
Estimated release date
Sometime between Q3 2016
and 2035 Greg Young
http://buildstuff.lt
19. voxxeddays.com/luxembourg/ #voxxeddaysLU
Commands and Queries
Command
⢠It requests an action
⢠It mutates state
⢠It does not return data
Query
⢠It answers a question
⢠It does not mutate state
⢠It returns data
20. voxxeddays.com/luxembourg/ #voxxeddaysLU
Optimized for reads
⢠80/20 law
⢠Denormalization brings direct
display in UI
⢠Thin data access layer
⢠Caching
⢠BASE on the read side
Write side ensures consistency
⢠Use of DDD
⢠Domain logic and rules are
enforced by aggregates
⢠ACID on the write side
Source : CQRS Journey
CQRS
22. voxxeddays.com/luxembourg/ #voxxeddaysLU
Brewerâs CAP theorem
⢠Consistency : all nodes see the same data at the same time
⢠Availability : a guarantee that every request receives a
response about whether it succeeded or failed
⢠Partition tolerance : the system continues to operate despite
arbitrary partitioning due to network failures
No, you canât always get what you want
ď Sometimes, you need to make hard a choices
Source : https://en.wikipedia.org/wiki/CAP_theorem
23. voxxeddays.com/luxembourg/ #voxxeddaysLU
Eventual consistency
Donât underestimate the cost of
maintaining consistency all the time
⢠What is the book of record ?
Itâs ok to use stale data
⢠Your data is stale as soon as it has
been read from the database anyway
Donât fight it, embrace it
⢠It might even become a competitive
advantage
26. voxxeddays.com/luxembourg/ #voxxeddaysLU
Using a reliable message transport
Source : CQRS Journey
Caracteristics
⢠Eventually consistent
⢠Performance
⢠Availability
Problems ?
⢠Your infrastructure needs
to supports transaction
over database and queue
28. voxxeddays.com/luxembourg/ #voxxeddaysLU
You seperated your reads from your writes
You bind DTO direcly in your UI
Your UI is task oriented
Your write side ensures business rules and consistency
Your read side is eventually consistent
You did good
But
⢠You persist only current state and you still need an ORM
⢠Syncing read from write is expensive and might require some kind of
transaction
32. voxxeddays.com/luxembourg/ #voxxeddaysLU
Event Sourcing
Save
⢠Donât save current state
⢠Save a stream of small immutable
events instead
Load
⢠Replay events to restore current state
⢠Use snapshots if need be
Sync
⢠Use events to sync the read model
⢠Use a publish/subscribe pattern to
scale denormalization
Source : CQRS Journey
33. voxxeddays.com/luxembourg/ #voxxeddaysLU
Projections
React to events as they are written
Create new events when
interesting combinations occur
Write temporal correlation queries
that run over historical data and on
into the future
Source : http://www.jefclaes.be/2013/10/event-projections.html
34. voxxeddays.com/luxembourg/ #voxxeddaysLU
Integration made easy
Source : http://www.confluent.io/blog/making-sense-of-stream-processing/
⢠Your even stream can be
used as a message queue
⢠Use event projections to
denormalize in multiple read
models or external systems
⢠Leverage publish/subscribe
infrastructure
35. voxxeddays.com/luxembourg/ #voxxeddaysLU
https://geteventstore.com/
Event sourced by design
⢠Writen as an event sourced system
⢠Open source ď go check the code out
Projections
⢠Consume or create new events
⢠Volatile, catch-up or persistent subsciptions
Portable
⢠Runs on mono on Linux, OS X and
Windows
⢠Clients API for HTTP, .NET, Akka, Erlang
Great performances
⢠15,000 writes per second
⢠50,000 reads per second
39. voxxeddays.com/luxembourg/ #voxxeddaysLU
A workshop format for
quickly exploring complex
business domains
Source:https://twitter.com/ziobrando/status/535828549102759936
Source : http://fr.slideshare.net/ziobrando/event-storming-recipes
EventStorming
It is powerful
It is engaging
It is efficient
It is easy
It is fun
40. voxxeddays.com/luxembourg/ #voxxeddaysLU
Things weâve learnt from modeling with events
⢠Applies to many domains
⢠Changes the way domain experts think about the system
⢠Focus on behavior instead of structure
⢠Focus on temporal aspects : this happens before that
ď Develop new competitive advantage
44. voxxeddays.com/luxembourg/ #voxxeddaysLU
Imperative vs Reactive
Responsive
⢠Respond in a timely manner
⢠Consistent quality of service
Resilient
⢠Stay responsive in the face of failure
⢠Failures are contained
⢠Recovery is delegated
to an other component
Elastic
⢠Stay responsive under
varying workloads
⢠No bottlenecks
Message driven
⢠Asynchronous message passing
⢠Clear boundaries ensure loose coupling
Source : http://www.reactivemanifesto.org
46. voxxeddays.com/luxembourg/ #voxxeddaysLU
Actor model
An actor is a computational entity that, in response to a message
it receives, can concurrently:
⢠send a finite number of messages to other actors;
⢠create a finite number of new actors;
⢠designate the behavior to be used for the next message it receives.
ď Computational model
ď Inherently concurrent
ď Infinitely composable
ď Fault tolerant through supervision
Source : http://www.brianstorti.com/the-actor-model
48. voxxeddays.com/luxembourg/ #voxxeddaysLU
⢠Functional language
⢠Immutable state
⢠Functions with no side effect
⢠Type system enforces invariants
⢠Event processing is a left fold
C#
F#
Source : Scott Wlaschin https://fsharpforfunandprofit.com/ddd
Itâs all functional
State <= State + Event
49. voxxeddays.com/luxembourg/ #voxxeddaysLU
Messaging & storage
Messaging infrastructure
⢠RabbitMQ
⢠ZeroMQ
⢠Apache Kafka
⢠Azure Service Bus
Make your pick
⢠Column
⢠Key-Value
⢠Document
⢠Graph
⢠Multi-model
Choose the right tool according to your context
ď No dogma
51. voxxeddays.com/luxembourg/ #voxxeddaysLU
Embrace the new trends
IoT
⢠Telemetry == Events
⢠Stream analytics
⢠Smart Everything
Source:https://www.control4.com/blog/2014/03/the-internet-of-things-and-the-connected-home
Big data
⢠Machine learning
⢠Deep learning
⢠Data lake
Source:https://www.ucl.ac.uk/big-data/bdi
53. voxxeddays.com/luxembourg/ #voxxeddaysLU
What is the next big thing ?
MicroServices is just the latest trend
ď Something else will come up !
Good modeling & design principles stay
valuable through time
⢠SOLID
⢠Patterns of Enterprise Application Architecture
⢠Enterprise Integration Patterns
⢠Domain-Driven Design
ď Loose coupling + high cohesion
54. voxxeddays.com/luxembourg/ #voxxeddaysLU
Distributed software is hard
First rule of disributed sofware
DONâT DISTRUBUTE unless you genuinely need to
ď Design your software so that you might distribute
Beware of accidental complexity
⢠Distribution makes things more difficult to understand
⢠The learning curve is steep
Remember : CQRS/ES is not a top level architecture
ď Use it only when it makes sense
56. voxxeddays.com/luxembourg/ #voxxeddaysLU
Interesting video content
⢠DDDEurope - Eric Evans â Tackling Complexity in the Heart of Software
⢠DDDEurope - Greg Young â A Decade of DDD, CQRS, Event Sourcing
⢠DDDEurope - Alberto Brandolini â The Precision Blade
⢠DDDx - Eric Evans - DDD and Microservices: At Last, Some Boundaries!
⢠DDDx - Scott Wlaschin â Domain Driven Design with the F# type system
⢠React 2014 - Erik Meijer â What does it mean to be Reactive?
⢠Lang.NEXT - Hewitt, Meijer and Szyperski â The Actor Model
Hinweis der Redaktion
Who knows anything about
Microservices
DDD
CQRS/ES
Event-driven architectures
I have been part of the DDD community for quite some time now.
Read the book in 2006
DDDx twice
DDDEurope in 2016
Speaker at BuildStuff
Let me know if I go too fast
Ask questions
What is a monolith ?
2001: A space odysey
Monolith = fear + curiosity
Mysterious force fallen from the sky
The central source that holds everything together
In software
Client/Server
Single unit of deployment per component
Vertical deployment even though N-tier
Scale up
Monolithic systems are not so bad.
I have built many of them that are still running
Who has never built a system like that ?
Problems
Tighly coupled
Heavy to deploy
Enforces silos structure ď Font end devs vs COBOL devs, devs vs ops
Do not scale very well ď Scale up has limitations
Do not cope well with concurrency
Leveraging multi core procs and cloud
CORBA
COM/DCOM
Webservices & WS* of death
Nothing very new
N-Tier
RMI
COM/DCOM/COM+
CORBA
WS* of death
REST
ESB
Heavyweight
Brokered architecture != distributed
Difficult to deploy and upgrade
Seldom used properly
business logic ends up in the ESB instead of in the domain model
ESB = Software vendors trick
Another software vendor trick makes you belive that
everything has to be built with a relational DB
Problem
Integration through the DB
Object/Relational impedence mismatch
Single point of failure
Does not scale
Again a software vendors trick
Now we have a better solution : Microservices
They are going to save the world
Is everything so much better ?
Itâs not only about deployment, itâs all about boundaries
We tend to see everything as a technical problem because we like that
But itâs actually a business problem.
How do you model a system that makes sense for your actual business domain ?
Itâs all about clean responsabilities segregation
DDD ď boundaries
Itâs not about building blocks and patterns
Itâs all about boundaries
The 2 most important concepts in DDD ?
Bounded contexts
Aggregates
According to Eric himself, you should start reading the book from chapter 7 and forward, then come back to the beginning
Skip the Building Blocks and understand Strategic Design first
Boundaries ď Encapsulation
Clean, documented ways to communicate
1 team ď 1 Bounded Context
Bounded contexts live into sub domains
You want to focus on your core domain ď where you have your competitive advantage
Aggregates should be simple
Beware the naive aggregate design approach
Duplicated in different Bounded Contexts
DB schema to separate concerns
Modules/Namespace
Perfectly viable option⌠but
Basic Availability
Soft-state
Eventual consistency
Atomic: Everything in a transaction succeeds or the entire transaction is rolled back.
Consistent: A transaction cannot leave the database in an inconsistent state.
Isolated: Transactions cannot interfere with each other.
Durable: Completed transactions persist, even when servers restart etc.
Rolling Stones song
If you want to favor availability and resilience of your system, you will need to relax consistency
2-phase commit ď
Viable solution
Viable solution
Think accounting
What is the book of records
ATM
Warehouse
The system is not the book of record
The physical world is the book of record
Device app is event sourced
Optimistic concurrency
Conflict resolution on events
ď Think about GIT