際際滷

際際滷Share a Scribd company logo
CQRS
with
JOliver Event Storev3
弍 舒于仂亠
 22 countries
 20 banks integrations
 80,000 financial administrations
 50,000 users
 51% of Dutch market
 Own data center
 3500 concurrent users
 > 100 TPS
仂仂亞舒 从 CQRS
GUI
Database
access
Business
logicGUI
Database access
Business logic
GUI
GUI
Database access
GUI
Database access
Business logic
GUI
GUI Database
accessBusiness logic
GUI
Business
logic
Business logicGUI
Database access
GUI
Business
logic
Data
access
M$$SQL
GUI
Domain Model
ORM
Database
M$$SQL
GUI
Domain Model
ORM
Database
Lazy Loading !!!
OUCH!
M$$SQL
GUI
Domain Model
ORM
Database
DTO
M$$SQL
GUI
Domain Model
ORM
Database
DTO
Object-To-Object Mapping !!!
OUCH!
RDB
ORM
亠
Domain
8-仄亳 舒亢仆亶 SQL
 从亳 仂, 仆舒 仂?
RDB
从舒仄亳
亠
N 舒亢仆亶 SQL
(仗舒于亟舒, 仗仂亳亠 亳 仗仂弍亠亠, 亠仄  ORM)
SQL 从舒亳于仂 仗舒仆 亰舒
舒舒亟仂仄 舒仆亳仄
仗仂亠亟
RDB
DTO
Handcrafted SQL
ORM
Application
Services
Domain
Object
Domain
Object
Reporting
Services
3NF with optimizations
like 1NF in some places 
DTO DTO DTO
Form UI Reports UI
send
request
RDB
DTO
Handcrafted SQL
ORM
Application
Services
Domain
Object
Reporting
Services
DTO DTO DTO
Form UI Reports UI
亟亠
亢亳仆亠仆从仂
 仂 亟舒仍亠?
Data Storage
Command
Application
Services
Domain
Object
Query
Services
Client
Domain
Object
Query
Data Storage
DTO DTO
CQRS (did you mean Cars?)
Domain Model View Model
舒从 亳仆仂仆亳亰亳仂于舒 ?
ORMDomain Changeset Denormalizer
View Model
仂亠 束亳損 亳亰仄亠仆亠仆亳亶
亠仗仂亰舒仆亶 亞仂从
亟舒仆仆
CQRS
+
Event Sourcing
=
LOVE!
ORMDomain
Storage
丐亠从亠亠 仂仂礌亳亠
丐舒亟亳亳仂仆仆亶 仗仂亟仂亟
Domain Invoice
Created
Invoice
Approved
Invoice
Finalized
仆舒仍 于亠 亳亰仄亠仆亠仆亳亶
Event Sourcing
丐舒亟亳亳仂仆仆亶 仗仂亟仂亟
Event Sourcing
SRP 仆舒 仂于仆亠 仄亠仂亟舒 !
亳仆亳亠 亠亠仆亳 仂
于仂亰仄仂亢仆仂亳 仗亠亠仂亟舒
仂仂礌亳
(弍亳亰仆亠-仗舒于亳仍舒)
亠亠仂亟 仂仂礌亳
(舒仆亰亳仂)
弌仂弍于亠仆仆仂,
亳亰仄亠仆亠仆亳亠 仂仂礌亳
(舒仗仗仍亳从舒仂)
 从舒从 仂 舒弍仂舒亠?
 亳 从舒从 仂 于 舒弍仂舒亠?
仂舒仆仂于仍亠仆亳亠 亠从亠亞仂 仂仂礌亳
Invoice
Created
Invoice
Approved
Invoice
Finalized
仆舒仍 亳亰仄亠仆亠仆亳亶
1
2
3
弌仂舒仆亠仆亳亠 亳亰仄亠仆亠仆亳亶
Invoice
Approved
Invoice
Finalized
亠
弌仂舒仆亠仆亳亠 亳亰仄亠仆亠仆亳亶
Invoice
Approved
Invoice
Finalized
亠
Invoice
Created
仆舒仍 亳亰仄亠仆亠仆亳亶
1
append
2
Invoice
Approved
Invoice
Finalized3
Log.append(id, events)
events = Log.read(id)
丐亳于亳舒仍仆仂,
仆亠仗舒于亟舒 仍亳?
弍亠仗亠亠仆亳亠 仗舒舒仍仍亠仍仆仂亞仂 亟仂仗舒
舒舒仍仍亠仍仆亠 仄仂亟亳亳从舒亳亳
Invoice
Created
Invoice
Updated
Invoice
Finalized
update
Invoice
finalize
仗亳仄亳亳亠从舒 弍仍仂从亳仂于从舒
Invoice
Created
Stream
[ID:542]
1
Invoice
Created
Invoice
[ID:542]
1
load Invoice
Created
Invoice
[ID:542]
1
load
1
仗亳仄亳亳亠从舒 弍仍仂从亳仂于从舒
Invoice
Created
Stream
[ID:542]
1
2
Invoice
Finalized
load Invoice
Created
Invoice
[ID:542]
1
2 Invoice
Finalized
load
store
1
2
originalRevision = currentRevison
Invoice
Created
Invoice
[ID:542]
1
仗亳仄亳亳亠从舒 弍仍仂从亳仂于从舒
Invoice
Created
Stream
[ID:542]
1
2
Invoice
Finalized
22
Invoice
Updated
load
store
Invoice
Created
Invoice
[ID:542]
1
2 Invoice
Finalized
load
store
1
2
Invoice
Created
Invoice
[ID:542]
1
originalRevision != currentRevison
仂仗亳仄亠 仗舒舒仍仍亠仍仆亠 仄仂亟亳亳从舒亳亳
Transaction
Posted
Transaction
Posted
Transaction
Posted
post
General Ledger
post
丐亠从舒 亠于亳亰亳
舒亞亞亠亞舒舒 仆亠亟仂舒仂仆仂
仂从舒 仗仂亳亰于仂亟亳亠仍仆仂
亳仆亳仄舒仍仆仂亠 从仂仍亳亠于仂
仂仗亠舒亳亶 亰舒仗亳亳
E1
Aggregate Stream
Commit
E1 E1
pack
C1
serialize
亳仆亳仄舒仍仆仂亠 从仂仍亳亠于仂
仂仗亠舒亳亶 亰舒仗亳亳
Commit
E1
Aggregate
E2
E3
E2
E3
Stream
C2
E2
E3
Commit
E1 E1
pack
pack
C1
serialize
serialize
亳弍从亳亠 于仂亰仄仂亢仆仂亳 亠亳舒仍亳亰舒亳亳
 JSON
 Binary
 Custom (ProtoBuf, .NET, whatever)
 GZip
 亳仗仂于舒仆亳亠
仗亳仄亳亰舒亳 仂仗亠舒亳亳 于仂舒仆仂于仍亠仆亳
仂仂礌亳 仗亳 仗仂仄仂亳 束仆亳仄从仂于損
亞亞亠亞舒  仂亠仆
亟仍亳仆仆仄
亢亳亰仆亠仆仆仄
亳从仍仂仄 亳 从亠亶
亳于亠仆仂于
E1
E2

E100500
Snapshot
[rev: E100500]
E100501
restore
replay the rest
of events
舒仗亠亟亠仍亠仆仆舒 舒仆亰舒从亳
弌1 弌2 .. 弌n
Command Queue
Command Processor
Event Store
dequeue (C1)
store (E1, E2)
MSDTC
亠亰 2PC
弌1 弌2 .. 弌n
Command Queue
Command Processor
Event Store
0. peek (C1)
1. store (E1, E2)
2. remove (C1) T2
T1
亠亰 2PC 仆亠仂弍仂亟亳仄舒
仗仂亟亟亠亢从舒 亳亟亠仄仗仂亠仆仆仂亳
弌1 弌2 .. 弌n
Command Queue
Command Processor
Event Store
0. peek (C1)
1. store (弌1, [E1, E2]) 2. dup (弌1)
4. remove (弌1)
Commit
E1
E2
亠亰 2PC 仆亠仂弍仂亟亳仄舒
仗仂亟亟亠亢从舒 亳亟亠仄仗仂亠仆仆仂亳
弌1 弌2 .. 弌n
Command Queue
Command Processor
Event Store
0. peek (C1)
1. store (弌1, [E1, E2]) 2. dup (弌1)
4. remove (弌1)
Commit
E1
E2
ID : UUID
亠亰 2PC 仆亠仂弍仂亟亳仄舒
仗仂亟亟亠亢从舒 亳亟亠仄仗仂亠仆仆仂亳
弌1 弌2 .. 弌n
Command Queue
Command Processor
Event Store
0. peek (C1)
1. store (弌1, [E1, E2]) 2. dup (弌1)
4. remove (弌1)
Commit
E1
E2
ID : UUID
Command
ID : UUID
弍舒弍仂从舒 仂弍亳亶
Event Store View Model
E1 E2
publish update
2PC, 仂仗?
弍舒弍仂从舒 仂弍亳亶 (PULL)
Event Store View Model
Get new events since (Time)
舒仗仂仄亳仆舒 仗仂仍亠亟仆亠亠
仂弍舒弍仂舒仆仆仂亠 仂弍亳亠
弍舒弍仂从舒 仂弍亳亶 (PULL)
Event Store View Model
Get new events since (Time)
Commit
E1
E2
ID : UUID
弍舒弍仂从舒 仂弍亳亶 (PULL)
Event Store View Model
Get new events since (Time)
Commit
E1
E2
ID : UUID
Dispatched : bool
弍舒弍仂从舒 仂弍亳亶 (PULL)
Event Store View Model
Get undispatched events
Commit
E1
E2
ID : UUID
Dispatched : bool
mark as
dispatched
弍舒弍仂从舒 仂弍亳亶 (PUSH)
Event Store View Model
publish (commit)
Commit
E1
E2
ID : UUID
Dispatched : bool
亟亠仄仗仂亠仆仆仂 于仂
View Model 舒仆亳仍亳亠
仗仂-仗亠亢仆亠仄 仆亢仆舒 
mark as
dispatched
仂亠仆仆亶 亟亳仗亠亠 仂弍亳亶
BUS
Command
Processor
Event Store
cmd
events
commit Dispatcher
Event
Publisher
commit
events
Storage
Your App
commit
mark as dispatched
OK
仂亠仆仆亶 亟亳仗亠亠 仂弍亳亶
BUS
Command
Processor
Event Store
cmd
events
commit Dispatcher
Event
Publisher
commit
events
Storage
Your App
commit dispatched = false
FAIL
亳亠从舒
Commit
Event Store
Persistence Engine
Event Stream Commit
Event Message
Dispatcher
Storage
仂亟亟亠亢亳于舒亠仄亠 亠仆仂仍仂亞亳亳
舒仆亳仍亳舒 亟舒仆仆
Relational Databases:
 SQL Server 2005 (or later)
 MySQL
 Firebird
 Oracle (planned)
Embedded Relational Databases:
 SQL Server CE 3.5 (or later)
 SQLite 3.0 (or later)
 MS Access 2000 (or later)
Cloud-based Databases:
 MS SQL Azure
 Amazon RDS (MySQL)
 Azure Tables/Blobs (in progress)
 Amazon SimpleDB/S3 (in progress)
Document Databases
 RavenDB r322 (or later)
 MongoDB 1.6 (or later)
 CouchDB 1.0 (planned)
舒亳磳仄仂
亠舒亟舒仆亠
Commit
Event Message
Dictionary<string, object>
Dictionary<string, object>
Office, User, PrecedingMessageId
EventId, AggregateType
丱从亳
Event Store
Persistence Engine
Commit
亠仂 亟仍 于亠亰从亳 于
从仂仆于亠亶亠 仂弍舒弍仂从亳
Hook into:
 select
 pre-commit
 post-commit
丱从亳
亳仗舒亠  仂 于仂亠仆仆亶 从
亠舒仆亳亰仄 于仂仍ム亳亳
亠仄 仂弍亳亶
2 仗仂亟仂亟舒
 丐仂仍亠舒仆仆亶 亠亳舒仍亳亰舒仂
 亊于仆仂亠 于亠亳仂仆亳仂于舒仆亳亠
弌于舒仍从舒 舒仗仗仍亳从舒仂仂于 于 弍亳亰仆亠-舒亞亞亠亞舒亠
亠亠仄于亠仆仆仂 于亠亳亶
InvoiceCreated
InvoiceCreated_v2
InvoiceCreated_v3
convert to
convert to
丱从-从仂仆于亠亠 于 Event Store
仂亠从 CommonDomain
舒亰仂于亶 从仍舒 亟仍 亞亞亠亞舒仂于
亠仗仂亰亳仂亳亶 - DAO 亟仍 亞亞亠亞舒仂于
弍舒弍仂从舒 从仂仆仍亳从仂于 仗舒舒仍仍亠仍仆仂亞仂 亟仂仗舒
仂仗亳仄亠 仗舒舒仍仍亠仍仆亠 仄仂亟亳亳从舒亳亳
Transaction
Posted
Transaction
Posted
Transaction
Posted
post
General Ledger
post
亠亞从仂 仂亰亟舒于舒 仗亠亳舒仍亳亰亳仂于舒仆仆亠 仗仂仍亳亳从亳
仂仗亠亟亠仍亠仆亳 从仂仆仍亳从仂于 仗舒舒仍仍亠仍仆 亳亰仄亠仆亠仆亳亶
弌仍仂从亳:
 http://cqrs.wordpress.com
 https://github.com/joliver/EventStore
 https://github.com/joliver/CommonDomain
CQRS with JOliver EventStore v3

More Related Content

CQRS with JOliver EventStore v3

Editor's Notes

  1. 丐舒从 亰舒亠仄 亢亠 仆舒仄 仆亢仆舒, 仗亠亳舒仍仆舒 弍亳弍仍亳仂亠从舒, 亟仍 舒从仂亶, 仗仂仂亶 仂仗亠舒亳亳 从舒从 :
  2. 仗仂仍亰仂于舒仆亳亠 仂仗亳仄亳亳亠从仂亶 弍仍仂从亳仂于从亳 仗亳 仗仂仄仂亳 StreamRevision
  3. 仗仂仍亰仂于舒仆亳亠 仂仗亳仄亳亳亠从仂亶 弍仍仂从亳仂于从亳 仗亳 仗仂仄仂亳 StreamRevision
  4. originalRevision = currentRevison
  5. originalRevision != currentRevision
  6. 亳弍从亳亠 于仂亰仄仂亢仆仂亳 亠亳舒仍亳亰舒亳亳: JSON, BSON, Gzip, 从亳仗仂于舒仆亳亠 亠从仂舒仂
  7. 舒亳仆舒亠 从仍亳于亳仂于舒 仄仆亠仆亳亠 仂 亟仍亳仆仆亠 舒亞亠亞舒 亳 仆亠仂弍仂亟亳仄仂 仆舒仗仂仂于 于仂仂弍亠, 仂 仂亳弍从舒 亟亳亰舒亶仆舒
  8. 舒亳舒 仂 仗仂于仂仆仂亞仂 于仗仂仍仆亠仆亳 从仂仄舒仆亟 于 舒仄从舒 束at least once delivery損 亳仆舒从
  9. 舒亳舒 仂 仗仂于仂仆仂亞仂 于仗仂仍仆亠仆亳 从仂仄舒仆亟 于 舒仄从舒 束at least once delivery損 亳仆舒从
  10. 舒亳舒 仂 仗仂于仂仆仂亞仂 于仗仂仍仆亠仆亳 从仂仄舒仆亟 于 舒仄从舒 束at least once delivery損 亳仆舒从
  11. 舒亳舒 仂 仗仂于仂仆仂亞仂 于仗仂仍仆亠仆亳 从仂仄舒仆亟 于 舒仄从舒 束at least once delivery損 亳仆舒从
  12. 舒亳舒 仂 仗仂于仂仆仂亞仂 于仗仂仍仆亠仆亳 从仂仄舒仆亟 于 舒仄从舒 束at least once delivery損 亳仆舒从
  13. 亟亠仄仗仂亠仆仆仂 于仂 View Model 舒仆亳仍亳亠 于亠 亠亠 仆亢仆舒
  14. Sync or Async
  15. 亳 仍亠亟ム亠仄 亰舒仗从亠 于亠 舒仆亟亳仗舒亠亟 从仂仄仄亳 弍亟 仗仂于仂仆仂 亰舒亟亳仗舒亠仆
  16. File System [Planned] .NET Managed System.IO APIs Dynamo Clones [Planned] Cassandra [Planned] Riak KV Stores / NoSQL [Planned] Redis [Planned] Memcached (Membase, Gear6, etc.) [Planned] HBase
  17. 丱舒仆亠仆亳亠 仄亠舒亟舒仆仆 于 亰舒亞仂仍仂于从舒
  18. 亠亳仂仆亳仂于舒仆亳亠 于仂仄舒亳亠从亳亶 舒仗亞亠亶亟 (从仂仆于亠舒亳)
  19. 亠亳仂仆亳仂于舒仆亳亠 于仂仄舒亳亠从亳亶 舒仗亞亠亶亟 (从仂仆于亠舒亳)
  20. 亳仄亠仆亠仆亳亠 于 从仂仆亠从亠 DDD\CQRS 舒亳亠从
  21. 弌仍亳礌亳亠 仂弍亳亶
  22. 弌仍亳礌亳亠 仂弍亳亶