What is Long Polling and How it Works (The Basics and Fundamentals)

Shalini P
Applozic
Published in
3 min readDec 7, 2021

--

Chat APIs, Audio APIs, and Video APIs can be built in many unique ways- especially with the number of implementation styles and types of backend server technology. However, in your research to evaluate the fundamentals of some of these API technologies, you may come across some terminology that may seem unfamiliar to you.

Long polling is the simplest way of maintaining a persistent connection with a server, especially one that doesn’t use any specific protocol like WebSocket or Server Side Events (SSE). It essentially holds the request until it has a response to send back. If it doesn’t have a response, the connection will simply hang until something gets sent back.

Long polling, more often than not, follows something similar to the following outline.

  1. A request is sent to the server.
  2. The server doesn’t close the connection until it has a message to send.
  3. When a message appears, the server responds to the request with it.
  4. The browser makes a new request immediately.

This video explores the concept of long polling and give you a well-rounded understanding of its benefits, drawbacks, and the different ways it can be implemented.

One of the many applications for long polling include chat-based applications. As messages are only sent every once in a while, it can be rather inefficient to use short polling for such situations where new data is not always guaranteed. Therefore, sending requests when a message is sent is much more effective in minimizing unnecessary responses being sent back and forth.

Also read about its benefits, drawbacks, and implementation styles, short vs long Polling, and how it’s different from real-time APIs?

Another application could possibly be turn-based gaming. A request can be sent when every turn is complete, instead of relying on repeated requests. Similar to chat applications, it would also only need the server to be notified when a turn is complete.

Web applications with low-frequency data can also be developed in a way that concepts of long-polling can be applied to them. They can query the server only when a user wishes to travel to a different tab, as opposed to constantly checking what page the user is on and to see if the user has clicked on a new page yet.

Applozic’s API allows you to seamlessly integrate all of your Chat and Audio applications with the amazing and powerful SDK created by our developers. You would lo longer need to worry about what technology your API servers are going to use, as that has already been handled by our team to minimize latency and improve performance for all of our users.

Applozic’s well written documentation will allow you to implement an in-app chat or in-app audio channels with ease and minimal hassle. If you want to try and implement it for your own, there is a free trial available for all of your testing purposes where you can sign up today. The link is given below.

Android documentation:

https://docs.applozic.com/docs/androi... https://github.com/AppLozic/Applozic-.

--

--

Shalini P
Applozic

7+ years in B2B SaaS as a Content Creator & Strategist | Sharing everything I have learnt about Apps, Products (Management) and the people behind their success.