Middleware
Pub/Sub Model
Persistent Storage
Software Architecture
Data Management

pub/sub middleware with persistent storage

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Publish/Subscribe (pub/sub) middleware is an architectural pattern used primarily for asynchronous communication among different components of a software system. In pub/sub architecture, messages are published to a topic by a publisher without the knowledge of who will receive them. Subscribers express interest in one or more topics and only receive messages that are of interest, without knowing who published them. This decoupling of publishers and subscribers facilitates scalable and manageable distributed systems.

Technical Overview of Pub/Sub Systems

In a basic pub/sub model, the components can be broken down into:

  • Publisher: Sends messages to the pub/sub system, targeting one or more topics.
  • Subscriber: Receives messages from the pub/sub system based on subscription preferences.
  • Message: The data or information sent from the publisher to the subscriber.
  • Topic: A channel or category through which messages are sent.

Publishers and subscribers interact with the message system, not directly with each other. The pub/sub system manages the delivery of messages from publishers to the appropriate subscribers.

Role of Persistent Storage in Pub/Sub Systems

Persistent storage in pub/sub systems ensures that messages are not lost in the case of a system failure and can be useful for delayed processing or auditing purposes. Adding persistence guarantees that even if the subscriber is not actively connected or able to process messages, it can still retrieve those messages at a later time. Persistence can be achieved through various database systems or file storage systems, depending on the scale, performance needs, and other system requirements.

Implementation Options

  1. Database Storage: Messages are written to a relational or NoSQL database which ensures durability. Technologies like PostgreSQL or MongoDB can be used.
  2. File Systems: Messages are stored in a file system which could be scalable and distributed like HDFS or Amazon S3.
  3. Specialized Messaging Systems: Some messaging systems like Apache Kafka and RabbitMQ support built-in disk storage to ensure message delivery even after system crashes.

Advantages of Using Persistent Pub/Sub Middleware

  • Reliability: Ensures message delivery even if the subscriber is temporarily offline.
  • Durability: Messages are preserved until they are explicitly deleted, which aids in system recovery and audit trails.
  • Scalability: By using distributed storage backends, the system can handle high volumes of data without a significant degradation in performance.

Challenges with Persistent Pub/Sub Middleware

  • Latency: Writing to and reading from a persistent store can introduce latency compared to in-memory pub/sub systems.
  • Complexity: Managing data consistency and replication over a distributed persistent storage layer adds complexity.
  • Cost: Increased resource consumption (storage space, I/O operations) might lead to higher operational costs.

Example Use Case: E-commerce Order Processing System

In an e-commerce application, an order processing system can utilize persistent pub/sub middleware to handle customer orders. Here is a hypothetical process flow:

  1. Order Placement: When a customer places an order, the order details are published to an "orders" topic.
  2. Order Processing: Services that handle inventory management, payment processing, and shipping subscribe to the "orders" topic.
  3. Persistence: All messages are stored in a distributed database ensuring that no information about the orders is lost.

Key Points Summary

FeatureDescriptionBenefit
Asynchronous communicationDecouples the timing between message production and consumption.Enhances scalability and system responsiveness.
ScalabilitySystem can handle growth in the number of messages or subscribers.Suitable for systems with fluctuating load.
DurabilityMessages are stored persistently.Prevents data loss in case of failures.

Conclusions

Persistent storage adds a layer of reliability and fault-tolerance to pub/sub systems that is essential for critical business applications. Despite potential issues such as increased latency and complexity, the benefits of using persistent pub/sub middleware -- particularly in terms of system resilience and data integrity -- make it a valuable component in modern distributed architectures.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.