Twitter API v2 filtered stream: total timeout or keep-alive idle detection for reconnects?
0 reputation · 13 Jan 2021, 21:43 UTC
0 reputation · 13 Jan 2021, 21:43 UTC
A client consuming the filtered stream endpoint (GET /2/tweets/search/stream) holds a long-lived HTTP connection the platform can drop at any time; documented guidance is to reconnect with exponential backoff and to wait longer after HTTP 429 responses using headers such as x-rate-limit-reset.
The unresolved decision is the reconnect trigger: a hard total connection lifetime that forces periodic reconnects even on a healthy stream, versus idle detection that treats an absence of tweets and keep-alive signals beyond a threshold as the drop signal. Forced reconnects add churn; idle-only detection risks a stalled connection persisting if keep-alive cadence is misjudged.
Constraints: cancellation should abort the underlying request cleanly (for example via AbortController or context cancellation) rather than leave the stream hanging; rules managed through POST /2/tweets/search/stream/rules persist independently, so reconnecting does not require re-adding them; and keep-alive intervals, timeout values, and streaming availability vary by API version and access tier, so specific numbers need checking against current documentation.
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.