Embrace Events and let CRUD die

Post on 13-Apr-2017

175 views 0 download

Transcript of Embrace Events and let CRUD die

Embrace Events

and let CRUD die

@cakper

Goal

CRUD

Who knows what CRUD is?

Clients

Database

DTO’s / Domain ObjectsData

Presentation

Service

Business Logic

Well known

Easy to sell

Tooling

Who never had problems with it?

Soft Delete

Audit

Calculating changes

Scaling

3rd Normal Form

Optimised for write

Large & slow queries

But that’s good!

In the WRITE context

What is your write:read ratio?

Some of the applications are read heavy

Joins are expensive

Can’t we all become join vegans?

Alberto Brandolini

Denormalisation

Read models

You have to maintain two models now

What if we treat change as a first class citizen?

Event Sourcing

Book added to library

Book lent to reader

Book extended

Book returned

Event1. something that happens or is

regarded as happening; an occurrence, especially one of some importance.

Current state is a left-fold over past events

Greg Young

Aggregate

Consistency boundary

Consuming commands

Producing events

Reconstituting from history

Snapshotting

Testing

State-based testing

We test what changed

What about things that didn’t?

Behaviour-based testing

Given:Book“DDD”wasaddedtolibrary

When:Readerlends“DDD”book

Then:Book“DDD”waslenttoreader

Given:Book“DDD”wasaddedtolibraryBook“DDD”waslenttoreader

When:Readerlends“DDD”book

Then:Exception:Book“DDD”alreadylent

Event Store

Append-only

Scaling

Optimistic locking

Retries

Integration

MQ

REST

2PC

Eventual consistency

Projections

Query optimised storage

Task-based UI

Business Value of Events

Insight into past data

Business Intelligence

Legal compliance

Debugging

How do we get there?

Event Storming

odd-looking workshop that has a massive consumption of orange sticky notes

Alberto Brandolini

How does it work?

Start by capturing Domain Events

Domain Event

Book added to library

Book extended

Book added to

inventory

Reader identity

confirmed

Reader registered

Book reservation

placed

Book lent to reader

Book recalled

Book returned

Behavioural mindset

Timeline

Book added to library

Book extended

Book added to

inventory

Reader identity

confirmedReader

registered

Book reservation

placed

Book lent to reader

Book recalled

Book returned

Naming

Book added to library

Book extendedBook

added to inventory

Reader identity

confirmedReader

registered

Book reservation

placed

Book lent to reader

Book recalled

Book returned

Complexity

Reader registered

Reader identity

confirmed

Identity Confirmed by

Carer

Deposit paid

Deposit Not Paid

Reader Account

Activated

Pin point risks

Risk

Reader registered

Reader identity

confirmed

Identity Confirmed by

Carer

Deposit paid

Deposit Not Paid

Reader Account

Activated

Registration

Right People

Event sources

Users

Command

Book Lent

Lend Book

Reader

Book Already Lent

Other events

Policy

Book Returned

LatePenalize Lock Account

Time

Book reserved for the user Release book

External systems

External System

Payment Gate Money Received

Grouping commands

Aggregates

Book Lent

Book Returned

Book Book Extended

Return

Lend

Extend

Making decision

Read Model

Book Returned

Book Added

Book Lent

Available Books

Making it work

Available Books

Reader Lend Book Book Lent

User

Command

Aggregate

External System

Domain Event

Read Model

Policy

Command

UI

Picture that explains everything

by Alberto Brandolini

Want to facilitate it?

Unlimited modelling surface

No chairs

Loads of sticky notes & sharpies

People with questions

People with answers!

Final words

Tools

Event Store

Messaging

Projections

Right problems

Make models useful but not perfect

Explicit Complexity

Intention-revealing interfaces

Writing software is about learning

Technical excellence

Thanks!@cakper