Top Banner
CQRS & EVENT SOURCING IN THE WILD Michiel Rook - @michieltcs
102

CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

May 25, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

CQRS & EVENT SOURCING IN THE WILD

Michiel Rook - @michieltcs

Page 2: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

➤ Developer, consultant, trainer, speaker

➤ @michieltcs

Page 3: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

YOU

Page 4: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

RAISE YOUR HAND

IF YOU HAVE

Page 5: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

read CQRS / Event Sourcing theory

RAISE YOUR HAND

IF YOU HAVE

Page 6: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

read CQRS / Event Sourcing theory

followed a tutorial, built a hobby project

RAISE YOUR HAND

IF YOU HAVE

Page 7: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

read CQRS / Event Sourcing theory

followed a tutorial, built a hobby project

used it in production

RAISE YOUR HAND

IF YOU HAVE

Page 8: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND
Page 9: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

QUICK RECAP

Page 10: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

' Event Sourcing ensures that all changes to application state are stored as a sequence of events.

-Martin Fowler

Page 11: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

ACTIVE RECORD VS. EVENT SOURCING

Account Id Account number Balance1234 12345678 �€50.00

... ... ...

Money WithdrawnAccount Id 1234

Amount �€50.00

Money DepositedAccount Id 1234

Amount �€100.00

Account OpenedAccount Id 1234

Account number 12345678

@michieltcs

Page 12: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

COMMANDS TO EVENTS

Deposit MoneyAccount Id 1234

Amount �€100.00

class DepositMoney { @TargetAggregateIdentifier public String accountId; public BigDecimal amount; }

@michieltcs

Page 13: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

COMMANDS TO EVENTS

Deposit MoneyAccount Id 1234

Amount �€100.00

@CommandHandler public void depositMoney(DepositMoney command) { apply(new MoneyDeposited( command.getAccountId(), command.getAmount(), ZonedDateTime.now())); }

command handler

@michieltcs

Page 14: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

COMMANDS TO EVENTS

Deposit MoneyAccount Id 1234

Amount �€100.00

Money DepositedAccount Id 1234

Amount �€100.00

class MoneyDeposited { public String accountId; public BigDecimal amount; public ZonedDateTime timestamp; }

command handler

@michieltcs

Page 15: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

AGGREGATES

class BankAccount { @AggregateIdentifier public String accountId; public String accountNumber; public BigDecimal balance; // ... @EventHandler public void accountOpened(AccountOpened event) { this.accountId = event.getAccountId(); this.accountNumber = event.getAccountNumber(); this.balance = BigDecimal.valueOf(0); } @EventHandler public void moneyDeposited(MoneyDeposited event) { this.balance = this.balance.add(event.getAmount()); } } @michieltcs

Page 16: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

AGGREGATE STATE

Account number Balance12345678 �€0.00

Account number Balance12345678 �€100.00

Account number Balance12345678 �€50.00

event handler

event handler

event handler

@michieltcs

Money WithdrawnAccount Id 1234

Amount �€50.00

Money DepositedAccount Id 1234

Amount �€100.00

Account OpenedAccount Id 1234

Account number 12345678

Page 17: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

Domain

UI

Event Bus

Event Handlers

Command

Repository

Data Layer

Database Database

Event Store

commands

events

events

queries DTOs

Aggregates

@michieltcs

Page 18: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

REPLAYS AND REBUILDS

Page 19: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

ANSWERING QUERIES

Page 20: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

BASED ON EVENTS

Page 21: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

QUERIES

Account Opened

Account Opened

Account Closed Number of active accounts?

@michieltcs

Page 22: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

QUERIES

Money Deposited

Money Withdrawn

Interest Received

Accounts with balance > �€100?

Money Deposited

Money Withdrawn

@michieltcs

Page 23: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PROJECTION

Account Opened Event Handler

# of active

accounts +1

Account Closed Event Handler

# of active

accounts -1

@michieltcs

Page 24: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PROJECTION

Events Event Handler(s) Storage

@michieltcs

Page 25: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

NEW PROJECTION

Page 26: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

NEW STRUCTURE

Page 27: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

BASED ON EXISTING EVENTS

Page 28: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

REBUILDING

Stop app CleanupLoop over events

Apply to projection Start app

@michieltcs

Page 29: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

ZERO DOWNTIME

Loop over existing events

Apply to new

projection

Use projection

@michieltcs

Page 30: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

ZERO DOWNTIME

New events Queue

Loop over existing events

Apply to new

projection

Apply queued events

Use projection

@michieltcs

Page 31: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

ZERO DOWNTIME

Get next event

Apply to new

projectionLast event? Use

projectionyes

no

@michieltcs

Page 32: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

LONG RUNNING REBUILDS?

Page 33: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

IN MEMORY

Page 34: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

DISTRIBUTED

Page 35: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PARTIAL

Page 36: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

BACKGROUND TASK

Page 37: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

TRACKING EVENT PROCESSOR

@michieltcs

@Target(ElementType.TYPE)

@Retention(RetentionPolicy.RUNTIME)

public @interface TrackedProjection {

}

Page 38: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

TRACKING EVENT PROCESSOR

@michieltcs

@Configuration public class ProjectionsConfiguration { @Autowired private EventHandlingConfiguration eventHandlingConfiguration; @PostConstruct public void startTrackingProjections() throws ClassNotFoundException { // ... } }

Page 39: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

TRACKING EVENT PROCESSOR

@michieltcs

ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(TrackedProjection.class)); for (BeanDefinition bd : scanner.findCandidateComponents("org.demo")) { Class<?> aClass = Class.forName(bd.getBeanClassName()); ProcessingGroup processingGroup = aClass.getAnnotation(ProcessingGroup.class); String name = Optional.ofNullable(processingGroup) .map(ProcessingGroup::value) .orElse(aClass.getPackage().getName()); eventHandlingConfiguration.registerTrackingProcessor(name); }

Page 40: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

EVENT VERSIONING

Page 41: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

NEW BUSINESS REQUIREMENTS

Page 42: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

CHANGING VIEW ON EVENTS

Page 43: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

IRRELEVANT

Page 44: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

DIFFERENT FIELDS

Page 45: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

WRONG NAME

Page 46: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

TOO COARSE

Page 47: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

TOO FINE

Page 48: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

SUPPORT YOUR LEGACY?

Page 49: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

Commands can be

renamed

1

@michieltcs

Page 50: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

Commands can be

renamed

1

Events are immutable

2

@michieltcs

Page 51: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

Commands can be

renamed

1

Events are immutable

Correct old events with new events

2 3

@michieltcs

Page 52: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

COMPENSATING ACTIONS

class MoneyWithdrawn { String accountId; BigDecimal amount; }

class WithdrawalRolledBack { String accountId; BigDecimal amount; }

Typo: too much withdrawn!

Page 53: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

COMPENSATING ACTIONS

class AccountOpened { String accountId; String accountNumber; }

class DuplicateAccountClosed { String accountId; }

Duplicate account number!

Page 54: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

UPCASTING

Page 55: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

UPCASTING

Event Store

@michieltcs

Page 56: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

UPCASTING

@michieltcs

@Revision("1.0") @Value class AccountOpened { String accountId; String accountNumber; }

Page 57: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

UPCASTING

Event Store

AccountOpened (1.0)

Event Handler

@michieltcs

Page 58: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

UPCASTING

@Revision("2.0") @Value class AccountOpened { String accountId; String accountNumberIban; }

@michieltcs

Page 59: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

UPCASTING

Event Store

AccountOpened (1.0)

Upcaster

AccountOpened (2.0)

Event Handler

@michieltcs

Page 60: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

UPCASTING

private static SimpleSerializedType targetType = new SimpleSerializedType(AccountOpened.class.getTypeName(), "1.0"); private static SimpleSerializedType outputType = new SimpleSerializedType(AccountOpened.class.getTypeName(), "2.0");

@michieltcs

Page 61: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

UPCASTING

public Stream<IntermediateEventRepresentation> upcast( Stream<IntermediateEventRepresentation> intermediateRepresentations) { return intermediateRepresentations.map(evt -> { if (!evt.getType().equals(targetType)) { return evt; } return evt.upcastPayload(outputType, Document.class, document -> { Element rootElement = document.getRootElement(); Element accountNumberElement = rootElement.element("accountNumber"); rootElement.remove(accountNumberElement); rootElement.addElement("accountNumberIban") .setText(toIban(accountNumberElement.getText())); return document; }); }); }

@michieltcs

Page 62: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

VERSIONED EVENT STORE

Page 63: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

VERSIONED EVENT STORE

events_v1

[ { "id": "12345678", "type": "AccountOpened", "aggregateType": "Account", "aggregateIdentifier": "1234", "sequenceNumber": 0, "payloadRevision": "1.0", "payload": { ... }, "timestamp": ... ... }, ... ]

@michieltcs

Page 64: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

COPY & REPLACE

Page 65: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

VERSIONED EVENT STORE

Loop over existing events

Apply upcaster

Add queued events

Use new event store

New events Queue

@michieltcs

Page 66: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

VERSIONED EVENT STORE

events_v2

[ { "id": "12345678", "type": "AccountOpened", "aggregateType": "Account", "aggregateIdentifier": "1234", "sequenceNumber": 0, "payloadRevision": "2.0", "payload": { ... }, "timestamp": ... ... }, ... ]

@michieltcs

Page 67: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

GDPR

Page 68: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

"RIGHT TO ERASURE"

Page 69: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PERSONALLY IDENTIFIABLE INFORMATION

Page 70: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

ANONYMIZED OR REMOVED

Page 71: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

IMMUTABLE EVENTS?

Page 72: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

CONCURRENCY

Page 73: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

CONCURRENT COMMANDS

Withdraw MoneyAccount Id 1234

Amount �€50.00

Deposit MoneyAccount Id 1234

Amount �€100.00

?

@michieltcs

Page 74: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PESSIMISTIC LOCKING

Withdraw MoneyAccount Id 1234

Amount �€50.00

Deposit MoneyAccount Id 1234

Amount �€100.00

Account Id Balance

1234 �€100.00

Account Id Balance

1234 �€50.00

wait for lock

lock

@michieltcs

Page 75: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

OPTIMISTIC LOCKING

Withdraw MoneyAccount Id 1234

Amount �€50.00

version 1

Deposit MoneyAccount Id 1234

Amount �€100.00

version 1

Account Id Balance1234 �€100.00

version 2

ConcurrencyException

@michieltcs

Page 76: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

MULTIPLE INSTANCES

Page 77: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

MULTIPLE INSTANCES

Replica

Replica

ReplicaCommands DistributedCommand Bus

CommandHandler

CommandHandler

CommandHandler

CommandHandler

CommandHandler

CommandHandler

CommandHandler

CommandHandler

CommandHandler

@michieltcs

Page 78: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

SCALE

Page 79: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PERFORMANCE

Server

@michieltcs

Page 80: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PERFORMANCE

Server

Database

@michieltcs

Page 81: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PERFORMANCE

Server

Database

Framework

@michieltcs

Page 82: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PERFORMANCE

Server

Database

Framework

Language

@michieltcs

Page 83: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

PERFORMANCE

Server

Database

Framework

Language

Serializer

@michieltcs

Page 84: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

STORAGE

#events

@michieltcs

Page 85: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

STORAGE

#events

#aggregates

@michieltcs

Page 86: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

STORAGE

#events

#aggregates

#events per aggregate

@michieltcs

Page 87: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

STORAGE

#events

#aggregates

#events per aggregate

Serializer

@michieltcs

Page 88: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

STORAGE

#events

#aggregates

#events per aggregate

Serializer

Payload

@michieltcs

Page 89: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

SNAPSHOTS

Events... ...

997 Account Opened998 Money Deposited999 Money Withdrawn

1000 Money Deposited

@michieltcs

Page 90: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

SNAPSHOTS

Events... ...

997 Account Opened998 Money Deposited999 Money Withdrawn

1000 Money Deposited1001 Money Withdrawn

@michieltcs

Page 91: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

SNAPSHOTS

Events... ...

997 Account Opened998 Money Deposited999 Money Withdrawn

1000 Money DepositedSNAPSHOT

1001 Money Withdrawn

Events... ...

997 Account Opened998 Money Deposited999 Money Withdrawn

1000 Money Deposited1001 Money Withdrawn

@michieltcs

Page 92: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

CLOSING WORDS

Page 93: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

CQRS + ES = AWESOME

Page 94: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

NO SILVER BULLET

Page 95: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

COMPLEXITY

Page 96: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

INFRASTRUCTURE

Page 97: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

AUDIT TRAIL

Page 98: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

SCALABILITY

Page 99: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

TESTING

Page 100: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

DOMAIN FIT

Page 101: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

LITERATURE

Page 102: CQRS & EVENT SOURCING - JAX London · CQRS & EVENT SOURCING IN THE WILD ... IF YOU HAVE. read CQRS / Event Sourcing theory followed a tutorial, built a hobby project RAISE YOUR HAND

THANK YOU!

@michieltcs / [email protected]

www.michielrook.nl