A presentation about data and how to build polyglot applications. The key component, as I see it, to build polyglot data applications is to use an event store as the master data storage and then use other types of databases as views of that data. The presentation also touches on Command Query Responsibility Segragation, CQRS, and event sourcing.
Powering Real-Time Decisions with Continuous Data Streams
Polyglot heaven
1. POLYGLOT HEAVEN
How to Build an Async, Reactive Application in
2014
NDC London
Tomas Jansson
04/12/2014
2. POLYGLOT HEAVEN
How to Build an Async, Reactive Application in
2014
NDC London
Tomas Jansson
04/12/2014
And this should probably be 2015
This here, a title to get accept
3. THIS IS ME
Tomas Jansson
Manager & Practice Lead .NET
BEKK Oslo
@TomasJansson
tomas.jansson@bekk.no
github.com/mastoj
blog.tomasjansson.com
4. AGENDA
WHY ASYNC AND REACTIVE?
LET’S TALK DATA
WHY POLYGLOT?
WHAT CAN WE DO?
DEMO
SUMMARY
5. WHY ASYNC AND REACTIVE? - ASYNC
Async doesn’t
mean unreliable
Async gives you
responsiveness
Data will be
consistent
6. WHY ASYNC AND REACTIVE? - REACTIVE
Message based
modular
React on change
Eventual
consistent
26. CQRS WITH EVENT SOURCING - OVERVIEW
Application: f(x, ys) ys’, x: Command, ys: list of Events
Projection: f(y, ys) z, y: Event, ys: list of Events, z: View
27. CQRS WITH EVENT SOURCING - OVERVIEW
Application: f(x, ys) ys’, x: Command, ys: list of Events
Projection: f(y, ys) z, y: Event, ys: list of Events, z: View
Your
application is a
pure function!
How you
implement it is
secondary, the
events are what
matters!
28. CQRS WITH EVENT SOURCING - TESTS
[Test]
public void PlaceOrder_Should_CreateAnOrder() {
var productId = Guid.NewGuid();
var customerId = Guid.NewGuid();
var orderId = Guid.NewGuid();
var orderItems =
Contracts.Helpers.ToFSharpList(new[] {new OrderItem(productId, 20)});
Given(new ProductCreated(productId, "a name", 20),
new CustomerCreated(customerId, "John Doe"));
When(new PlaceOrder(orderId, customerId, orderItems));
Then(new OrderPlaced(orderId, customerId, orderItems));
}
Pure functions
are easy to test
29. WHAT WILL I SHOW TODAY?
ApplicationCommand Events
Events Projection View
30. WHAT WILL I SHOW TODAY?
ApplicationCommand Events
Events Projection View
HTTP
35. SUMMARY
Why async and reactive?
• Responsive
• Scalable
• Modular
Why polyglot?
• Not all data is the same
• Not everything is a nail
36. SUMMARY
Why async and reactive?
• Responsive
• Scalable
• Modular
Why polyglot?
• Not all data is the same
• Not everything is a nail
Event sourcing and CQRS
• CQRS is divide and conquer on an architecture level
• Your application should be a function
• You don’t have to write in a functional language to write functional code (but it might make it easier)
37. SUMMARY
Why async and reactive?
• Responsive
• Scalable
• Modular
Why polyglot?
• Not all data is the same
• Not everything is a nail
Event sourcing and CQRS
• CQRS is divide and conquer on an architecture level
• Your application should be a function
• You don’t have to write in a functional language to write functional code (but it might make it easier)
You will get a response, it is not fire and forget model your error handling
Responsiveness return to the user early
The data will be consistent, at some point in time
Applications that react to changes
Message based, in the form of event
Things are modular fits in your head. This doesn’t mean it is not complex, the connections between the modules might be harder to see
Not all system react at the same time, but it will lead to eventual consistency
A simple question
No! Not all data are the same, so why are we often treaten the data the same way (yes I’m thinking about SQL)
Changes or events
I’ve had some discussion with other people telling me that the thing I sugges is the new hammer since it is new and shiny and we should stick with SQL. But that reasoning makes SQL your hammer. I’m suggesting different tools for different problems.
SQL is terrible at relations, if they get somewhat complex. Use SQL for reporting, then it is great!
Standard picture from googling the ”standard” architecture 3-layered architecture
As soon as you want to show the user some variation of the data you have to change the model where you have your domain logic makes your domain complex doing more than it is supposed to.. Domain is about behavior and changes!
This is a technique most of us learned in college or university, so why doesn’t we use it more?
This is a really simplified picture of CQRS, but it’s not that simplified. It comes from CQS but applied to todays context
I do have a test helper, but it is just setting up dependencies