C.W.K.
Stream
Lesson 01 of 08 · published

HTTP 의 그 한계

~14 min · foundations, http

Level 0Poller
0 XP0/60 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Request-response 는 일방통행

HTTP 는 엄격한 request-response 계약 위에 올라가있어. 클라가 묻고, 서버가 답하고, 연결 끊고, 다음. 서버가 먼저 말 못 해, 클라가 절실하게 필요한 것을 알고 있어도. 식당에서 웨이터가 절대 테이블에 다가올 수 없는 그림이야 — 음식이 10분 전에 나왔는데 네가 손짓해서 부르기 전엔 모르는 거.

이 모델은 문서 받아오는 데는 괜찮아. 이벤트 한테는 구조적으로 적대적이야. modern web 의 모든 'real-time' 기능 — chat, presence, live price, collaborative cursor, AI 토큰 streaming — 다 같은 문제의 다른 옷이야. 서버는 새 소식이 있고, 클라는 묻지 않았고, 다음 request 까지 기다리는 건 답이 아니야.

HTTP overhead 의 비용

HTTP request 마다 cookie, auth token, user-agent, accept-encoding negotiation, content-type, origin — 헤더의 짐이 따라붙어. 한 자리 정수 답을 받으려고 수백 바이트의 메타데이터를 끌고 가. 분당 1 request 면 안 보이지. 백만 user × 초당 10 request 면 transit 과 CPU 로 수백만 달러야.

이 quest 가 가는 길

Track 1 은 WebSocket 을 polling, long polling, Server-Sent Events 옆에 같이 올려놓고 지도를 그려. Track 끝나면 ceremony 없이 옳은 걸 골라. WebSocket 은 도구 하나야. 가끔 옳은 답이고, 자주 그렇지 않아.

Code

HTTP request 가 실제로 끌고 다니는 짐·http
GET /api/messages HTTP/1.1
Host: example.com
Cookie: session=abc123def456
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

# ~600 bytes of envelope just to ask: "anything new?"
# Multiply by 10K clients polling every 2 seconds.
같은 대화, 세 번 물어본 깊이·text
Client                          Server
  |                                |
  |--- GET /messages ------------->|
  |<-- 200 OK [] ------------------|   "no, nothing new"
  |                                |
  |   ... 3 seconds idle ...       |
  |                                |
  |--- GET /messages ------------->|
  |<-- 200 OK [] ------------------|   "still no"
  |                                |
  |   ... 3 seconds idle ...       |
  |   (server now has news)        |
  |                                |
  |--- GET /messages ------------->|
  |<-- 200 OK [{msg}] -------------|   "finally"

External links

Exercise

브라우저 dev tools 의 network 탭 열어놓고, 매일 쓰는 chat 이나 social 앱 들어가서 30초 idle 상태로 봐. 분당 request 몇 개? polling 인지 long-polling 인지 SSE (text/event-stream 보임) 인지 WebSocket (status 101 보임) 인지 노트해. 이 리스트 quest 끝나면 다시 와서 본다.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.