{
  "id": 6228467,
  "title": "Delivery Map Presence at Scale: A 4-State Room Lifecycle for Trusted Event Flow",
  "url": "https://urgent.news/2026/09/08/delivery-map-presence-at-scale-a-4-state-room-lifecycle-for-trusted",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-08T03:59:29.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/thalynrift3485/delivery-map-presence-at-scale-a-4-state-room-lifecycle-for-trusted-event-flow-4a1l"
  },
  "original_language": "en",
  "account": "The article discusses a room lifecycle design for a delivery map application that requires explicit token scope, presence state, and recovery rules. The goal is to make the boundaries of real-time API visibility clear rather than hiding them in a client SDK. The article highlights four key states: authenticated, subscribed, publishing, and recoverable. Each transition between states should be observable data.\n\nThe server determines who can enter a workspace and publish delivery events. The client only renders presence and sends intent. Three separate streams are maintained: authentication, subscription state, and business events. Each stream should carry a workspace identifier, a short-lived token scope, and a monotonically increasing event sequence.\n\nPresence entries should include a role (courier or dispatcher), last-seen timestamp, and the sequence at which that state changed. This allows the map to show \"stale\" status without implying offline status. Token scope should be the narrowest possible, with server-side permission checks on reconnect. Client-side role flags are presentation hints, not authorization.\n\nThe article provides an example of a RoomState type and a next state function that determines the next state based on the current state and event type. It also defines a Presence type and an acceptPresence function to handle presence updates. When a disconnect event occurs, the server-side cleanup should be explicit, using a POST request to /v1/realtime/user/disconnect. For automatic network loss, the client should first mark itself as recoverable and use a bounded reconnect loop.\n\nA minimal recovery loop involves checking for expired credentials, duplicate deliveries using sequence checks, and handling partial failures with visible state to avoid claiming current positions. The retry process includes an idempotency key to prevent applying the same intent twice.",
  "summary": "Short answer: use a room lifecycle with explicit token scope, presence state, and recovery rules; pick the realtime API that makes those boundaries visible instead of hiding them in a client SDK. For an e-commerce delivery tracking map, “online” is not a boolean. A dispatcher can have a valid login but no map subscription. A courier can reconnect with an old token. A browser can receive the same…",
  "key_points": [
    "Four-state lifecycle: authenticated, subscribed, publishing, recoverable",
    "Server determines workspace access, client only renders presence and sends intent",
    "Three streams maintained: authentication, subscription state, business events"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}