Study map · Advanced · Runs in your IDE
Practice file delivery, SSE and WebSocket.
Learn file delivery, SSE and WebSocket through three independent services. Some language journeys include a follow-up that combines all three.
01 · Learning order
Each first exercise keeps one subject
| Exercise | Only observe | Why it is separate |
|---|---|---|
| 01 · File delivery | GET /download returns manual.txt. | Focus on authority, path, limits and the file-response contract. |
| 02 · SSE | GET /events emits state: ready, then done. | Focus on one-way streaming, event fields and reconnect meaning. |
| 03 · WebSocket | GET /socket sends ready and echoes text. | Focus on upgrade, subprotocol and a bidirectional session. |
| 04 · Integration | All three endpoints in one service. | Learn composition after no capability needs to be guessed. |
The integration is optional, not the starting point. Production still maps authorization, replay and session policy to the application domain.
Open the exercise
02 · Verify the behavior
Run only the check for the current exercise
Replace PORT with the printed port
curl http://127.0.0.1:PORT/download
curl -N http://127.0.0.1:PORT/events
const socket = new WebSocket(
"ws://127.0.0.1:PORT/socket",
"coakka.demo",
);
socket.onmessage = (event) => console.log(event.data);
socket.onopen = () => socket.send("hello");03 · Parameters beside the example
Configure only what changes user-visible behavior
authority id- Identity connecting a file response to its configured root; it is not a filesystem descriptor.
root path- The allowed filesystem boundary. A request cannot select another absolute path.
max active files- Bounds concurrent transfers so a slow client cannot retain unlimited resources.
max file bytes- A larger file is refused instead of silently loaded or sent.
encoded path- A relative path inside the authority, selected by the application after authorization.
data- The SSE event payload.
event- An optional SSE event type for client dispatch.
id- An application cursor/identity; it does not create a replay store.
retry- An SSE client reconnect-delay hint, not a server retry.
subprotocol- The application protocol requested by the client and selected during the WebSocket handshake.
04 · Failure lookup
Start from the symptom, locate the boundary, then fix it
| Symptom | Common cause | Response |
|---|---|---|
| File 404/refusal | Wrong encoded path, missing file or path outside the authority. | Check business mapping and deployment; do not widen the root to hide the error. |
| File refused under concurrency | Active-transfer or file-size bound reached. | Measure concurrency/size; reduce load or tune from evidence. |
| SSE stops early | Client disconnect, write timeout or service drain. | Stop the producer and release its subscription; reconnect/replay by application policy. |
| WebSocket does not upgrade | Route, auth/origin, subprotocol or capacity mismatch. | Read the HTTP refusal and service error; do not create a fake session. |
| WebSocket closes after send | Handler error, message/pressure limit or peer close. | Read close code, background error and limits; reconnect finitely. |
| Timeout | No terminal outcome was observed within the budget. | Do not assume the message was not delivered; reconcile side effects before retry. |
05 · Operate the feature
Monitor behavior, not implementation details
- Count requests, status, latency and background service errors by route.
- Track active file transfers, bytes and size/capacity refusals.
- Track active SSE/WebSocket sessions, disconnects, close codes and write timeouts.
- Alert on rising refusal/timeout ratios, not a single isolated failure.
- During deployment, stop new admission, drain finitely and watch remaining sessions.
- Correlate requests/sessions with application identity without logging secrets or full payloads by default.