Download pdf - Polyglot heaven

Transcript
Page 1: Polyglot heaven

POLYGLOT HEAVEN

How to Build an Async, Reactive Application in 2014

NDC London

Tomas Jansson

04/12/2014

Page 2: Polyglot heaven

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

Page 3: Polyglot heaven

THIS IS ME

Tomas Jansson

Manager & Practice Lead .NETBEKK Oslo

@[email protected]/mastojblog.tomasjansson.com

Page 4: Polyglot heaven

AGENDA

WHY ASYNC AND REACTIVE?

LET’S TALK DATA

WHY POLYGLOT?

WHAT CAN WE DO?

DEMO

SUMMARY

Page 5: Polyglot heaven

WHY ASYNC AND REACTIVE? - ASYNC

Async doesn’t mean unreliable

Async gives you responsiveness

Data will be consistent

Page 6: Polyglot heaven

WHY ASYNC AND REACTIVE? - REACTIVE

Message based modular

React on changeEventual

consistent

Page 7: Polyglot heaven

LET’S TALK DATA

Let’s talk Data

Page 8: Polyglot heaven

LET’S TALK DATA

Are all data the same?

Page 9: Polyglot heaven
Page 10: Polyglot heaven

LET’S TALK DATA

What different kinds of data do we have?

Page 11: Polyglot heaven

LET’S TALK DATA

Changes, state, relations, cache...

Page 12: Polyglot heaven

”if all you have is a hammer, everything looks like a nail”

Why polyglot?

Page 13: Polyglot heaven

WHY POLYGLOT? – CHOOSE THE RIGHT TOOLS

Documents

Page 14: Polyglot heaven

WHY POLYGLOT? – CHOOSE THE RIGHT TOOLS

DocumentsDocument database

Page 15: Polyglot heaven

WHY POLYGLOT? – CHOOSE THE RIGHT TOOLS

DocumentsDocument database

Changes

Page 16: Polyglot heaven

WHY POLYGLOT? – CHOOSE THE RIGHT TOOLS

DocumentsDocument database

Changes Event store

Page 17: Polyglot heaven

WHY POLYGLOT? – CHOOSE THE RIGHT TOOLS

DocumentsDocument database

Changes Event store

Relations

Page 18: Polyglot heaven

WHY POLYGLOT? – CHOOSE THE RIGHT TOOLS

DocumentsDocument database

RelationsGraph

database

Changes Event store

Page 19: Polyglot heaven

What can we do?

Page 20: Polyglot heaven

Change!

Page 21: Polyglot heaven

3-LAYERED ARCHITECTURE – WHY OH WHY?

Page 22: Polyglot heaven

3-LAYERED ARCHITECTURE – WHY OH WHY?

You are mixing your domain

with your query model!

Page 23: Polyglot heaven

What do you think about ”Divide and Conquer?”

Page 24: Polyglot heaven

COMMAND QUERY RESPONSIBILITY SEGREGATION - CQRS

CQRS is ”Divide and Conquer” applied on a

architecutral level

Page 25: Polyglot heaven

CQRS WITH EVENT SOURCING - OVERVIEW

ApplicationCommand Events

Events Projection View

Page 26: Polyglot heaven

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

Page 27: Polyglot heaven

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!

Page 28: Polyglot heaven

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

Page 29: Polyglot heaven

WHAT WILL I SHOW TODAY?

ApplicationCommand Events

Events Projection View

Page 30: Polyglot heaven

WHAT WILL I SHOW TODAY?

ApplicationCommand Events

Events Projection View

HTTP

Page 31: Polyglot heaven

THE KEY COMPONENT

This is where the ”truth” is

stored

Page 32: Polyglot heaven

Demo!

Page 33: Polyglot heaven

View databases

Web

Application View

CreateCustomer

CreateProduct

PlaceOrder

GetRecommendations

GetCustomer

GetProduct

Page 34: Polyglot heaven

SUMMARY

Why async and reactive?

• Responsive

• Scalable

• Modular

Page 35: Polyglot heaven

SUMMARY

Why async and reactive?

• Responsive

• Scalable

• Modular

Why polyglot?

• Not all data is the same

• Not everything is a nail

Page 36: Polyglot heaven

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)

Page 37: Polyglot heaven

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)

Page 38: Polyglot heaven

http://www.slideshare.net/mastoj/polyglot-heaven

https://github.com/mastoj/PolyglotHeaven

http://open.bekk.no/polyglot-heaven-a-response-to-the-bekk-radar

Page 39: Polyglot heaven

Questions?

Page 40: Polyglot heaven

Thank you!

@TomasJansson