Chapter 8. Publish/Subscribe

Why It Matters

“Are we there yet?” asks a small boy in the back seat of a car. “No, not yet,” answers the adult. Some minutes later, the child asks, “Are we there now?” This short but frequently repeated exchange is a real-world example of a polling system: the child won’t know when the vehicle is approaching its destination, so he frequently checks with the adult driving the car. That is, the child is polling for information.

Usually it doesn’t take long for the adult to reply, “I’ll tell you when we’re there.” This is an example of a publish/subscribe system: here, the boy has expressed an interest in (subscribed to) a piece of information, and the adult will tell the child once the information changes (i.e., once updated information is published). Publish/subscribe systems avoid the need to frequently poll for updates. In this example, this helps the adult traveling with a young boy to stay sane; on the Internet, it serves the dual purpose of saving bandwidth and server resources (there are no more “has it changed?”, “no, it hasn’t” exchanges), and ensuring that the subscriber receives updates as quickly as the network can deliver them, rather than only the next time the subscriber polls the source.

As in real life, polling over the Internet is painful, especially for the server. Imagine that you have 100 “followers” on a microblogging service, each of whom polls the server every 10 minutes on the off chance that you have said something interesting (indeed, ...

Get XMPP: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.