Short Poll, Long Poll vs Callback

Short Poll, Long Poll vs Callback

Imagine you're on a long road trip with your family. It's a bright, sunny day, and the car is packed with snacks, games, and eager anticipation. But there's one thing that can make the journey feel a bit longer: the constant chorus of "Are we there yet?" from the kids in the backseat. This is a perfect analogy for what we call "short polling" in software engineering.

Short Poll

Just like the kids repeatedly asking "Are we there yet?" every few minutes, short polling involves frequently checking the server to see if there's any new information or update. This constant checking can keep both the kids (your application) and the parents (the server) quite busy. It might not be the most efficient way to get updates, but it keeps everyone engaged and informed—though it can be a bit exhausting.

Short Polling Strategy

Long Poll

Now, imagine if the kids asked "Are we there yet?" but instead of asking every few minutes, they decide to ask every 2 hours. The parents know they have a bit of a break between questions, and the kids are reassured they will get an update periodically. This is similar to "long polling." Instead of constantly checking, the kids (your application) wait for a longer period before asking again, making it less frequent but still ensuring they eventually get the update. This reduces the back-and-forth chatter, conserving energy and patience for both the kids and the parents.

Long Polling Strategy

Callback

Finally, let's say the kids have a different approach. They decide to enjoy their games and snacks without worrying about the destination at all. The parents promise to call them when they are about to arrive, so the kids can fully enjoy their journey. This is akin to using "callbacks." The server promises to notify the application when new information is available. The kids (application) can relax and do other things, knowing they'll be informed at the right time.

Callback Strategy



So, there you have it: a family road trip analogy to explain short polling, long polling, and callbacks in a way that's easy to understand and relate to. Whether it's constant questioning, periodic checking, or trusting to be notified, each method has its own way of managing the journey towards getting the information you need.

Weyman Cohen

Transforming the economics of software development ????

5 个月

Very helpful thanks Asim!

Junaid Khokhar

Technology Leader | Architect | Cloud | Enterprise

5 个月

why its not shareable ?

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了