Event Sourcing
& CQRS
Retour d'expérience

Etienne Neveu
@eneveu

Thursday, June 27, 13

Sfeir Plays

Maher TEBOURBI
@mteb...
Thursday, June 27, 13
Thursday, June 27, 13
Urban Power

Thursday, June 27, 13
Thursday, June 27, 13
Thursday, June 27, 13
Thursday, June 27, 13
Thursday, June 27, 13
UI

Rest API

AMQP

MDM Server

Adapters
MySql

Tomcat

Thursday, June 27, 13

Cassandra
RawDatapoint

Validation

Estimation

Context

Persistence

CEP

Aggregation

MySQL

Thursday, June 27, 13

Cassandra
UI

Rest API

MDM Server
Adapters
Netty

Thursday, June 27, 13

Cassandra
Event
Business Processor

Input
Buffer

Thursday, June 27, 13

Business Logic

Output
Buffer
Consumer
Handler 1

3

4

2

5

1

6

12

7

Handler 2

Producer

8

11
10

9
Handler n

Thursday, June 27, 13
Log

Business
Processor

Timer

Input Ring

Input

Pub

Output Ring

Commit
Replicator

Thursday, June 27, 13

Response
Business Processor - Intro

Event
Business Processor

Input
Buffer

Évènements d'entrée

Thursday, June 27, 13

Business L...
Business Processor - Évènement d'entrée
@Immutable
public	
  class	
  RawDatapointEvent	
  {
	
  	
  	
  private	
  final	...
Business Processor - Consumer
public	
  class	
  RawDatapointEventConsumer	
  implements	
  EventConsumer<RawDatapointEven...
Business Processor - Évènement de résultat
@Immutable
public	
  class	
  RawDatapointEvent	
  {
	
  	
  	
  //	
  fields,	...
Business Processor - Code client
RawDatapointEvent	
  rawEvent	
  =	
  createRawEventFromJson(httpRequest.getContent());
	...
Mono threading - Synchronisation

synchronized
ConcurrentHashMap

volatile

ReentrantLock

Thursday, June 27, 13
Mono threading - I/O

Thursday, June 27, 13
In-Memory Model - Persistence and caching

Thursday, June 27, 13
In-Memory Model - DDD

Thursday, June 27, 13
In-Memory Model - Data structures
CopyOnWriteArrayList
ConcurrentHashMap

ReentrantLock

HashSet
HashMap
ArrayList
Multima...
In-Memory Model - Immutability
@Immutable
public	
  final	
  class	
  Money	
  {
	
  
	
  	
  	
  //	
  I	
  swear,	
  tho...
In-Memory Model - Immutability
@Immutable
public	
  final	
  class	
  Money	
  {
	
  
	
  	
  	
  private	
  final	
  BigD...
In-Memory Model - Managers
public	
  class	
  UserManager	
  {
	
  
	
  	
  	
  private	
  final	
  Map<String,	
  User>	
...
In-Memory Model - Memory Size

http://commons.wikimedia.org/wiki/File:Hard_disk_Western_Digital_WD740_1_(dark1).jpg
Thursd...
Snapshots - Intro

Thursday, June 27, 13
Snapshots - Sérialisation

Protocol Buffers

Thursday, June 27, 13
Snapshots - Migration

Snapshot
V4

Messages
Protobuf
V4

Thursday, June 27, 13

Snapshot
V5

Messages
Protobuf
V5
BV1
Data

Batch Layer

BV2
BV3

Event

V2

Event Source Server

RTV2
RTV3
Speed Layer

Thursday, June 27, 13
Thursday, June 27, 13
Upcoming SlideShare
Loading in …5
×

Event Sourcing & CQRS

832 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
832
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Event Sourcing & CQRS

  1. 1. Event Sourcing & CQRS Retour d'expérience Etienne Neveu @eneveu Thursday, June 27, 13 Sfeir Plays Maher TEBOURBI @mtebourbi
  2. 2. Thursday, June 27, 13
  3. 3. Thursday, June 27, 13
  4. 4. Urban Power Thursday, June 27, 13
  5. 5. Thursday, June 27, 13
  6. 6. Thursday, June 27, 13
  7. 7. Thursday, June 27, 13
  8. 8. Thursday, June 27, 13
  9. 9. UI Rest API AMQP MDM Server Adapters MySql Tomcat Thursday, June 27, 13 Cassandra
  10. 10. RawDatapoint Validation Estimation Context Persistence CEP Aggregation MySQL Thursday, June 27, 13 Cassandra
  11. 11. UI Rest API MDM Server Adapters Netty Thursday, June 27, 13 Cassandra
  12. 12. Event Business Processor Input Buffer Thursday, June 27, 13 Business Logic Output Buffer
  13. 13. Consumer Handler 1 3 4 2 5 1 6 12 7 Handler 2 Producer 8 11 10 9 Handler n Thursday, June 27, 13
  14. 14. Log Business Processor Timer Input Ring Input Pub Output Ring Commit Replicator Thursday, June 27, 13 Response
  15. 15. Business Processor - Intro Event Business Processor Input Buffer Évènements d'entrée Thursday, June 27, 13 Business Logic Output Buffer • Domain Model • Logique métier • Consumers Évènements de sortie: - persistence - appels WS externes
  16. 16. Business Processor - Évènement d'entrée @Immutable public  class  RawDatapointEvent  {      private  final  String  sensorId;      private  final  DateTime  measureTime;      private  final  double  value;      public  RawDatapointEvent(String  sensorId,  DateTime  measureTime,  double  value)  {            this.sensorId  =  sensorId;            this.measureTime  =  measureTime;            this.value  =  value;      }      public  String  getSensorId()  {  return  sensorId;  }      public  DateTime  getMeasureTime()  {  return  measureTime;  }      public  double  getValue()  {  return  value;  } } Thursday, June 27, 13
  17. 17. Business Processor - Consumer public  class  RawDatapointEventConsumer  implements  EventConsumer<RawDatapointEvent>  {      @Inject      DatapointPreprocessingService  preprocessingService;      @Override      public  void  consume(RawDatapointEvent  rawEvent,                                              Model  model,                                              EventProcessor  eventProcessor)  {            PreprocessingResult  result  =  preprocessingService.preprocess(model,  rawEvent);            if  (result.hasError())  {                  eventProcessor.sendReply(new  FailedDatapointResult(result.getErrorMsg()));            }            eventProcessor.sendReply(new  SuccessfulDatapointResult());            eventProcessor.process(                  new  AddDatapointToTimeSeriesEvent(result.getAccount(),                                                                                      result.getSensor().getTimeSeries(),                                                                                      result.getDatapoint()                  )            );      } } Thursday, June 27, 13
  18. 18. Business Processor - Évènement de résultat @Immutable public  class  RawDatapointEvent  {      //  fields,  constructor,  getters...      public  interface  Result  {}      public  static  class  SuccessfulDatapointResult  implements  Result  {}      public  static  class  FailedDatapointResult  implements  Result  {                private  final  String  errorMessage;                public  FailedDatapointResult(String  errorMessage)  {                      this.errorMessage  =  errorMessage;              }                public  String  getErrorMessage()  {                      return  errorMessage;              }      } } Thursday, June 27, 13
  19. 19. Business Processor - Code client RawDatapointEvent  rawEvent  =  createRawEventFromJson(httpRequest.getContent());   ListenableFuture<RawDatapointEvent.Result>  future  =  client.sendEvent(rawEvent);   Futures.addCallback(future,  new  FutureCallback<RawDatapointEvent.Result>()  {      @Override      public  void  onSuccess(RawDatapointEvent.Result  result)  {              ...      }        @Override      public  void  onFailure(Throwable  t)  {              ...      } }); Thursday, June 27, 13
  20. 20. Mono threading - Synchronisation synchronized ConcurrentHashMap volatile ReentrantLock Thursday, June 27, 13
  21. 21. Mono threading - I/O Thursday, June 27, 13
  22. 22. In-Memory Model - Persistence and caching Thursday, June 27, 13
  23. 23. In-Memory Model - DDD Thursday, June 27, 13
  24. 24. In-Memory Model - Data structures CopyOnWriteArrayList ConcurrentHashMap ReentrantLock HashSet HashMap ArrayList Multimap BiMap Thursday, June 27, 13
  25. 25. In-Memory Model - Immutability @Immutable public  final  class  Money  {        //  I  swear,  those  are  final!      private  BigDecimal  amount;      private  Currency  currency;      //  For  Hibernate  only!      Money()  {}      public  Money(BigDecimal  amount,  Currency  currency)  {            this.amount  =  amount;            this.currency  =  currency;      }      public  BigDecimal  getAmount()  {  return  amount;  }      public  Currency  getCurrency()  {  return  currency;  }      //  For  Hibernate  only!      void  setAmount(BigDecimal  amount)  {  this.amount  =  amount;  }      void  setCurrency(Currency  currency)  {  this.currency  =  currency;  } } Thursday, June 27, 13
  26. 26. In-Memory Model - Immutability @Immutable public  final  class  Money  {        private  final  BigDecimal  amount;        private  final  Currency  currency;        public  Money(BigDecimal  amount,  Currency  currency)  {              this.amount  =  amount;              this.currency  =  currency;      }        public  BigDecimal  getAmount()  {              return  amount;      }        public  Currency  getCurrency()  {              return  currency;      }   } Thursday, June 27, 13
  27. 27. In-Memory Model - Managers public  class  UserManager  {        private  final  Map<String,  User>  users  =  Maps.newHashMap();        public  void  add(@Nonnull  User  user)  {              users.put(user.primaryKey(),  user);      }        public  void  remove(@Nonnull  String  userId)  {              User  removedUser  =  users.remove(userId);              if  (removedUser  ==  null)  throw  new  UserNotFoundException(userId);        }        public  User  getById(@Nonnull  String  userId)  {              User  user  =  users.get(userId);              if  (user  ==  null)  throw  new  UserNotFoundException(userId);              return  user;      }        public  List<User>  getAll()  {              return  ImmutableList.copyOf(users.values());      }   } Thursday, June 27, 13
  28. 28. In-Memory Model - Memory Size http://commons.wikimedia.org/wiki/File:Hard_disk_Western_Digital_WD740_1_(dark1).jpg Thursday, June 27, 13
  29. 29. Snapshots - Intro Thursday, June 27, 13
  30. 30. Snapshots - Sérialisation Protocol Buffers Thursday, June 27, 13
  31. 31. Snapshots - Migration Snapshot V4 Messages Protobuf V4 Thursday, June 27, 13 Snapshot V5 Messages Protobuf V5
  32. 32. BV1 Data Batch Layer BV2 BV3 Event V2 Event Source Server RTV2 RTV3 Speed Layer Thursday, June 27, 13
  33. 33. Thursday, June 27, 13

×