# Overview Long polling is... #flashcard An option for handling communication via an [[HTTP(S)]] API request that keeps the connection between a client and [[Computer Server]] open until the server has data to send back to the client. This allows for sending the response data to the client as soon as it is available, without the client needing to send additional requests to the server. Once the data is received, the client can immediately send another request to reopen the connection and repeat, as necessary. <!--ID: 1751507777137--> # Key Considerations This approach can be implemented using standard [[Load Balancer]] and [[Firewall]]s. You must consider the polling frequency (15-30 seconds) is common. Also, you must consider how the servers will send the data to the client. Approaches include: - Pushing via [[Consistent Hashing]] - Pushing via [[Pub-sub]] # Pros of Long Polling #flashcard - Builds on standard HTTP and works everywhere HTTP works - Easy to implement - No special infrastructure needed - [[stateless]] server-side <!--ID: 1751507777140--> # Cons of Long Polling #flashcard - Higher latency than alternatives - More HTTP overhead - Can be resource-intensive with many clients - Not suitable for frequent updates due to the issues with latency when re-establishing a connection - Makes monitoring more painful since requests can hang around for a long time - Browsers limit the number of concurrent connections per domain, meaning you may only be able to have a few long-polling connections per domain <!--ID: 1751507777142--> # Use Cases for Long Polling #flashcard - Near real-time updates with a simple implementation where the updates are infrequent (e.g., payment processing) <!--ID: 1751507777144--> # Related Topics --- Items to discuss when using long polling in a system design interview: #flashcard - Polling frequency. - Keep in mind that each hop in your infrastructure needs to be aware of these lengthy requests: you don't want your load balancer hanging up on the client after 30 seconds when your long-polling server is happy to keep the connection open for 60 (15-30s is a pretty common polling interval that minimizes the fuss here) <!--ID: 1752427993568--> ---