Why we poll at the edge instead of the originПочему мы поллим на edge, а не на origin
A media session is a tiny thing — a position, a token, a couple of bitrate flags. But players touch it constantly: every few seconds, on every device. When that round-trip crosses an ocean to your origin, the cost shows up as laggy resume, late watch-party sync and stale QoE data.
Our first version polled the origin directly. p50 was fine in our home region and ugly everywhere else. So we moved the long-poll termination to the CDN edge.
What "polling at the edge" means here
The edge PoP accepts the client's long-poll, holds the connection on a warm keep-alive to origin, and returns the delta the moment it's ready. The viewer pays one short hop to the nearest city instead of a full transcontinental round-trip.
- Cache stays off for the session path — every poll is live.
- Query string, cookies and the playback token are forwarded untouched.
- The SDK bundle, by contrast, is cached hard at the same edge.
What it cost
Keep-alive pools per PoP, careful timeout tuning, and a health endpoint the CDN can probe cheaply. The payoff: median poll round-trip dropped to ~38 ms across regions.
If you're building something similar, the one rule we'd repeat: never let the edge cache the dynamic channel. A cached session delta is worse than a slow one.
Медиа-сессия — мелочь: позиция, токен, пара флагов битрейта. Но плееры дёргают её постоянно: каждые несколько секунд, на каждом устройстве. Когда этот round-trip идёт через океан до origin, цена видна как лаги при продолжении, опоздавший синхрон совместного просмотра и устаревшая QoE-аналитика.
Первая версия поллила origin напрямую. p50 был ок в домашнем регионе и ужасен везде ещё. Поэтому мы перенесли терминацию long-poll на edge CDN.
Что значит «поллить на edge»
Edge-узел принимает long-poll клиента, держит соединение с origin на тёплом keep-alive и отдаёт дельту, как только она готова. Зритель платит за один короткий хоп до ближайшего города вместо полного трансконтинентального round-trip.
- Кэш выключен для session-пути — каждый поллинг живой.
- Query, cookies и playback-токен форвардятся без изменений.
- А вот бандл SDK кэшируется на том же edge жёстко.
Чем это обошлось
Пулы keep-alive на каждый PoP, аккуратная настройка таймаутов и health-endpoint, который CDN может дёшево опрашивать. Результат: медианный round-trip поллинга упал до ~38 мс по регионам.
Если строите похожее, одно правило мы бы повторили: никогда не давайте edge кэшировать динамический канал. Закешированная дельта сессии хуже медленной.