Pub/Sub is a computer to computer messaging system. The Pub/Sub itself is really just an inbox and an outbox for data. It works a lot like your email inbox in many ways.
Inbound messages come from Publishers and those publishers send their messages to a Pub/Sub Topic. A topic can receive messages from one or many publishers, depending on your needs. The topic returns an acknowledgement to the publisher and their part of the transaction is complete. The publisher can do this as often as it wants. It can publish any data, whether it’s a simple “Hello world” or an encrypted chunk of binary data.
The other half of pub/sub is the Subscription. There can be one or many subscriptions for each topic. Each subscription has your choice of two different delivery methods. It can either Push messages to a URL you’ve configured ahead of time or it can wait for the Subscriber to Pull the messages on their own. Push is kinda like how text messages just appear on your phone without you taking action. Pull is kinda like how you have to go to your physical mailbox to pick up any messages that arrived there.
Here’s what those relationships look like in action:
When you put all these pieces together, what you end up with is a powerful tool that can be used in many applications. It can act as a bridge between two services that couldn’t otherwise talk to each other directly, perhaps because they’re in two separate private networks.
Another common application for Pub/Sub is like a shared messaging bus. Twitter is a decent example of a human messaging bus. There are many, many users all sending messages to Twitter. In this case, the users are publishers and Twitter is the pub/sub service. There are also lots of other twitter users who consume these tweets, but they generally don’t care about most of the messages and just let them fly by, only stopping for the most interesting ones. In this case, the users are the subscribers.