Slide 1

Slide 1 text

BOUNDED CONTEXTS + EVENTS => MICROSERVICES PRACTICAL DOMAIN-DRIVEN DESIGN @indu_alagarsamy

Slide 2

Slide 2 text

@indu_alagarsamy

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Product Name Description Product Images List Price Shipping Options Stock Availability Customer Reviews Dimensions @indu_alagarsamy

Slide 5

Slide 5 text

Sales Inventory Shipping WHAT IS A PRODUCT ? It’s a thing that has a description, images, price It’s a thing that is either available or not It’s a thing that has weight and dimensions that needs to be packaged @indu_alagarsamy

Slide 6

Slide 6 text

UNIFIED MODELS ARE HARD @indu_alagarsamy

Slide 7

Slide 7 text

BOUNDED CONTEXT IS A SAFE SPACE Source: https://www.airbnb.com/rooms/15448688?guests=1&adults=1

Slide 8

Slide 8 text

CONTEXTS PROVIDE CLARITY @indu_alagarsamy

Slide 9

Slide 9 text

FINDING THE BOUNDARY @indu_alagarsamy

Slide 10

Slide 10 text

Product Name Description Product Images List Price Shipping Options Stock Availability Customer Reviews Dimensions @indu_alagarsamy Do you need transactional consistency for updating the description and the stock availability?

Slide 11

Slide 11 text

Sales Inventory Shipping Description Product Images List Price Stock Availability Shipping Options SPLIT THE MODEL ACCORDING TO TEAMS OR DEPARTMENTS Dimensions Product Product Product Dimensions @indu_alagarsamy

Slide 12

Slide 12 text

SPLIT THE MODEL ACCORDING TO BUSINESS PROCESSES @indu_alagarsamy Get $70 off instantly: Pay $0.00 upon approval for the Amazon Prime Rewards Visa card Get it tomorrow. Order within 1hr 53 mins and choose One-Day Shipping at checkout

Slide 13

Slide 13 text

More info on finding boundaries: http://go.particular.net/ exploreddd19

Slide 14

Slide 14 text

HOW DO BOUNDED CONTEXTS COMMUNICATE? THE AIRLINE EXAMPLE @indu_alagarsamy

Slide 15

Slide 15 text

COMMANDS & EVENTS @indu_alagarsamy Something of importance happened Do something Domain Event Command

Slide 16

Slide 16 text

WHEN an aircraft type is changed: Passenger gets notified with a new booking proposal Passenger can cancel flight Passenger can accept proposed booking @indu_alagarsamy

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Mycenae, Greece A Business Process can be triggered by an event from a different bounded context AircraftTypeHasChanged FLIGHT PLANNING BOUNDED CONTEXT BOOKING BOUNDED CONTEXT WHEN an aircraft type is changed @indu_alagarsamy

Slide 19

Slide 19 text

Mycenae, Greece Multiple messages can take part in a business process AircraftTypeHasChanged NotifyCustomer RebookFlight BookingWasCancelled @indu_alagarsamy FLIGHT PLANNING BOUNDED CONTEXT BOOKING BOUNDED CONTEXT

Slide 20

Slide 20 text

Mycenae, Greece Saga Pattern BUSINESS POLICY STATE @indu_alagarsamy

Slide 21

Slide 21 text

@indu_alagarsamy EVENTSTORMING Source: dddeurope.com

Slide 22

Slide 22 text

Flight planning context Booking context MODELING USING EVENT STORMING @indu_alagarsamy Aircraft type has changed Booked Flight Was Changed Booking was confirmed Booking was cancelled

Slide 23

Slide 23 text

EVENT STORMING @indu_alagarsamy Aircraft type was changed Rebook Flight Booked Flight Was Changed Notify customer about flight change Request time out (5 days) Booking was confirmed Booking was cancelled

Slide 24

Slide 24 text

Booking Context AircraftType Was Changed class AircraftTypeWasChangedHandler : IHandleMessages { Handle(AircraftTypeWasChanged msg, MessageHandlerContext context) { // Find all the relevant booking references context.Send(new RebookFlight{…}); } }

Slide 25

Slide 25 text

Booking Context RebookFlight class RebookFlightHandler : IHandleMessages { Handle(RebookFlight msg, MessageHandlerContext context) { // Find a good proposed route context.Publish(new BookedFlightWasChanged{…}); } }

Slide 26

Slide 26 text

Booking Context BookedFlight WasChanged Booking WasCancelled Cancellation GracePeriodElapsed public class BookingChangePolicy : Saga, IAmStartedByMessages, IAmStartedByMessages, IHandleTimeouts @indu_alagarsamy

Slide 27

Slide 27 text

@indu_alagarsamy NAMING THINGS ARE HARD

Slide 28

Slide 28 text

@indu_alagarsamy Aircraft type was changed Rebook Flight Booked Flight Was Changed Notify customer about flight change Booking was confirmed Booking was cancelled Passenger gets notified with a new booking proposal Propose Rebooking Rebooking Was Proposed Notify customer about proposed rebooking Request time out (5 days) Rebooking was accepted

Slide 29

Slide 29 text

class AircraftTypeWasChangedHandler : IHandleMessages class ProposeNewRebookingWhenAircraftTypeWasChanged : IHandleMessages HEALTHY OBSESSION WITH LANGUAGE @indu_alagarsamy

Slide 30

Slide 30 text

public class BookingChangePolicy : Saga, IAmStartedByMessages, IAmStartedByMessages, IHandleTimeouts class GracePeriodForAcceptingRebookings : Saga, IAmStartedByMessages, IAmStartedByMessages, IHandleTimeouts HEALTHY OBSESSION WITH LANGUAGE @indu_alagarsamy

Slide 31

Slide 31 text

public class AircraftTypeWasChanged { public OldAircraftId {get; set;} } MAKE MESSAGES IMMUTABLE @indu_alagarsamy Get rid of the public setters Set the properties at construction time

Slide 32

Slide 32 text

WHEN Aircraft type is changed: Passenger gets notified with a new booking proposal Passenger can cancel flight Passenger can accept proposed booking @indu_alagarsamy Only applies to passengers who are flying business class or first or Platinum loyalty

Slide 33

Slide 33 text

LoyaltyStatus ProcessLoyaltyInfo() @indu_alagarsamy Temporal Coupling AircraftTypeHasChanged RebookingWasProposed PROPOSE REBOOKING Booking Context GetLoyaltyStatus(customerId) PROMOTE CUSTOMER Loyalty Context

Slide 34

Slide 34 text

BOOKING LOYALTY CustomerWasPromotedToGold CustomerWasPromotedToPlatinum Customer PromotionInfo FLIGHT PLANNING AircraftTypeHasChanged ProposeRebooking @indu_alagarsamy Make Autonomous Decisions

Slide 35

Slide 35 text

Source: http://www.gameslayer.org/articles/My_Tron_Style_Working_Environment-4/work-environment-02.jpg DEPLOYMENTS

Slide 36

Slide 36 text

ProposeRebooking v1.1 ProposeRebooking v1.0 AircraftTypeHasChanged SIDE BY SIDE @indu_alagarsamy

Slide 37

Slide 37 text

ProposeRebooking v1.1 ProposeRebooking v1.0 AircraftTypeHasChanged ROLLBACKS Error Queue @indu_alagarsamy

Slide 38

Slide 38 text

@indu_alagarsamy Talk to domain experts. Event storm with them. Models are not perfect Evolve and refactor with an obsession for domain language Strive for Autonomy. Use events to communicate between bounded contexts

Slide 39

Slide 39 text

THANK YOU @indu_alagarsamy https://indu.dev