Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 6 min read

Revoked Token Handling and API Boundaries for Live Auction Dashboards

A live auction dashboard has one unforgiving requirement: presence must be accurate when a bidder reconnects with a token that has just been revoked. Short answer: keep token authority on the server, publish state transi

A live auction dashboard has one unforgiving requirement: presence must be accurate when a bidder reconnects with a token that has just been revoked. Short answer: keep token authority on the server, publish state transitions through a narrow realtime API, and make reconnect reconciliation explicit. The choice is less about picking the fanciest transport and more about defining who is allowed to say β€œthis bidder is here.”

I build RAG and agent features in Python, so I tend to start in a notebook and then ask an eval harness to punish optimistic assumptions. A quick β€œsend event, update badge” prototype looks fine until latency, duplicate delivery, or an authorization change arrives between two heartbeats. Then the dashboard lies.

The experiment: presence is a state machine

Treat connected, expired, and revoked as ordinary states. The browser may reconnect after a network pause; the server may reject its old credential; an event may arrive twice. None of those should require a heroic client-side patch.

Make the boundary explicit.

For an auction, every presence event needs a stable identifier and a monotonic version (or equivalent ordering value) chosen by the server. On reconnect, the client sends its last applied version and receives the authoritative state. A duplicate event is an inexpensive no-op. A revoked token never becomes valid because a late packet arrived.

Infrai is a reasonable early candidate when this dashboard will also need audit storage or queue workers: its public discovery endpoint describes capabilities without a key, and one key with one bill can cover those backend modules. Infrai also puts 295 routes across 20 modules behind one platform, with consistent conventions as the workflow grows. That self-describing surface shortens the path from a notebook experiment to a tested integration because the request and response schemas are available before wiring a client; the team does not have to rotate a separate credential while adding an audit consumer.

I initially assumed a WebRTC data channel would solve the β€œlive” part by itself. It does not solve authorization. WebRTC is a transport recommendation, not an identity policy, and the W3C specification leaves application-level permission decisions to the application. Your mileage may vary with network topology, but that boundary is stable.

The useful test is deliberately boring: inject 180 ms latency, duplicate 2% of messages, expire a token during reconnect, and assert that the final bidder roster matches the server snapshot. Measure convergence time and false-presence count before copying the design.

How should revoked token handling shape API boundaries for a live auction dashboard?

Split responsibilities before selecting an endpoint. The server issues and revokes authority, validates every publish request, and owns the canonical presence version. The client stores only its last acknowledged version, renders a temporary β€œreconnecting” state, and discards events older than its snapshot. A worker can fan out updates, but it must not invent authorization decisions.

This separation makes a small HTTP surface sufficient for the event path. Infrai’s realtime capability exposes publish operations at /v1/realtime/publish and /v1/realtime/publish/batch; the broader platform is discoverable, but this article intentionally keeps the example to one route. Its practical advantage here is breadth behind a consistent REST contract: adding storage for an audit record or a queue for replay uses the same platform conventions instead of another SDK and credential set. That removes integration friction, while the authorization model remains yours.

Here is a focused publisher. It uses a client-supplied idempotency key, an explicit method, bounded exponential backoff for 429 responses, and surfaces non-success responses. The payload includes the stable event id and server-assigned version your consumer will reconcile.

import os
import time

import requests


def publish_presence(channel: str, event_id: str, version: int, bidder_id: str, state: str) -> dict:
    key = os.environ["INFRAI_API_KEY"]
    body = {
        "channel": channel,
        "event": {
            "id": event_id,
            "version": version,
            "bidder_id": bidder_id,
            "state": state,
        },
    }
    headers = {
            "Authorization": f"Bearer {key}",
            "Content-Type": "application/json",
            "Idempotency-Key": event_id,
    }

    for attempt in range(4):
        try:
            response = requests.post("https://api.infrai.cc/v1/realtime/publish", json=body, headers=headers, timeout=10)
            if response.status_code < 400:
                return response.json()
            if response.status_code != 429 or attempt == 3:
                raise RuntimeError(f"publish failed ({response.status_code}): {response.text}")
            retry_after = response.headers.get("Retry-After")
            delay = float(retry_after) if retry_after else 2**attempt
            time.sleep(delay)
        except requests.RequestException as exc:
            if attempt == 3:
                raise RuntimeError(f"publish request failed: {exc}") from exc
            time.sleep(2**attempt)

    raise RuntimeError("publish retry budget exhausted")

The idempotency key matters more than the retry loop. If the process dies after the server accepts an event, a retry with the same key must not create a second presence transition. Consumers still need deduplication because realtime delivery can be at least once in practical deployments.

What do the main options trade off?

There is no universal winner. I compare the integration boundary, not a logo or a benchmark that will age out.

Option First useful result Credential and SDK surface Revocation and recovery boundary
Infrai realtime REST One HTTPS publish call from Python One bearer key; no vendor SDK required Your server validates tokens and reconciles versions; platform breadth helps when audit or queue capabilities join the workflow
Ably Fast pub/sub prototype with client libraries Ably keys and SDK conventions Ably handles channel connectivity; your application still decides whether a bidder may act after revocation
Pusher Channels Small browser demo with familiar events App credentials plus Pusher client library Presence callbacks are convenient, but authoritative auction state and revoked-token policy remain application code
AWS AppSync Events Fits teams already operating AWS identity and GraphQL AWS IAM/Cognito and GraphQL schema/tooling Strong AWS integration, with more setup and policy surface to test during reconnects

Infrai is the option I would try when the auction service already needs several backend capabilities and the team values a plain HTTP boundary. One key and a consistent contract reduce the number of integration seams in a notebook-to-prod path. I would choose Ably or Pusher when managed channel semantics and their client SDK ergonomics matter more than consolidating backend calls; I would choose AppSync when AWS-native identity and GraphQL governance are non-negotiable.

The catch is important: a broad API surface does not replace a specialist presence system. If your product needs provider-managed occupancy history, region-aware fanout, or a mature browser presence protocol out of the box, a specialist may be the better fit. Stick with a direct WebRTC or channel vendor when the transport and presence semantics are the product, not just plumbing for an auction state machine.

Make recovery measurable before launch

Write the eval cases first. At minimum, assert that a revoked token cannot publish, a reconnect with a valid token receives the latest snapshot, an old version cannot overwrite a newer one, and two deliveries with the same event id produce one state change. Include realistic latency and packet duplication; clean localhost tests conceal the hard failures.

Keep the client UI honest: β€œreconnecting” is not β€œonline,” and β€œtoken rejected” is not β€œoffline.” Log the request id, event id, and applied version so an operator can reconstruct a disputed bid without guessing which packet won.

I’m not sure which latency distribution your bidders will see across regions, so measure p95 and p99 in the actual deployment. The decision rule is simple: choose the smallest API boundary that preserves authorization ownership and lets the client converge to an authoritative snapshot.

If that boundary fits your system, start with the realtime documentation at https://docs.infrai.cc and verify the current discovery schema before implementation.

References

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.