Publish-Subscribe (Pub/Sub)
A communication pattern that allows publishers to send messages to a channel while subscribers are notified about those messages.
Classification
- ComplexityMedium
- Impact areaTechnical
- Decision typeTechnical
- Organizational maturityAdvanced
Technical context
Principles & goals
Use cases & scenarios
Compromises
- Loss of Messages on Failures
- Security Risks with Open Channels
- Need for Monitoring
- Use simple message formats.
- Implement error handling for message loss.
- Use monitoring tools.
I/O & resources
- Data Streams
- Event Reports
- User Requests
- Notifications
- Data Analyses
- Feedback Reports
Description
The Publish-Subscribe pattern (Pub/Sub) allows for the decoupling of message senders and receivers. It is used in distributed systems where asynchronous communication mechanisms are required. Pub/Sub enhances scalability and flexibility in system architecture.
✔Benefits
- Increased Scalability
- Improved Flexibility
- Decoupling of Senders and Receivers
✖Limitations
- Complexity of Message Management
- Potential Delays in Message Delivery
- Requirements for System Configuration
Trade-offs
Metrics
- Message Processing Time
The time taken to process a message.
- System Availability
The availability of the system during operation.
- Scalability Test
A test to evaluate scalability capabilities.
Examples & implementations
Real-Time Delivery Tracking
An example of how the Pub/Sub pattern is used in a delivery tracking app.
Comment System for Blogs
Application of the Pub/Sub pattern to send notifications for new comments.
Real-Time Data Analysis in IoT
Using the Pub/Sub pattern in IoT applications for analyzing sensor data.
Implementation steps
Define the message formats.
Implement the publishers and subscribers.
Test the message delivery.
⚠️ Technical debt & bottlenecks
Technical debt
- Outdated libraries for message transmission.
- Lack of modularity in components.
- Undocumented system dependencies.
Known bottlenecks
Misuse examples
- Using complex data structures in messages.
- Ignoring security requirements.
- Inadequate testing before production deployment.
Typical traps
- Excessive complexity in implementation.
- Insufficient error logging.
- Managing legacy systems that are not compatible.
Required skills
Architectural drivers
Constraints
- • Dependency on Network Availability
- • Need for Synchronization
- • Compliance with Data Protection Regulations