0
0
Microservicessystem_design~25 mins

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

Choose your learning style9 modes available
Design: Event Types in Microservices Architecture
Design focuses on event types and their handling in a microservices environment. Out of scope are detailed UI notification designs and specific business logic implementations.
Functional Requirements
FR1: Support domain events to capture business state changes within a service
FR2: Support integration events to communicate between different microservices asynchronously
FR3: Support notification events to inform users or external systems about important occurrences
FR4: Ensure reliable delivery of events with minimal latency
FR5: Allow event consumers to subscribe selectively to event types
FR6: Support event versioning and schema evolution
FR7: Handle failures and retries for event processing
Non-Functional Requirements
NFR1: System must handle up to 10,000 events per second
NFR2: Event delivery latency p99 should be under 200ms
NFR3: Availability target of 99.9% uptime
NFR4: Events must be durable and not lost in case of failures
NFR5: Support eventual consistency between microservices
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
❓ Question 6
Key Components
Event producers within microservices
Message broker or event bus (e.g., Kafka, RabbitMQ)
Event consumers or subscribers
Event schema registry for versioning
Dead letter queues for failed events
Notification service for user or external alerts
Design Patterns
Event-driven architecture
Publish-subscribe pattern
Event sourcing for domain events
CQRS (Command Query Responsibility Segregation)
Retry and dead letter queue patterns
Schema evolution and backward compatibility
Reference Architecture
 +----------------+       +----------------+       +----------------+
 |  Microservice  |       |  Message Broker |       |  Microservice  |
 |  (Event Prod)  | ----> |  (Event Bus)   | ----> |  (Event Cons)  |
 +----------------+       +----------------+       +----------------+
         |                        |                        |
         | Domain Events          | Integration Events     | Notification Events
         |                        |                        |
         v                        v                        v
 +----------------+       +----------------+       +----------------+
 | Domain Event   |       | Integration    |       | Notification   |
 | Handler       |       | Event Handler  |       | Service       |
 +----------------+       +----------------+       +----------------+
Components
Microservice Event Producer
Any microservice framework (e.g., Spring Boot, Node.js)
Generates domain events when business state changes occur
Message Broker / Event Bus
Apache Kafka or RabbitMQ
Routes integration and notification events asynchronously between services
Microservice Event Consumer
Microservice framework
Consumes integration events to update local state or trigger actions
Notification Service
Dedicated service with email/SMS/push capabilities
Sends notifications to users or external systems based on notification events
Event Schema Registry
Confluent Schema Registry or custom solution
Manages event schemas and supports versioning for compatibility
Dead Letter Queue
Message broker feature
Stores events that failed processing for later inspection or retry
Request Flow
1. 1. A microservice performs a business operation and emits a domain event internally.
2. 2. The domain event is published to the message broker as an integration event if other services need to know.
3. 3. Other microservices subscribe to integration events from the broker and update their own state accordingly.
4. 4. When a notification event is generated (either by domain or integration event handlers), it is sent to the notification service.
5. 5. The notification service delivers messages to users or external systems via email, SMS, or push notifications.
6. 6. Failed event deliveries are routed to the dead letter queue for manual or automated retries.
7. 7. Event schemas are validated and managed via the schema registry to ensure compatibility.
Database Schema
Entities: - Event: id (PK), type (domain/integration/notification), payload (JSON), timestamp, version - Subscription: id (PK), microservice_name, event_type, endpoint - Notification: id (PK), event_id (FK), recipient, status, sent_timestamp Relationships: - One Event can trigger multiple Notifications - Subscriptions link microservices to event types they consume
Scaling Discussion
Bottlenecks
Message broker throughput limits when event volume grows beyond 10K events/sec
Event consumers overwhelmed by high event processing rates
Notification service latency when sending large volumes of messages
Schema registry becoming a single point of failure
Dead letter queue growing large with many failed events
Solutions
Partition topics in message broker and scale brokers horizontally
Scale event consumers horizontally with load balancing and backpressure handling
Use bulk sending and rate limiting in notification service; integrate with third-party providers
Deploy schema registry in a highly available cluster with caching
Implement automated retries and monitoring for dead letter queue; archive old events
Interview Tips
Time: Spend 10 minutes clarifying requirements and constraints, 20 minutes designing the architecture and data flow, 10 minutes discussing scaling and trade-offs, and 5 minutes summarizing.
Explain the differences and purposes of domain, integration, and notification events clearly
Show understanding of asynchronous communication and event-driven design
Discuss how to ensure reliability and ordering in event delivery
Mention schema management and versioning importance
Address scaling challenges and practical solutions
Highlight how notifications integrate with event processing