DEV Community

Cover image for Easiest way to understand Pub/Sub System (kid friendly)
Clara Situma
Clara Situma

Posted on

2

Easiest way to understand Pub/Sub System (kid friendly)

Imagine that you are in a library, and you want to borrow a book. You don't want to go to each shelf in the library and search for the book yourself, because that would take a lot of time and you might not even find the book. Instead, you decide to use the pubsub pattern to find the book.

Here's how you might use the pubsub pattern to find a book in the library:

  1. You are the publisher in this situation, because you are the one sending the "find book" message to everyone else. When you want to borrow a book, you go to the librarian and tell them the title of the book you are looking for.

  2. The library assistants are the subscribers in this situation, because they are the ones listening for the "find book" message. When a library assistant hears that someone is looking for a particular book, they go and search for the book on the shelves.

  3. The librarian is the message broker in this situation, because they are the ones who receive the "find book" message from you and send it to the appropriate subscribers. When you tell the librarian the title of the book you are looking for, they pass this message along to the library assistants, who start searching for the book.

This way, you don't have to go and search for the book yourself. You can just tell the librarian the title of the book you want, and the library assistants will do the work for you. This makes it easier to find the book you are looking for and borrow it from the library.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay