31
Acknowledging CAP at the Root in the Domain Model Eric Evans Domainlanguage.com Twi>er: ericevans0 #dddesign

Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Acknowledging  CAP  at  the  Root  -­‐-­‐  in  the  Domain  Model  

Eric  Evans  

Domainlanguage.com  

Twi>er:  ericevans0    #dddesign  

Page 2: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Gap  between  formalism  and    

 pracFce  

Page 3: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

2

4 2

1

Vessel  Voyage  XYZ  

OAK

LGB SHA

HKG

Page 4: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Vessel  Voyage  ABC  

SEA

LGB

SNG

Page 5: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Cargo  IFnerary  

SEA

LGB

HKG

Page 6: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Our  Cargo  Needs  2  Voyages  

Page 7: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Schedules  and  IFneraries  IFnerary  HKG-­‐SEA  

•  HKG-­‐LGB  on  XYZ  •  LGB-­‐  SEA  on  ABC  

EsFmated  Layover  in  LGB:    13:20  Th  –10:15  Sa  

 Elapsed:  45:55  

Voyage  Schedule  for  XYZ  •  ETD  HKG  08:30  Sa  

•  ETA  SHA  21:00  Sa  

•  ETD  SHA  06:30  Su  

•  ETA  LGB  13:20  Th  

•  …  

Voyage  Schedule  for  ABC  •  ETD  SNG  14:15  Tu  

•  ETA  LGB  22:05  Fr  

•  ETD  LGB  10:15  Sa  

•  ETA  SEA  07:40  Su  

 

Page 8: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

*

*

*

startLocationendLocationavailableTimelayover

cargoId OriginDestinationArrival DeadlineWeight ...

Schedule

vesselVoyageIdassignedVessel ...

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

loadLocationloadTime unloadLocationunloadTime

Leg

Itinerary

Cargo

Page 9: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Schedules  and  IFneraries  IFnerary  HKG-­‐SEA  

•  HKG-­‐LGB  on  XYZ  •  LGB-­‐  SEA  on  ABC  

EsFmated  Layover  in  LGB:    13:20  Th  –10:15  Sa  

 Elapsed:  45:55  

Voyage  Schedule  for  XYZ  •  ETD  HKG  08:30  Sa  

•  ETA  SHA  21:00  Sa  

•  ETD  SHA  06:30  Su  

•  ETA  LGB  13:20  Th  

•  …  

Voyage  Schedule  for  ABC  •  ETD  SNG  14:15  Tu  

•  ETA  LGB  22:05  Fr  

•  ETD  LGB  10:15  Sa  

•  ETA  SEA  07:40  Su  

 

Page 10: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Delay  IFnerary  HKG-­‐SEA  

•  HKG-­‐LGB  on  XYZ  •  LGB-­‐  SEA  on  ABC  

EsFmated  Layover  in  LGB:    13:20  Th  –10:15  Sa  

 Elapsed:  45:55  

Voyage  Schedule  for  XYZ  •  ETD  HKG  08:30  Sa  

•  ETA  SHA  21:00  Sa  

•  ETD  SHA  06:30  Su  

•  ETA  LGB  13:20  Th  

•  …  

Voyage  Schedule  for  ABC  •  ETD  SNG  14:15  Tu  

•  ETA  LGB  22:05  Fr  

•  ETD  LGB  10:15  Sa  

•  ETA  SEA  07:40  Su  

 

Page 11: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

New  Schedule  IFnerary  HKG-­‐SEA  

•  HKG-­‐LGB  on  XYZ  •  LGB-­‐  SEA  on  ABC  

EsFmated  Layover  in  LGB:    3:00  Sa  –10:15  Sa  

 Elapsed:  45:55    7:15  

Voyage  Schedule  for  XYZ  •  ETD  HKG  08:30  Sa  

•  ETA  SHA  21:00  Sa  

•  ETD  SHA  06:30  Su  

•  ETA  LGB  13:20  Th  3:00  Sa  (next)  

•  …  

Voyage  Schedule  for  ABC  •  ETD  SNG  14:15  Tu  

•  ETA  LGB  22:05  Fr  

•  ETD  LGB  10:15  Sa  (next)  

•  ETA  SEA  07:40  Su  (next)  

 

Page 12: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

*

*

*

startLocationendLocationavailableTimelayover

cargoId OriginDestinationArrival DeadlineWeight ...

Schedule

vesselVoyageIdassignedVessel ...

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

loadLocationloadTime unloadLocationunloadTime

Leg

Itinerary

Cargo

Page 13: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

•  IFnerary  corresponds  to  Vessel  Voyage  

•  IFnerary  connected  

•  Layover  >  24  hours        

Some  Consistency  Rules  

Page 14: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Mo unloadLocCode = LGBunloadTime = 13:20 Th

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

Page 15: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55 7:15

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Sa unloadLocCode = LGBunloadTime=13:20Th 3:00 Sa

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th 3:00 Sa

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

Page 16: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Aggregates  

Page 17: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Aggregates:    Consistency  Boundaries  

•  Aggregates  are  always  internally  consistent.  –  Invariants  apply  at  every  transacFon  commit  

•  Aggregates  “eventually  consistent”  with  each  other.  –  Asynchronous  updates  propagate  through  system    

•  Limit  Interconnectedness.  –  References  limited  to  aggregate  roots.  

Page 18: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Draw  Aggregate  Boundaries  

(But probably not these!)

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Sa unloadLocCode = LGBunloadTime = 13:20 Th

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

Page 19: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Allowed  State  IFnerary  HKG-­‐SEA  

•  HKG-­‐LGB  on  XYZ  •  LGB-­‐  SEA  on  ABC  

EsFmated  Layover  in  LGB:    3:00  Sa  –10:15  Sa  

 Elapsed:  45:55    

Voyage  Schedule  for  XYZ  •  ETD  HKG  08:30  Sa  

•  ETA  SHA  21:00  Sa  

•  ETD  SHA  06:30  Su  

•  ETA  LGB  13:20  Th  3:00  Sa  (next)  

•  …  

Voyage  Schedule  for  ABC  •  ETD  SNG  14:15  Tu  

•  ETA  LGB  22:05  Fr  

•  ETD  LGB  10:15  Sa  (next)  

•  ETA  SEA  07:40  Su  (next)  

 

Page 20: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Mo unloadLocCode = LGBunloadTime = 13:20 Th

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

Page 21: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Sa unloadLocCode = LGBunloadTime = 13:20 Th

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

Page 22: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Sa unloadLocCode = LGBunloadTime = 13:20 Th

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

Too  Interconnected  

Page 23: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Reference  Root  

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Sa unloadLocCode = LGBunloadTime = 13:20 Th

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

Page 24: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Allowed  State  IFnerary  HKG-­‐SEA  

•  HKG-­‐LGB  on  XYZ  •  LGB-­‐  SEA  on  ABC  

EsFmated  Layover  in  LGB:    13:20  Th  –10:15  Sa  

 Elapsed:  45:55    

Voyage  Schedule  for  XYZ  •  ETD  HKG  08:30  Sa  

•  ETA  SHA  21:00  Sa  

•  ETD  SHA  06:30  Su  

•  ETA  LGB  13:20  Th  3:00  Sa  (next)  

•  …  

Voyage  Schedule  for  ABC  •  ETD  SNG  14:15  Tu  

•  ETA  LGB  22:05  Fr  

•  ETD  LGB  10:15  Sa  (next)  

•  ETA  SEA  07:40  Su  (next)  

 

Page 25: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

A  While  Later  IFnerary  HKG-­‐SEA  

•  HKG-­‐LGB  on  XYZ  •  LGB-­‐  SEA  on  ABC  

EsFmated  Layover  in  LGB:    3:00  Sa  –10:15  Sa  

 Elapsed:  45:55    7:15  

Voyage  Schedule  for  XYZ  •  ETD  HKG  08:30  Sa  

•  ETA  SHA  21:00  Sa  

•  ETD  SHA  06:30  Su  

•  ETA  LGB  13:20  Th  3:00  Sa  (next)  

•  …  

Voyage  Schedule  for  ABC  •  ETD  SNG  14:15  Tu  

•  ETA  LGB  22:05  Fr  

•  ETD  LGB  10:15  Sa  (next)  

•  ETA  SEA  07:40  Su  (next)  

 

Page 26: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

A  few  seconds  (or  hours)  later  

IFnerary  HKG-­‐SEA  

•  HKG-­‐LGB  on  XYZ  •  LGB-­‐  SEA  on  ABC  

•  EsFmated  Layover  in  LGB:  13:20  Th    03:00  Sa  –10:15  Sa  

•  Elapsed:  45:55  07:15  

Voyage  Schedule  for  XYZ  

•  ETD  HKG    08:30  Mo  

•  ETA  LGB  13:20  Th  03:00  Sa  •  …  Voyage  Schedule  for  ABC  

•  ETD  SNG  14:15  Tu  •  ETA  LGB    22:05  Fr  •  ETD  LGB    10:15  Sa  •  ETA  SEA      07:40  Su    

Page 27: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Sa unloadLocCode = LGBunloadTime = 13:20 Th

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

vesselVoyageId = XYZ

Schedule ChangedDomain  Event  

Page 28: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Bounded  Context  

•  Aggregates  are  part  of  the  model  

•  Data  inconsistency  within  a  context  with  model  consistency  

•  Strict  asserFons  about  what’s  consistent  when  

Page 29: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

startLocationCode= HKGendLocCode = SEAavailableTime = 7:40 Sulayover = 45:55

1st

cargoId = AXB234QOrigin = HKGDestination = SEAArrival Deadline = Tue nextWeight = ...

Schedule

loadLocationCode = LGBloadTime = 10:15 Sa unloadLocCode = SEAunloadTime = 7:40 Su

2nd

loadLocationCode = HKGloadTime = 8:30 Sa unloadLocCode = LGBunloadTime = 13:20 Th

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 Th

VesselLeg

departureLocCode = LGBEDT = 10:15 Sa unloadLocCode = SEAETA = 7:40 Su

vesselVoyageId = XYZ

Vessel Voyage

departureLocCode = HKGEDT = 8:30 Mo unloadLocCode = LGBETA = 13:20 ThdepartureLocCode = SHA

EDT = 6:30 Su unloadLocCode = LGBETA = 13:20 Th

departureLocCode = HKGEDT = 8:30 Sa unloadLocCode = SHAETA = 21:00 Sa

VesselLeg

VesselLeg

VesselLeg

Leg

Leg

Itinerary

Cargo

Schedule

vesselVoyageId = ABC

Vessel Voyage

vesselVoyageId = XYZ

Schedule Changed

vesselVoyageId = ABC

Schedule Changed

Anticorruption Layer

Fewer  AssumpFons  

Page 30: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

Main  Points  

•  Aggregates  model  domain  knowledge  about  logic  coupling  and  update  pa>erns.  

•  Domain  Events  represent  what  happened  in  domain,  giving  meaning  to  state  change.  

•  Context  boundaries  mark  where  a  model  allows  strong  asserFons.  

Page 31: Acknowledging,CAP,atthe,Root 33,in,the,Domain,Model, - QCon

•  Eric  Evans  •  Domainlanguage.com  

•  Twi>er:  ericevans0    #dddesign