ASGI (Uvicorn) + Redis pubsub. Do not look at solutions.md before submitting.
Exercise 1 — The decision matrix
- For each case, pick the protocol and justify in 2 lines: (a) public API for integrators; (b) internal billing-service talking to reservation-service; (c) a mobile app showing a configurable dashboard; (d) live support chat; (e) a "your ticket is ready" notification.
- Which of the five cases does NOT deserve anything new on TicketFlow today, and why?
Exercise 2 — Minimum viable SSE
- Start the lesson's SSE endpoint (or a simulated one publishing the free-seat count every 2s) with
python manage.py runserver(ASGI) and consume it withcurl -N http://.../events/{uuid}/availability/stream/. Do you see events arrive? - Publish from another process (
redis-cli PUBLISH avail:42 '{"free": 41}') and verify reception on the stream. - Add keepalive: a
: pingevent every 15s. Why do Nginx/proxies cut the connection without it?
Exercise 3 — From reservation event to push
- Connect
reserve()(10): after creating the reservation,PUBLISH avail:{event_id} {"free": N}. Verify your exercise 2 curl receives the update. - Design question: do you publish inside
transaction.atomic()or after the commit? What does the client receive if you pick the wrong side? (hint: rollback).
Exercise 4 — Connection load
- Open 200 SSE streams (a script with parallel
curl -Nor asynchttpx). Watch the process's memory (05) andss -tan(05): how many ESTAB connections? - Change keepalive to 1s and repeat: does anything measurable change? What happens with 2,000 connections and Uvicorn defaults (hint: open-file limits —
ulimit -n)?
Exercise 5 — The written decision (mini-ADR)
Write TicketFlow's ADR-0007: "Live availability via SSE" — context (the real pain), decision, rejected alternatives (polling with numbers, WS), operational consequences (connections, proxies, Last-Event-ID reconnection).
Submit
Paste the stream curl, the ADR and the load numbers. Next: Lesson 17 — Webhooks and third-party APIs.