What is the Publisher Subscriber Model?
About this video
### Summary of Event-Driven Services and Publisher-Subscriber Model: 1. **Microservice Architecture Overview**: - The system consists of multiple services (S0, S1, S2, S3, S4). - A client sends a request to S1, which processes it and sends messages to S0 and S2. - S2 further sends messages to S3 and S4 after processing. 2. **Request-Response Architecture Drawbacks**: - **Asynchronous Requests**: Even with asynchronous requests, services like S2 may wait for responses from S3 and S4. - **Failure Handling**: If S4 fails, it causes a timeout, leading to stale data and multiple changes in the database by S1 and S2. - **Complexity**: Multiple points of failure make the system harder to manage. 3. **Publisher-Subscriber Model Advantages**: - **Decoupling**: Removes dependencies between services. S1 publishes messages to a message broker (e.g., Kafka, RabbitMQ) instead of directly communicating with S0 and S2. - **Message Persistence**: Ensures messages are not lost and retries occur if a service is down. - **Scalability**: Easily add new services (e.g., S6) without modifying existing services. - **Developer Simplicity**: Services send generic messages, reducing the need for specific interface interactions. - **Transaction Guarantees**: Provides at-least-once delivery, ensuring messages eventually reach their destinations. 4. **Publisher-Subscriber Model Disadvantages**: - **Consistency Issues**: Not suitable for financial systems requiring strict consistency. Example: Inconsistent fund transfers due to delayed or failed messages. - **Idempotency Challenges**: Messages can cause unintended repeated actions (e.g., debiting 50 rupees multiple times) unless handled explicitly by developers. - **No Atomicity**: Transactions across services lack atomicity, leading to partial successes or failures. 5. **Use Cases**: - **Not Suitable for Finance**: Due to lack of transactional guarantees and consistency. - **Ideal for Gaming/Analytics**: Works well for systems like gaming services or platforms like Twitter, where events (e.g., tweets) are published and consumed by many subscribers. 6. **Conclusion**: - The publisher-subscriber model is foundational for event-driven services, enabling scalable and decoupled architectures. - While powerful, it has limitations in mission-critical systems requiring strong consistency and atomicity. - Awareness of its advantages and disadvantages is crucial for effective implementation. 7. **Next Steps**: - Further discussion on consistency and idempotency solutions will be covered in subsequent sessions. - Event-driven services will be explored in more detail in the next video.
Course: System Design Playlist
**Course Description: System Design Playlist** This comprehensive course, titled "System Design Playlist," is designed to provide students with a deep understanding of system design principles and practices through real-world analogies and technical explanations. The course begins by using the analogy of running a pizza restaurant to illustrate fundamental concepts in system design, such as optimizing processes, scaling resources, and ensuring resilience. Students will learn about vertical scaling—enhancing the capabilities of existing resources—and horizontal scaling—adding more resources to distribute the workload. Through this engaging example, participants will grasp essential strategies for improving throughput, eliminating single points of failure, and implementing backup systems to maintain operational continuity. As the course progresses, students will delve into advanced topics like microservice architecture, where responsibilities within a system are clearly defined and divided among specialized teams or services. This approach allows for efficient scaling and management of different components based on their specific needs. Additionally, the course covers distributed systems, highlighting the importance of fault tolerance and quick response times by strategically placing servers closer to users. Concepts such as load balancing, which intelligently routes requests to optimize performance, and decoupling systems to enhance flexibility and adaptability, are thoroughly explored. Participants will also learn about logging and metrics to monitor system health and make informed decisions. The course wraps up by contrasting high-level system design, which focuses on overarching architectural decisions, with low-level system design, which deals with the actual coding and implementation details. By mapping business scenarios to technical solutions, students will gain insights into designing scalable, reliable, and extensible systems. Whether you're new to system design or looking to deepen your expertise, this course equips you with the knowledge and tools needed to tackle complex design challenges and develop robust systems capable of meeting diverse user demands.
View Full Course