Bird
Raised Fist0
Microservicessystem_design~7 mins

Event types (domain, integration, notification) in Microservices - System Design Guide

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Problem Statement
When microservices communicate, mixing different kinds of events without clear separation causes confusion, tight coupling, and harder maintenance. Without distinguishing event types, teams struggle to know which events trigger internal logic, which coordinate between services, and which inform users or external systems.
Solution
Classify events into domain, integration, and notification types to clarify their purpose and scope. Domain events represent important business state changes within a service. Integration events coordinate actions across services by sharing state changes. Notification events inform users or external systems about events without affecting business logic. This separation improves decoupling and clarity.
Architecture
┌─────────────┐       ┌───────────────┐       ┌───────────────┐
│ Domain      │       │ Integration   │       │ Notification  │
│ Events      │──────▶│ Events        │──────▶│ Events        │
│ (Internal)  │       │ (Cross-service│       │ (User/External│
└─────────────┘       │ communication)│       │ communication)│
                      └───────────────┘       └───────────────┘

This diagram shows the flow and separation of event types: domain events occur inside a service, integration events share state changes between services, and notification events inform users or external systems.

Trade-offs
✓ Pros
Improves clarity by defining event responsibilities clearly.
Reduces tight coupling between microservices by separating internal and cross-service events.
Facilitates easier maintenance and evolution of services.
Enables targeted handling and scaling strategies per event type.
✗ Cons
Adds complexity in event design and requires discipline to maintain separation.
May increase the number of events and infrastructure overhead.
Requires clear documentation and team alignment to avoid misuse.
Use when building microservices with asynchronous communication and multiple teams managing different services, especially when business logic and integration concerns must be separated at scale (100+ services or high event volume).
Avoid when building simple or monolithic applications with minimal asynchronous communication or when event volume is very low (<100 events per minute), as the overhead outweighs benefits.
Real World Examples
Uber
Uber uses domain events to track ride status changes internally, integration events to synchronize data between services like payments and notifications, and notification events to inform users about ride updates.
Netflix
Netflix separates domain events for user activity within services, integration events to coordinate between microservices like recommendations and billing, and notification events to send alerts or emails to users.
Amazon
Amazon uses domain events to represent order state changes, integration events to update inventory and shipping services, and notification events to send order confirmations and delivery updates to customers.
Code Example
The before code mixes all event types in one method using string checks, causing confusion and tight coupling. The after code defines separate classes for each event type and processes them with dedicated handlers, improving clarity and separation of concerns.
Microservices
### Before: Mixed event handling without clear types
class EventProcessor:
    def process(self, event):
        if event['type'] == 'order_created':
            self.handle_order_created(event)
        elif event['type'] == 'payment_received':
            self.handle_payment(event)
        elif event['type'] == 'send_email':
            self.handle_notification(event)

### After: Clear event type separation
class DomainEvent:
    def __init__(self, data):
        self.data = data

class IntegrationEvent:
    def __init__(self, data):
        self.data = data

class NotificationEvent:
    def __init__(self, data):
        self.data = data

class EventProcessor:
    def process(self, event):
        if isinstance(event, DomainEvent):
            self.handle_domain_event(event)
        elif isinstance(event, IntegrationEvent):
            self.handle_integration_event(event)
        elif isinstance(event, NotificationEvent):
            self.handle_notification_event(event)

    def handle_domain_event(self, event):
        # business logic
        pass

    def handle_integration_event(self, event):
        # cross-service coordination
        pass

    def handle_notification_event(self, event):
        # user or external notifications
        pass
OutputSuccess
Alternatives
Event Sourcing
Stores all changes as a sequence of events representing state changes, focusing on persistence rather than event type separation.
Use when: Choose when you need full audit trails and the ability to reconstruct state from events.
Command Query Responsibility Segregation (CQRS)
Separates read and write models, often using events to update read models, but focuses on query optimization rather than event type classification.
Use when: Choose when read and write workloads differ significantly and need separate optimization.
Summary
Separating events into domain, integration, and notification types clarifies their roles and reduces coupling in microservices.
Domain events represent internal business changes, integration events coordinate between services, and notification events inform users or external systems.
This separation improves maintainability, scalability, and team collaboration in complex distributed systems.

Practice

(1/5)
1. Which type of event in microservices captures important business actions inside a single service?
easy
A. Domain event
B. Integration event
C. Notification event
D. System event

Solution

  1. Step 1: Understand event types in microservices

    Domain events represent significant business actions occurring within a single service boundary.
  2. Step 2: Differentiate from other event types

    Integration events share data between services, and notification events alert users or external systems, so they are not internal business actions.
  3. Final Answer:

    Domain event -> Option A
  4. Quick Check:

    Business action inside service = Domain event [OK]
Hint: Domain events are about internal business actions [OK]
Common Mistakes:
  • Confusing integration events with domain events
  • Thinking notification events capture business logic
  • Assuming system event is a standard event type
2. Which of the following is the correct way to describe an integration event in microservices?
easy
A. An event that triggers UI updates within the same service
B. An event that shares information between different services
C. An event that sends alerts to users only
D. An event that logs errors internally

Solution

  1. Step 1: Define integration events

    Integration events are designed to share information or changes between different microservices to keep them in sync.
  2. Step 2: Eliminate incorrect options

    UI updates are usually local, alerts to users are notification events, and error logs are internal diagnostics, not integration events.
  3. Final Answer:

    An event that shares information between different services -> Option B
  4. Quick Check:

    Sharing info between services = Integration event [OK]
Hint: Integration events connect multiple services [OK]
Common Mistakes:
  • Mixing notification events with integration events
  • Thinking integration events only affect one service
  • Confusing error logs with integration events
3. Consider this code snippet in a microservice:
publishEvent({ type: 'UserRegistered', payload: { userId: 123 } });
What type of event is this most likely representing?
medium
A. Notification event
B. System event
C. Integration event
D. Domain event

Solution

  1. Step 1: Analyze the event name and context

    The event 'UserRegistered' indicates a business action inside the service, such as a user signing up.
  2. Step 2: Match event type to definition

    Since it captures a business action inside the service, it is a domain event, not a notification or integration event.
  3. Final Answer:

    Domain event -> Option D
  4. Quick Check:

    Business action event = Domain event [OK]
Hint: Event names with business actions are domain events [OK]
Common Mistakes:
  • Assuming all events are integration events
  • Confusing notification events with domain events
  • Ignoring event naming conventions
4. A microservice is sending an event to notify users about a password change. The event is mistakenly labeled as an integration event. What is the main issue here?
medium
A. Notification events should not be sent to users
B. Password change is a domain event, not a notification
C. Notification events should not be labeled as integration events
D. Integration events cannot carry user-related data

Solution

  1. Step 1: Identify the event purpose

    The event is meant to notify users, which fits the notification event type.
  2. Step 2: Understand event labeling importance

    Labeling a notification event as an integration event causes confusion and wrong handling in the system.
  3. Final Answer:

    Notification events should not be labeled as integration events -> Option C
  4. Quick Check:

    Correct event labeling avoids confusion [OK]
Hint: Match event label to its purpose carefully [OK]
Common Mistakes:
  • Mixing notification and integration event roles
  • Assuming integration events can't have user data
  • Thinking notification events are internal only
5. You are designing a microservices system where a user registration triggers multiple actions: updating internal user stats, notifying other services, and sending a welcome email. Which event types should you use for these actions respectively?
hard
A. Domain event, integration event, notification event
B. Integration event, domain event, notification event
C. Notification event, domain event, integration event
D. Domain event, notification event, integration event

Solution

  1. Step 1: Map actions to event types

    Updating internal user stats is a business action inside the service, so it is a domain event.
  2. Step 2: Identify cross-service communication

    Notifying other services requires sharing information between services, so it is an integration event.
  3. Step 3: Recognize user alerts

    Sending a welcome email is a message to the user, which fits notification events.
  4. Final Answer:

    Domain event, integration event, notification event -> Option A
  5. Quick Check:

    Internal action, cross-service, user alert = Domain, Integration, Notification [OK]
Hint: Match event type to action scope: internal, cross-service, user [OK]
Common Mistakes:
  • Swapping integration and notification events
  • Using domain events for cross-service communication
  • Confusing notification with domain events