sse의 연결 요청은 client가 수행한다.
sse는 연결된 시간 동안 connection을 유지하기 때문에 서버 자원을 소모한다. 따라서 sse connection을 너무 길게 설정하면 불필요하게 서버 자원을 소모한다.
한편 client는 데이터가 오지 않은 상태에서 설정된 retry 시간이 지나면 서버로 다시 sse 연결 요청을 한다.
즉 sse 시간을 너무 짧게 설정하면 long polling방식과 차이가 없어지고, sse를 너무 길게 설정하면 서버 자원이 소모될 염려가 있다.
polling과 sse의 가장 큰 차이는 클라이언트 구현에 있다. (서버 입장에서는 Connection을 유지해놓고 데이터를 전송한다는 점에서는 큰 차이가 없다)
Long polling의 경우 이벤트 발생 시 request 재전송 등의 로직을 프론트엔드 개발자가 구현해야 한다. 그러나 sse의 경우 이러한 처리를 브라우저 자체가 지원한다.
EventSource interface allows the application to focus on the business logic: open new connection, process received event notifications, terminate stream when finished.
As icing on the cake, the EventSource interface also provides auto-reconnect and tracking of the last seen message: if the connection is dropped, EventSource will automatically reconnect to the server and optionally advertise the ID of the last seen message, such that the stream can be resumed and lost messages can be retransmitted.출처
프론트엔드 개발자는 새로운 스트림의 생성, 이벤트별 분기처리 등 핵심 로직에만 집중할 수 있는 게 polling방식과의 차이라고 볼 수 있다.
polling방식의 경우 클라이언트 request가 제어권을 가진 반면 sse는 재접속 시도 시간의 제어권도 서버에게 있다는 점이 다르다.
SSE was specifically designed as a simple, efficient, server-to-client transport for text-based data. If you need to transfer binary payloads, then a WebSocket is the right tool for the job.