S2_Slides
S2_Slides
Memi Lavi
www.memilavi.com
Events
• Polyglot
Service
Service
Service DB
Service
DB
Microservices Communication
microservices architecture
• Services either:
• Send command
Orders Payment
service service
Process payment
Processing completed
successfully
failure indicator
Query
Customers Orders
service service
How many orders for customer X?
17
• Main characteristics:
Command Query
• Do something • Retrieve data
• Usually synchronous • Almost always synchronous
• Sometimes returns a response • Always returns a response
• Calling service needs to know • Calling service needs to know
who handles the command who handles the query
Problems with Command and Query
Performance
Coupling
Scalability
Performance
complete
• If the called service changes – the calling service has to change too
Customers
service
New customer was added
• Main characteristics:
Event
• Something happened
• Asynchronous
• Never returns a response
• Calling service has no idea who
handles the event
Contents of Event
Complete Pointer
• Contains all the relevant data • Contains pointer to the complete data of the entity
• Usually entity data • Complete data usually stored in a database
• No additional data is required for • Event handler needs to access the database to
the event processing retrieve complete data
• Example: • Example:
event_type: CustomerCreated event_type: CustomerCreated
customer_id: 17 customer_id: 17
first_name: David
last_name: Jones
join_date: 2022-03-15 Pointer
Flow of Complete Event Handling
Customers
service
New customer was added
Event handler
Customers
service
New customer was added
Event handler
Database
Complete vs Pointer
Complete Pointer
• The better approach • Use when:
• Makes the event completely • Data is large
autonomous • Need to ensure data is up-to-date
• Can get out of the system • Assuming database is a single-source-of-
boundaries truth