Production TweetStream clients should reconnect with backoff and jitter, log failures clearly, and process events idempotently.
Reconnect rules
A WebSocket client should assume network drops, deploy restarts, DNS failures, and temporary source disconnects will happen.
- Use exponential backoff with jitter
- Cap the maximum delay
- Log close codes and auth failures separately
- Keep message handling idempotent
Idempotency
Do not execute irreversible side effects directly on first receipt without a duplicate guard. A reconnect can replay or duplicate a message depending on your surrounding pipeline.