From Event Driven to Event Sourcing by Thomas Bgh Fangel & - - PowerPoint PPT Presentation

from event driven to event sourcing
SMART_READER_LITE
LIVE PREVIEW

From Event Driven to Event Sourcing by Thomas Bgh Fangel & - - PowerPoint PPT Presentation

From Event Driven to Event Sourcing by Thomas Bgh Fangel & Emil Krog Ingerslev 1 Who are we? 2.1 Emil Krog Ingerslev @emilingerslev Site reliability engineer & architect @lunarway Works with Thomas on backend of the future


slide-1
SLIDE 1

From Event Driven to Event Sourcing

by Thomas Bøgh Fangel & Emil Krog Ingerslev

1

slide-2
SLIDE 2

Who are we?

2.1

slide-3
SLIDE 3

Emil Krog Ingerslev @emilingerslev Site reliability engineer & architect @lunarway Works with Thomas on backend of the future ❤ reliable efficient automated soware coffee geek ☕ Talks... a lot

2.2

slide-4
SLIDE 4

Thomas Bøgh Fangel @tbfangel Architect @lunarway Works with Emil on the backend of the future Always looking for a better design ❤ to write and talk about what we do Talks... less

2.3

slide-5
SLIDE 5

2.4

slide-6
SLIDE 6

2.5

slide-7
SLIDE 7

in numbers

80.000+

Users

10M+

Transcations

+75

Microservices

80+

Employees

1.000M+

€ Volume

3

K8S clusters

2.6

slide-8
SLIDE 8

Platform Evolution

3.1

slide-9
SLIDE 9

From monolith...

3.2

slide-10
SLIDE 10

3.3

slide-11
SLIDE 11

... to event driven microservices ...

75+

microservices

async messages

communication pattern

10+ integrations

to 3rd parties

50+

daily deployments

3.4

slide-12
SLIDE 12

... to event sourcing with consistency guarantees

3.5

slide-13
SLIDE 13

Identified some problems found desired characteristics how we implemented them

4.1

slide-14
SLIDE 14

a fictive overview not showing message queues databases etc...

4.2

slide-15
SLIDE 15

5.1

slide-16
SLIDE 16

We built services CRUD like Behavior: Step 1 - do change in DB Step 2 - publish message

5.2

slide-17
SLIDE 17

Consistency problem do change in DB service fails event NOT published

5.3

slide-18
SLIDE 18

Consistency problem relied on broker receiver in dark publisher in dark

5.4

slide-19
SLIDE 19

receiver never gets event zero-or-once delivery actually zero-or-more! Consequence

5.5

slide-20
SLIDE 20

services state dri weird support cases hours of logs scrolling synthetic symptom fixes

5.6

slide-21
SLIDE 21

Imagine some other characteristics “Atomic state change and message publication” + “At-least-once delivery”

5.7

slide-22
SLIDE 22

Event sourcing as a solution Every event IS the state change = Atomic event generation & state change

5.8

slide-23
SLIDE 23

Guaranteed event publishing Read stream Got event #1 Publish event #1 Save cursor #1 continue to #2 crash

5.9

slide-24
SLIDE 24

Guaranteed event publishing Starting up Read cursor #1 Read stream from > #1 Got event #2 Publish event #2 Save cursor #2

5.10

slide-25
SLIDE 25

Guaranteed atomic state change + event publishing at least once event publishing

5.11

slide-26
SLIDE 26

6.1

slide-27
SLIDE 27

6.2

slide-28
SLIDE 28

Bootstrapping the old way replay from Poor Man synthetic events

6.3

slide-29
SLIDE 29

Bootstrapping problems manual process availability of events consistency handling load

6.4

slide-30
SLIDE 30

Can we do better?

“Events as first class citizens”

+

“Event streams with possibility of redelivery”

=

Bootstrap galore

6.5

slide-31
SLIDE 31

Event sourcing as a solution "Every event IS the state change"

+

API on top of event stream

=

Events as first class citizens with event streams with redelivery

6.6

slide-32
SLIDE 32

Event Sourcing Patterns Bootstrap on-demand Integration events on the outside

6.7

slide-33
SLIDE 33

Integration Events are a projection of internal events with same characteristics so whats the purpose? Less coupling Producer ↔ Consumer

6.8

slide-34
SLIDE 34

Producer ... ... Finds event stream for User #1 Hydrates integration events Sends events back ... ... New Consumer Gets request from User #1 Asks for events for User #1 ... ... ... Hydrates User #1 view Responds to request

6.9

slide-35
SLIDE 35

7.1

slide-36
SLIDE 36

Healing problem Service listens for events Receives event #1 event #2 is sent, but is lost Receives event #3 State has dried

7.2

slide-37
SLIDE 37

Driing state Consumer le in dark Support cases Sync logic to fix problems Consequences

7.3

slide-38
SLIDE 38

Desired characteristics Heal our broken state Know if events are missing Redelivery of missing events

7.4

slide-39
SLIDE 39

"Event streams with possibility of redelivery" Take 2 "Ordered event streams with possibility of redelivery"

7.5

slide-40
SLIDE 40

Revisiting the event sourcing patterns Bootstrapping was about redelivery from scratch Redelivery from any event

7.6

slide-41
SLIDE 41

Self healing Service listens for events Receives event #1 Moves cursor to #1 Receives event #3 Request events since #1 Get event #2 Moves cursor to #2 Continue on event #3

7.7

slide-42
SLIDE 42

Pitfalls many streams missing events detected when new event arrives lost last event eventually never consistent driing state

7.8

slide-43
SLIDE 43

Reconstitution Like syncing state, but generic Walk over all known event streams Ask upstream service for events since "internal cursor" Either we receive nothing ✅ up to date we receive events ✅ get up to date Problem solved. Thanks event sourcing

7.9

slide-44
SLIDE 44

8.1

slide-45
SLIDE 45

deprecate existing data add new data modify existing data

8.2

slide-46
SLIDE 46

8.3

slide-47
SLIDE 47

hard coupling via events no versioning

  • nly additive changes

coordinated migrations

8.4

slide-48
SLIDE 48

events detached from producer events cannot be updated consumers must adapt

8.5

slide-49
SLIDE 49

Evolution as an ordinary, daily thing?

"If it hurts, do it more oen"

8.6

slide-50
SLIDE 50

producer owns events ability to map events to new models controlled, step-wise migrations

8.7

slide-51
SLIDE 51

Event sourcing as a solution "Ordered, persisted event streams with easy re- delivery" ➕ integration events on the outside versioning of projections walkers for hydration

8.8

slide-52
SLIDE 52

about integration events... internal events can be used for multiple integration event streams

  • move to new integration events

through a non-blocking migration

8.9

slide-53
SLIDE 53

Producer add new projection ... ... ... ...

  • ld projection

Consumers ... extend consumer 1 extend consumer 2

  • ld projection in consumer 2
  • ld projection in consumer 1

...

mutual agreements strict coordination

8.10

slide-54
SLIDE 54

saw problems in old architecture characteristics to eliminate problems found solutions in event sourcing

9.1

slide-55
SLIDE 55

Things to take into account not an off the shelf product developing a framework is costly introducing a new service design paradigm is hard solid patterns, easy to improve

9.2

slide-56
SLIDE 56

A look from above A pattern emerges Pain ➡ Normal Focus on business domain and iterating... over & over

9.3

slide-57
SLIDE 57

If It Hurts, Do It More Frequently, and Bring the Pain Forward

  • Jez Humble

9.4

slide-58
SLIDE 58

hurt to validate state bootstrapping was hurtful change is cumbersome & hard check state all the time redelivery as a daily pratice change as an enjoyable thing

9.5

slide-59
SLIDE 59

We wont lie It's not an easy solution, but these characteristics & guarantees lead to reliable improvable microservices

9.6

slide-60
SLIDE 60

questions?

10.1

slide-61
SLIDE 61

thanks

Thomas Bøgh Fangel @tbfangel Emil Krog Ingerslev @emilingerslev

10.2