SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
Event Sourcing
& CQRS
Retour d'expérience

Etienne Neveu
@eneveu

Thursday, June 27, 13

Sfeir Plays

Maher TEBOURBI
@mtebourbi
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 Logic

Output
Buffer

• Domain Model
• Logique métier
• Consumers

Évènements de sortie:
- persistence
- appels WS externes
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
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
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
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
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
Multimap
BiMap

Thursday, June 27, 13
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
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
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
In-Memory Model - Memory Size

http://commons.wikimedia.org/wiki/File:Hard_disk_Western_Digital_WD740_1_(dark1).jpg
Thursday, June 27, 13
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

Weitere ähnliche Inhalte

Was ist angesagt?

Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Ontico
 

Was ist angesagt? (20)

The Ring programming language version 1.5.1 book - Part 60 of 180
The Ring programming language version 1.5.1 book - Part 60 of 180The Ring programming language version 1.5.1 book - Part 60 of 180
The Ring programming language version 1.5.1 book - Part 60 of 180
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6
 
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210
 
Rxjs vienna
Rxjs viennaRxjs vienna
Rxjs vienna
 
継承だろJK
継承だろJK継承だろJK
継承だろJK
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
The Ring programming language version 1.2 book - Part 45 of 84
The Ring programming language version 1.2 book - Part 45 of 84The Ring programming language version 1.2 book - Part 45 of 84
The Ring programming language version 1.2 book - Part 45 of 84
 
CodiLime Tech Talk - Katarzyna Ziomek-Zdanowicz: RxJS main concepts and real ...
CodiLime Tech Talk - Katarzyna Ziomek-Zdanowicz: RxJS main concepts and real ...CodiLime Tech Talk - Katarzyna Ziomek-Zdanowicz: RxJS main concepts and real ...
CodiLime Tech Talk - Katarzyna Ziomek-Zdanowicz: RxJS main concepts and real ...
 
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
The Ring programming language version 1.5.3 book - Part 73 of 184
The Ring programming language version 1.5.3 book - Part 73 of 184The Ring programming language version 1.5.3 book - Part 73 of 184
The Ring programming language version 1.5.3 book - Part 73 of 184
 
Pemrograman visual
Pemrograman visualPemrograman visual
Pemrograman visual
 
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
 
React. Redux. Real world.
React. Redux. Real world.React. Redux. Real world.
React. Redux. Real world.
 
The Ring programming language version 1.5.2 book - Part 62 of 181
The Ring programming language version 1.5.2 book - Part 62 of 181The Ring programming language version 1.5.2 book - Part 62 of 181
The Ring programming language version 1.5.2 book - Part 62 of 181
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
 
The Ring programming language version 1.10 book - Part 76 of 212
The Ring programming language version 1.10 book - Part 76 of 212The Ring programming language version 1.10 book - Part 76 of 212
The Ring programming language version 1.10 book - Part 76 of 212
 
The Ring programming language version 1.5.2 book - Part 59 of 181
The Ring programming language version 1.5.2 book - Part 59 of 181The Ring programming language version 1.5.2 book - Part 59 of 181
The Ring programming language version 1.5.2 book - Part 59 of 181
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
 
A promise is a Promise
A promise is a PromiseA promise is a Promise
A promise is a Promise
 

Ähnlich wie Event Sourcing & CQRS

Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
ShriKant Vashishtha
 
Drupal in aerospace - selling geodetic satellite data with Commerce - Martin ...
Drupal in aerospace - selling geodetic satellite data with Commerce - Martin ...Drupal in aerospace - selling geodetic satellite data with Commerce - Martin ...
Drupal in aerospace - selling geodetic satellite data with Commerce - Martin ...
DrupalCamp MSK
 
mDevCamp - The Best from Google IO
mDevCamp - The Best from Google IOmDevCamp - The Best from Google IO
mDevCamp - The Best from Google IO
ondraz
 
Architecting JavaScript Code
Architecting JavaScript CodeArchitecting JavaScript Code
Architecting JavaScript Code
Suresh Balla
 

Ähnlich wie Event Sourcing & CQRS (20)

Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Presentation Android Architecture Components
Presentation Android Architecture ComponentsPresentation Android Architecture Components
Presentation Android Architecture Components
 
Pragmatic Functional Refactoring with Java 8
Pragmatic Functional Refactoring with Java 8Pragmatic Functional Refactoring with Java 8
Pragmatic Functional Refactoring with Java 8
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Drupal in aerospace - selling geodetic satellite data with Commerce - Martin ...
Drupal in aerospace - selling geodetic satellite data with Commerce - Martin ...Drupal in aerospace - selling geodetic satellite data with Commerce - Martin ...
Drupal in aerospace - selling geodetic satellite data with Commerce - Martin ...
 
mDevCamp - The Best from Google IO
mDevCamp - The Best from Google IOmDevCamp - The Best from Google IO
mDevCamp - The Best from Google IO
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture Components
 
Architecting JavaScript Code
Architecting JavaScript CodeArchitecting JavaScript Code
Architecting JavaScript Code
 
Innovative Specifications for Better Performance Logging and Monitoring
Innovative Specifications for Better Performance Logging and MonitoringInnovative Specifications for Better Performance Logging and Monitoring
Innovative Specifications for Better Performance Logging and Monitoring
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
 
How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy Code
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
Aspect-Oriented Programming (AOP) in .NET
Aspect-Oriented Programming (AOP) in .NETAspect-Oriented Programming (AOP) in .NET
Aspect-Oriented Programming (AOP) in .NET
 
Применение паттерна Page Object для автоматизации веб сервисов
Применение паттерна Page Object для автоматизации веб сервисовПрименение паттерна Page Object для автоматизации веб сервисов
Применение паттерна Page Object для автоматизации веб сервисов
 
Time-driven applications
Time-driven applicationsTime-driven applications
Time-driven applications
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Event Sourcing & CQRS

  • 1. Event Sourcing & CQRS Retour d'expérience Etienne Neveu @eneveu Thursday, June 27, 13 Sfeir Plays Maher TEBOURBI @mtebourbi
  • 12. Event Business Processor Input Buffer Thursday, June 27, 13 Business Logic Output Buffer
  • 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. 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. 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. 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. 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. Mono threading - Synchronisation synchronized ConcurrentHashMap volatile ReentrantLock Thursday, June 27, 13
  • 21. Mono threading - I/O Thursday, June 27, 13
  • 22. In-Memory Model - Persistence and caching Thursday, June 27, 13
  • 23. In-Memory Model - DDD Thursday, June 27, 13
  • 24. In-Memory Model - Data structures CopyOnWriteArrayList ConcurrentHashMap ReentrantLock HashSet HashMap ArrayList Multimap BiMap Thursday, June 27, 13
  • 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. 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. 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. In-Memory Model - Memory Size http://commons.wikimedia.org/wiki/File:Hard_disk_Western_Digital_WD740_1_(dark1).jpg Thursday, June 27, 13
  • 30. Snapshots - Sérialisation Protocol Buffers Thursday, June 27, 13
  • 31. Snapshots - Migration Snapshot V4 Messages Protobuf V4 Thursday, June 27, 13 Snapshot V5 Messages Protobuf V5
  • 32. BV1 Data Batch Layer BV2 BV3 Event V2 Event Source Server RTV2 RTV3 Speed Layer Thursday, June 27, 13