Communication

Publisher–Subscriber

Description

A messaging pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers, but instead categorize published messages into classes without knowledge of which subscribers, if any, there may be.

Where to use

  • Notifications.
  • \n
  • Chat systems.
  • \n
  • News feeds.

Real World Example

A YouTube channel uploads a video (Publish). Millions of subscribers get a notification (Subscribe).

Code Example

# Code Concept for Publisher–Subscriber\n# This pattern is architectural.\n\nclass Service:\n    def execute(self):\n        # Implementation logic\n        pass