Polling vs. PubSub

Lavesh Dalmiya
1 min readMay 19, 2022

Let’s assume that its time that your maid arrives and helps you with your household chores. You have to open the door when she arrives.

But how do you know that she has arrived at the door?

One way is to go check your door every few minutes till she is finally there. Other way is you fit a door bell which you can ask her to ring when she arrives.

Interestingly systems can also get information from one another in the same way!

The first way (checking your door every few minutes) is called Polling where you keep on sending a request to other system asking it to share what is the update.

The 2nd way (fitting a doorbell) is called Publisher-Subscriber model where the other system sends data as soon as an event is triggered (publisher) and you just need to subscribe to other system to receive that data by providing information about where to send it (subscriber).

Polling will be consuming more resources as you may have multiple events for which you might keep on following up with the other system every few seconds or minutes depending on how much realtime that information is needed. (Imagine if you are Amazon and you keep on following up every second with banks for success status of every single payment that was initiated on your app before confirming the order)

Publisher-Subscriber model saves that effort because as soon as the event happens, you automatically know.

--

--

Lavesh Dalmiya

I am a Product Manager at LohonoStays. I transitioned to this role after spending 4.5 years in Analytics to ship products & increase revenue based on data!