Track, upload and search end to end
We follow one evening in the app that uses all three parts of the unit at once. Each flow keeps large or long-lived work away from the API servers, in a different way. We will cover tracking an order live, uploading a photo, searching for dinner, and the unit on one page.
#Section 33One evening, three flows
User 42 places order 124, and the app opens a live tracking screen. It asks the API for a ticket, POST /ws-ticket, and opens an SSE stream to rt.wren.example/orders/124/events over HTTP/2 with that ticket. The realtime server redeems the ticket, checks that order 124 belongs to user 42, and subscribes its process to the order:124 channel on the broker. When the kitchen accepts the order, the order service commits, its outbox event reaches Kafka, Unit VIII, and a publisher sends order:124 version 3, accepted to the broker. Only the realtime server holding user 42’s stream is subscribed, and it writes the event, with id 3, to the stream. The phone shows “accepted” within a few hundred milliseconds of the commit.
The phone loses signal in a lift. The stream drops with no close frame. When signal returns, EventSource reconnects with Last-Event-ID: 3, the load balancer sends it to a different realtime server, and that server replays events 4 and 5 from the replay buffer and carries on. The courier’s location arrives over the courier app’s WebSocket every 5 s, is coalesced to the latest position per order, and appears on the map. No API server held a connection for any of this.
When the food arrives, user 42 photographs it and uploads it with a review. The app asks the API for a presigned URL. The API checks that user 42 can review order 124, generates quarantine/u/42/8f3a2c91.jpg, and returns a PUT URL valid for 5 minutes and limited to images under 10 MB. The phone uploads 5 MB directly to object storage. The ObjectCreated event starts the pipeline. A worker checks the magic bytes, decodes and re-encodes the image without its GPS metadata, scans it, writes 400 px, 800 px and WebP variants under versioned keys to the public bucket, and marks the review’s photo ready in PostgreSQL. The app’s next refresh shows the photo from the CDN.
The next evening, user 42 searches “spicy rice dish near me”. The search service analyzes the query with the food analyzer, embeds it, and sends one query to the search engine with filters for open restaurants within 5 km. BM25 and HNSW retrieve candidates in parallel from the menu alias. RRF fuses them, a cross-encoder reranks the top 50, distance and rating boosts adjust the order, and the first result is restaurant 9’s chicken biryani, which BM25 alone would have ranked far lower. A price shown in the results was indexed 2 s after the restaurant’s last change, and the dish page, opened from the result, reads the current price from the database.
Put together, the unit is three answers to the same question, what to do with work that does not fit one short request. Realtime keeps connections open, so it treats each connection as state, authenticated by tickets, authorized per subscription, bounded by send buffers, fanned out through a broker, and resumed by sequence or event id after the inevitable drops. Files are large and hostile, so they go straight to object storage through presigned URLs, are validated and transformed in quarantine, cleaned up by lifecycle rules, and served from a CDN. Search needs structures a transactional database is not built for, so analyzers, inverted indexes, BM25 and vectors live in an engine that follows the database through a change stream and changes shape safely behind aliases. Unit XIII turns to the attacks that each of these surfaces invites, and the rest of the backend’s security.