15 Nov 2023
Domain events are a crucial concept in Domain-Driven Design (DDD). They represent meaningful occurrences in the domain that have significance and are typically used to communicate changes or state transitions within the system. Here are some examples of domain events in different domains:
-
E-commerce Domain:
OrderPlaced: Triggered when a customer successfully places an order.OrderShipped: Indicates that the ordered items have been shipped.PaymentProcessed: Signifies successful processing of a payment for an order.ProductBackordered: Indicates that a product is not currently in stock and is put on backorder.
-
Human Resources Domain:
EmployeeHired: Fired when a new employee is hired.EmployeeTerminated: Triggered when an employee is terminated.SalaryIncreased: Indicates that an employee's salary has been increased.
-
Healthcare Domain:
PatientAdmitted: Fired when a patient is admitted to a hospital.DiagnosisMade: Indicates that a doctor has made a diagnosis for a patient.PrescriptionFilled: Triggered when a patient's prescription is filled at a pharmacy.
-
Social Media Domain:
FriendRequestSent: Indicates that a user has sent a friend request to another user.PostPublished: Fired when a user publishes a new post.CommentAdded: Triggered when a user adds a comment to a post.
-
Banking Domain:
AccountOpened: Fired when a new bank account is opened.WithdrawalMade: Indicates that a withdrawal transaction has been processed.DepositMade: Triggered when a deposit transaction is made.
-
Travel Booking Domain:
FlightBooked: Indicates that a user has booked a flight.HotelReservationMade: Fired when a hotel reservation is successfully made.TripCancelled: Triggered when a user cancels their entire travel itinerary.
-
Education Domain:
CourseEnrolled: Fired when a student enrolls in a course.AssignmentSubmitted: Indicates that a student has submitted an assignment.GradePublished: Triggered when a teacher publishes grades for a course.
These examples illustrate how domain events capture important business occurrences, helping to maintain consistency between different parts of a system and enabling better communication between various components. In DDD, it's common to use these events to trigger side effects, update projections, or inform other parts of the system about changes in the domain.