0
0
LLDsystem_design~25 mins

Event-driven design in LLD - System Design Exercise

Choose your learning style9 modes available
Design: Event-driven design system
Design focuses on the core event-driven architecture including event producers, event broker, and event consumers. Out of scope are detailed UI design and specific business logic inside consumers.
Functional Requirements
FR1: The system should allow components to communicate by sending and receiving events asynchronously.
FR2: It must support decoupling between event producers and consumers.
FR3: The system should handle high throughput of events, up to 10,000 events per second.
FR4: Events must be processed in near real-time with p99 latency under 200ms.
FR5: Support for event persistence to allow replay and recovery.
FR6: Allow multiple consumers to subscribe to the same event type.
FR7: Ensure reliable delivery of events with at-least-once semantics.
Non-Functional Requirements
NFR1: System availability target is 99.9% uptime (about 8.77 hours downtime per year).
NFR2: The system should scale horizontally to handle increasing event volume.
NFR3: Event ordering is required only per event type but not globally.
NFR4: Use technologies suitable for low-latency asynchronous communication.
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
❓ Question 6
❓ Question 7
Key Components
Event producers (services or modules generating events)
Event broker or message queue (middleware to route events)
Event consumers (services or modules processing events)
Event storage for persistence and replay
Monitoring and alerting components
Design Patterns
Publish-Subscribe pattern
Event Sourcing
Message Queueing
Event Streaming
Dead Letter Queue for failed events
Reference Architecture
 +----------------+       +----------------+       +----------------+
 | Event Producer | ----> | Event Broker   | ----> | Event Consumer |
 +----------------+       +----------------+       +----------------+
          |                        |                        |
          |                        |                        |
          |                        |                        |
          |                        v                        |
          |                +----------------+              |
          |                | Event Storage  | <-------------+
          |                +----------------+              |
          |                        |                        |
          +------------------------+------------------------+
Components
Event Producer
Any service or module generating events
Creates and publishes events to the event broker asynchronously
Event Broker
Apache Kafka / RabbitMQ / AWS SNS+SQS
Receives events from producers, routes them to consumers, and ensures delivery guarantees
Event Consumer
Microservices or modules subscribing to events
Processes events asynchronously and performs business logic
Event Storage
Kafka log storage or a database like Cassandra
Persists events for replay, audit, and recovery
Monitoring & Alerting
Prometheus + Grafana or CloudWatch
Tracks system health, event throughput, and failures
Request Flow
1. 1. Event Producer creates an event and publishes it to the Event Broker.
2. 2. Event Broker receives the event and stores it in Event Storage for durability.
3. 3. Event Broker routes the event asynchronously to all subscribed Event Consumers.
4. 4. Event Consumers receive the event and process it independently.
5. 5. If processing fails, the event is sent to a Dead Letter Queue for later inspection.
6. 6. Monitoring components track event flow and system health continuously.
Database Schema
Entities: - Event: {event_id (PK), event_type, payload, timestamp, status} - Subscription: {subscription_id (PK), consumer_id, event_type} - Consumer: {consumer_id (PK), name, endpoint} Relationships: - One Event can be delivered to many Consumers via Subscriptions (1:N) - Event Storage holds all Events for replay and audit
Scaling Discussion
Bottlenecks
Event Broker throughput limits when event volume grows beyond capacity.
Event Storage size and read/write performance under heavy load.
Consumer processing speed causing backpressure.
Network latency affecting event delivery speed.
Single point of failure in Event Broker or Storage.
Solutions
Scale Event Broker horizontally by partitioning topics and adding brokers.
Use distributed, scalable storage like Kafka logs or Cassandra for event persistence.
Implement consumer scaling with multiple instances and load balancing.
Use efficient serialization and compression to reduce network overhead.
Deploy redundant brokers and storage clusters with failover mechanisms.
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying questions, 20 minutes designing the architecture and data flow, 10 minutes discussing scaling and trade-offs, and 5 minutes summarizing.
Explain how event-driven design decouples components for flexibility and scalability.
Describe the role of the event broker and how it ensures reliable delivery.
Discuss event persistence for replay and fault tolerance.
Highlight how consumers can scale independently and handle failures.
Mention trade-offs like eventual consistency and ordering guarantees.
Show awareness of bottlenecks and practical scaling strategies.