Presenters Phillipa Avery Robert Reta Senior Software Engineer - - PowerPoint PPT Presentation

presenters
SMART_READER_LITE
LIVE PREVIEW

Presenters Phillipa Avery Robert Reta Senior Software Engineer - - PowerPoint PPT Presentation

Presenters Phillipa Avery Robert Reta Senior Software Engineer Senior Software Engineer Project Technical Lead and Engineer Event Sourcing System Architect Downloads License Accounting Downloads License Accounting pavery@Netflix.com /


slide-1
SLIDE 1
slide-2
SLIDE 2

Presenters

Phillipa Avery

Senior Software Engineer Project Technical Lead and Engineer Downloads License Accounting pavery@Netflix.com / @PhillipaAvery

Robert Reta

Senior Software Engineer Event Sourcing System Architect Downloads License Accounting rreta@netflix.com / @rreta04

slide-3
SLIDE 3

Phillipa Robert

slide-4
SLIDE 4

Overview

  • 1. Why do we need a Downloads License Accounting

Service?

  • 2. Event Sourcing overview.
  • 3. Deep dive into the Event Sourcing Architecture.
  • 4. What’s it like working with the License Accounting

Service after release?

slide-5
SLIDE 5

LICENSE CREATE PLAYBACK CONTEXT SESSION EVENTS (START, PAUSE, RESUME, KEEPALIVE)

Streaming Playback Lifecycle

slide-6
SLIDE 6

RELEASE LICENSE SESSION EVENT (STOP)

STOP

Streaming Playback Lifecycle

slide-7
SLIDE 7

LICENSE CREATE PLAYBACK CONTEXT DOWNLOADED ENCODED MOVIE

Downloads Playback Lifecycle

slide-8
SLIDE 8

~ 1 year

SESSION EVENTS (START, PAUSE, RESUME, KEEPALIVE, STOP) RENEW LICENSE?

X

RELEASE LICENSE

Downloads Playback Lifecycle

slide-9
SLIDE 9

Download Business Requirements

  • Devices with downloads
slide-10
SLIDE 10

Download Business Requirements

  • Devices with downloads
  • Downloads per studio
slide-11
SLIDE 11

Download Business Requirements

  • Devices with downloads
  • Downloads per studio
  • Movie downloads or playback over year

~ 1 year

slide-12
SLIDE 12

License Accounting Service Requirements

❏ Flexible ❏ Debuggable ❏ Reliable ❏ Scalable

F l e x i b i l i t y Debuggability S c a l a b i l i t y R e l i a b i l i t y

slide-13
SLIDE 13

License Accounting Service Requirements...

✓ Flexible: data model can be changed

❏ RDBMS ❏ Document Model

slide-14
SLIDE 14

License Accounting Service Requirements...

✓ Flexible: data model can be changed

❏ RDBMS ❏ Document Model

✓ Debuggable

❏ Event Sourcing

slide-15
SLIDE 15

License Accounting Service Requirements...

✓ Flexible: data model can be changed

❏ RDBMS ❏ Document Model

✓ Debuggable

❏ Event Sourcing ✓ Reliable ❏ Fallbacks

slide-16
SLIDE 16

License Accounting Service Requirements...

✓ Flexible: data model can be changed

❏ RDBMS ❏ Document Model

✓ Debuggable

❏ Event Sourcing ✓ Reliable ❏ Fallbacks ✓ Scalable

slide-17
SLIDE 17

Event Sourcing

slide-18
SLIDE 18

Domain Model

slide-19
SLIDE 19

Make Purple Command

Commands

slide-20
SLIDE 20

Commands

Make Purple Command

Command Handler

slide-21
SLIDE 21

Added Red Event Added Blue Event Make Purple Command

Command Handler

Commands

slide-22
SLIDE 22

Events

Added Red Event Added Blue Event

Event Handler

slide-23
SLIDE 23

Events

Added Blue Event

Event Handler

slide-24
SLIDE 24

Domain Model

slide-25
SLIDE 25

Aggregate

slide-26
SLIDE 26

Commands

Make Red Command

Command Handler

slide-27
SLIDE 27

Command Handler

Commands

Make Red Command

slide-28
SLIDE 28

Aggregate Service

REST Endpoint

Aggregate Repository

Event Store

Query Query Query

slide-29
SLIDE 29

Event Store

Row ID Events

slide-30
SLIDE 30

Event Store

Row ID Events

slide-31
SLIDE 31

Row ID Events

e1

e2 e3 e5 e6 e7 e4

Event Store

Aggregate id 1 Aggregate id 2

slide-32
SLIDE 32

Aggregate Repository

Query

Event Store

slide-33
SLIDE 33

Aggregate Repository Event Store

Query

select * from events where rowId =

slide-34
SLIDE 34

Aggregate Repository Event Store

Response

e1

e2 e3 e5 e6 e7 e4

slide-35
SLIDE 35

Aggregate Repository

e1

e2 e3 e5 e6 e7 e4

Aggregate id 1 Aggregate id 2

e1

e2 e5 e6 e3 e4 e7

slide-36
SLIDE 36

Aggregate Repository

Aggregate id 2 Aggregate id 1

e1

e2 e5 e6 e3 e4 e7 Aggregate 1 Aggregate 2

slide-37
SLIDE 37

Aggregate Repository

Aggregate 2 Aggregate 1

Aggregate id 2 Aggregate id 1

e1

e2 e5 e6 e3 e4 e7

slide-38
SLIDE 38

Aggregate Repository

Aggregate 2 Aggregate 1

Aggregate id 2 Aggregate id 1

e2

e5 e6 e3 e7

slide-39
SLIDE 39

Aggregate Repository

Aggregate 2 Aggregate 1

Aggregate id 2 Aggregate id 1

e5

e6 e7

slide-40
SLIDE 40

Aggregate Repository

Aggregate 2 Aggregate 1

Aggregate id 2 Aggregate id 1

e6

slide-41
SLIDE 41

Aggregate Repository

Aggregate 2 Aggregate 1

slide-42
SLIDE 42

Aggregate Repository

Command

Aggregate 1

Command Handler

slide-43
SLIDE 43

Aggregate Repository

Command Handler

e8 e9

slide-44
SLIDE 44

Aggregate Repository

e8 e9 Aggregate 1

slide-45
SLIDE 45

Aggregate Repository

Aggregate 1 e8 e9

slide-46
SLIDE 46

Aggregate Repository

Aggregate 1 e9

slide-47
SLIDE 47

Aggregate Repository

Aggregate 1

slide-48
SLIDE 48

Aggregate Repository Event Store

Update

append events where rowId =

e8 e9

slide-49
SLIDE 49

Event Store

Aggregate id 1 Aggregate id 2 Row ID Events

e1

e2 e3 e5 e6 e7 e4 e8 e9

slide-50
SLIDE 50

Aggregate Repository

Query

Aggregate Service

Get all aggregates for a customer

slide-51
SLIDE 51

Aggregate Repository Aggregate Service

Response Aggregate 2 Aggregate 1

slide-52
SLIDE 52

Aggregate

Downloaded Aggregate License Aggregate

slide-53
SLIDE 53

License Service Acquire License Endpoint

Query

customerId: Bayley titleId: GlowS01E01

slide-54
SLIDE 54

License Service

Query

customerId: Bayley titleId: GlowS01E01

Downloaded Service

isAllowed?

slide-55
SLIDE 55

Query

customerId: Bayley titleId: GlowS01E01 since: 6/27/2016

Downloaded Service Downloaded Repository

getAggregates

slide-56
SLIDE 56

Downloaded Service Downloaded Repository Response Downloaded Aggregate customerId: Bayley titleId: GlowS01E01 date: 2/15/2017 Downloaded Aggregate customerId: Bayley titleId: GlowS01E01 date: 5/25/2017

slide-57
SLIDE 57

License Service Downloaded Service Response

isAllowed?

aggregates.size() < yearly limit

slide-58
SLIDE 58

License Service Downloaded Service Response

isAllowed?

True

aggregates.size() < yearly limit (2) < (3)

slide-59
SLIDE 59

License Service

Update

License Repository

Create Aggregate

Create License Command customerId: Bayley titleId: GlowS01E01 date: 6/27/2017 License Aggregate customerId: titleId: expires: released:

slide-60
SLIDE 60

License Repository

Command Handler

Create License Command customerId: Bayley titleId: GlowS01E01 date: 6/27/2017 License Aggregate customerId: titleId: expires: released:

slide-61
SLIDE 61

License Repository

Command Handler

Create License Command customerId: Bayley titleId: GlowS01E01 date: 6/27/2017 License Aggregate customerId: titleId: expires: released:

License Created Event

customerId: Bayley titleId: GlowS01E01 date: 6/27/2017

slide-62
SLIDE 62

License Repository

Event Handler

License Aggregate customerId: titleId: expires: released:

License Created Event

customerId: Bayley titleId: GlowS01E01 date: 6/27/2017 License Aggregate customerId: Bayley titleId: GlowS01E01 expires: 7/27/2017 released: false

slide-63
SLIDE 63

License Repository

Event Store

Save

License Created Event

customerId: Bayley titleId: GlowS01E01 date: 6/27/2017

slide-64
SLIDE 64

License Service License Repository

Create Aggregate

Created

Acquire License Endpoint

Response

slide-65
SLIDE 65

License Service License Repository Response

isAllowed?

aggregates.filter(GlowS01E01) .size() < yearly limit

Get all licenses

slide-66
SLIDE 66

Table

Partition Keys Clustering Columns Columns

slide-67
SLIDE 67

Event Table

rowId

text

Event Time

timestamp

Event Data

blob

Aggregate Id

text

Event Mapper

String

slide-68
SLIDE 68
  • A fast and efficient object graph serialization framework for Java

○ https://github.com/EsotericSoftware/kryo

  • Able to preconfigure the library to your data models for extra compaction
  • Custom serializers
slide-69
SLIDE 69

AggregateId

text

Event Data

blob

rowId

text

Event Time

timestamp

House of Cards LicenseCreated

Matt:LicenseAggregate

Buddy Thunderstruck LicenseCreated 1 The Hardy Boys LicenseCreated

Jeff:LicenseAggregate

2

slide-70
SLIDE 70

AggregateId

text

Event Data

blob

rowId

text

Event Time

timestamp

House of Cards LicenseCreated

Matt:LicenseAggregate

House of Cards

LicenseReleased

3 Buddy Thunderstruck LicenseCreated 1 The Hardy Boys LicenseCreated

Jeff:LicenseAggregate

2

slide-71
SLIDE 71

AggregateId

text

Event Data

blob

rowId

text

Event Time

timestamp

House of Cards LicenseCreated

Matt:LicenseAggregate

House of Cards

LicenseReleased

3 Buddy Thunderstruck LicenseCreated 1 The Hardy Boys LicenseCreated

Jeff:LicenseAggregate

2

slide-72
SLIDE 72

AggregateId

text

Event Data

blob

rowId

text

Event Time

timestamp

House of Cards LicenseCreated

Matt:LicenseAggregate

House of Cards

LicenseReleased

3 Buddy Thunderstruck LicenseCreated 1 The Hardy Boys LicenseCreated

Jeff:LicenseAggregate

2

slide-73
SLIDE 73

Snapshotting

House of Cards LicenseCreated Matt:LicenseAggregate House of Cards LicenseReleased 3 Buddy Thunderstruck LicenseCreated 1 Master of None LicenseCreated Master of None LicenseReleased 3 Bojack LicenseCreated 1 Lucha Underground LicenseCreated Lucha Underground LicenseReleased 3 Grace & Frankie LicenseCreated 1 House of Cards LicenseCreated

slide-74
SLIDE 74

Snapshot Table

rowId

text

version

int

Snapshot Data

blob

slide-75
SLIDE 75

Version

int

Event Data

blob

rowId

text

1 binaryData

Matt:LicenseAggregate

slide-76
SLIDE 76

AggregateId

text

Event Data

blob

rowId

text

Event Time

timestamp

House of Cards LicenseCreated

Matt:LicenseAggregate:0

House of Cards

LicenseReleased

Matt:LicenseAggregate:1

3 Jessica Jones LicenseCreated 1 The Hardy Boys LicenseCreated

Jeff:LicenseAggregate:0

2

slide-77
SLIDE 77

Working With Event Sourcing

slide-78
SLIDE 78

Flexibility in Practice

  • Changes to the Data Model are trivial!

○ Device deactivation

slide-79
SLIDE 79

New Device Deactivation Requirement

Deactivate Device Endpoint Device Service Device Repository Device Aggregate

Device Deactivated Event

Deactivate Device Command

slide-80
SLIDE 80

New Device Deactivation Requirement...

Deactivate Device Endpoint Device Service

Deactivate Device

Can Deactivate?

Device Repository

Response

Device Aggregate

CustomerId: Bayley DeviceId: iPhone Deactivations: 1

slide-81
SLIDE 81

New Device Deactivation Requirement...

Deactivate Device Endpoint Device Service

Deactivate Device

Can Deactivate

License Service

Release Licenses

slide-82
SLIDE 82

Device Repository

Command Handler

Deactivate Device Command

customerId: Bayley deviceId: iPhone

Device Deactivated Event

customerId: Bayley deviceId: iPhone

Device Aggregate

CustomerId: Bayley DeviceId: iPhone Deactivations: 1

New Device Deactivation Requirement...

slide-83
SLIDE 83

Debugging

  • Possibly the biggest win
  • Current tooling is rudimentary

{ "Event" : "LicenseAcquiredEvent", "Event Time" : "2017-06-25 05:23:00 PM", "aggregateId" : "aggregateId1", "committed" : true, "eventTimeStamp" : 1498411380903, "eventOrderNumber" : 0 }

slide-84
SLIDE 84

Debugging...

Acquire License Event

customerId: Bayley deviceId: iPhone date: 01/05/2017

Release License Event

customerId: Bayley deviceId: iPhone date: 01/05/2017

Renew License Event

customerId: Bayley deviceId: iPhone date: 01/06/2017

License Aggregate

customerId:Bayley expires: 01/07/2017 released: True

slide-85
SLIDE 85

Reliability: Fallbacks

Edge API Layer License Accounting Service Client

License Accounting Service

Cassandra

Fallback Response

slide-86
SLIDE 86

How Did it Scale?

Predictive Scaling

slide-87
SLIDE 87

Scalability with Cassandra SSD (I2) Nodes

slide-88
SLIDE 88

Scalability with Cassandra SSD Nodes...

  • Could handle much higher loads
  • Storage use ramping up very quickly
slide-89
SLIDE 89

Storage Optimizations

  • TTLs
  • HDD (D2) clusters:

○ More storage ○ Higher latency (up to 1 second)

slide-90
SLIDE 90

Storage Optimizations...

  • Partitioned approach

○ Snapshot and subsequent events saved to i2 (SSD) cluster ○ Archive events to D2 (HDD) cluster

Snapshot Data

Version 3

Event Data

Version 3

Event Data

Version <= 2

i2 D2

slide-91
SLIDE 91

Storage Optimizations...

Partitioned approach using CQRS (Command Query Responsibility Segregation)

  • Write segregation

○ Event handlers that determine partitioned usage

  • Query segregation

○ Query SSD or HDD (or both) ○ Uninterrupted event stream

Event Data

i2

D2

Snapshot + Events

Event Handler

slide-92
SLIDE 92

Key Event Sourcing Take-Aways

  • Flexible: Adapting to change can be simple
slide-93
SLIDE 93

Key Event Sourcing Take-Aways

  • Flexible: Adapting to change can be simple
  • Debugging: Debugging data / state transitions greatly simplified
slide-94
SLIDE 94

Key Event Sourcing Take-Aways

  • Flexible: Adapting to change can be simple
  • Debugging: Debugging data / state transitions greatly simplified
  • Reliable: Fallbacks provide service reliability
slide-95
SLIDE 95

Key Event Sourcing Take-Aways

  • Flexible: Adapting to change can be simple
  • Debugging: Debugging data / state transitions greatly simplified
  • Reliable: Fallbacks provide service reliability
  • Scalable: Service scaled well, but good architectural solutions for

data storage solutions should be considered.

slide-96
SLIDE 96

Questions?

Phillipa Avery

Senior Software Engineer Project Technical Lead and Engineer Downloads License Accounting pippa@netflix.com / @PhillipaAvery

Robert Reta

Senior Software Engineer Event Sourcing System Architect Downloads License Accounting rreta@netflix.com / @rreta04