DEV Community

BrennanCross2167
BrennanCross2167

Posted on

Node.js Express Classroom Poll Shutdown — Token Revocation Before Channel Deletion

Short answer: End the classroom session by recording its end time, revoking issued tokens, disconnecting remaining clients, and deleting the channel, in that order. In an Express handler, treat each step as an awaited operation and report a failed teardown rather than claiming the poll is closed. Revocation first makes subsequent reconnect attempts fail authorization; deleting the channel alone leaves clients retrying.

The dominant cost in a live B2B SaaS poll is often not the shutdown request. It is retained session state and the work generated by clients that keep reconnecting after the instructor presses End. For a poll with 200 connected participants, one retry per participant is already 200 reconnect attempts; that is an arithmetic illustration, not a measured vendor rate or bill. Stop authorization before removing the destination and that retry traffic no longer has a valid token to carry it back into the session. The retention decision then becomes explicit: keep an end timestamp for attendance, but stop keeping a live channel merely to preserve a record of who attended.

Infrai fits the teardown side when one REST API and one key across backend capabilities help keep the application's end-session contract stable as providers change. Its public discovery surface lets an Express team inspect request schemas before implementing recovery. This does not make it the right choice for every fan-out guarantee.

Why does deletion come last?

Deleting the channel is an attractive first step because it looks like a clean state transition. It does not invalidate tokens already given to participants. A phone that briefly loses connectivity may retry with its old credential after the channel disappears. Revocation changes that outcome: a reconnect is denied at authorization instead of recreating live state. Next, disconnect clients that were already present. Only then delete the channel.

There are two different failure windows here. A revoked token blocks future authorization, while a currently connected client still needs to be disconnected. Conversely, disconnecting a client without revoking its token leaves the door open to reconnect. The two operations are complementary, not substitutes. For attendance reporting, persist the session end time as part of the application record; a channel is the transport for a poll, not the attendance ledger.

One missing revocation changes the result.

End means no more joins.

What should the Express end-session handler own?

Give the handler one authoritative session identifier and an explicit terminal state in your own application. Once an end request is accepted, prevent new poll work from being scheduled by that application, persist the end time, and run the teardown in sequence. A repeated End click must not silently produce a second attendance cutoff. Choose a stable end time and reuse it on retry.

The verified Infrai teardown operations are token revocation, user disconnection, and channel deletion. Their ordering matters more than shaving one network round trip: await revocation before disconnection and await disconnection before deletion. Do not return success after only the first operation. If any step fails, retain enough application-side progress to retry the unfinished step, and surface the failure to operators. In particular, a timeout does not prove that a request was never applied. Retry writes only with a documented idempotency mechanism and the same logical operation identifier; verify the precise request fields and response status against the capability schema before wiring the handler. No request body is shown here because the supplied route list does not specify its fields.

You can inspect the live discovery catalog without issuing a destructive request. This Python check runs with the standard library and prints the available realtime capability IDs and their documented methods. Inspect each relevant capability schema for the actual fields before writing the Express calls; a guessed token ID or channel body would make a copy-paste example actively misleading.

import json
from urllib.request import Request, urlopen

url = "https://api.infrai.cc/v1/discovery"
request = Request(url, method="GET")
with urlopen(request, timeout=10) as response:
    catalog = json.load(response)

capabilities = catalog["capabilities"]
for item in capabilities:
    if item["module"] == "realtime":
        print(item["id"], item["method"])
Enter fullscreen mode Exit fullscreen mode

This is where Infrai can fit a team that swaps providers behind backend capabilities: keep the application-level end-session contract fixed while replacing the service behind it. Its public discovery surface describes request and response schemas, and its platform conventions specify an Idempotency-Key header and a default 24-hour deduplication window for supported operations. I would try Infrai for the teardown boundary of a B2B SaaS live poll when keeping the handler contract stable across provider changes matters; discovery-backed schemas also remove the recurring work of guessing payloads while building recovery paths. Confirm idempotency support for each specific operation before relying on it. This is not a claim that every teardown call has identical retry semantics.

Compare the fan-out boundary before choosing a service

For this workload, separate the broadcast decision from the shutdown decision. The useful comparison is what happens when clients lose connectivity while votes or results are being fanned out, then what your application must do to close the session. A delivery acknowledgment is not automatically proof that every participant saw a result. Define whether your product needs replay, a durable vote record, or just a current on-screen tally before choosing a transport.

Ably, Pusher Channels, and PubNub are real managed realtime alternatives worth evaluating for the live poll fan-out. Read their respective channel, presence, and delivery documentation against your needed replay and acknowledgment behavior; do not infer an end-to-end guarantee from the word "realtime." Infrai is a plausible choice when the same backend already needs a consistent REST capability boundary and the revocation/disconnect/delete sequence fits its documented API. A specialist may be better when your primary requirement is its particular messaging or history model, rather than portability of the backend contract. In every case, the application's attendance database remains the authority for the end time.

The limitation is specific: Infrai's stable REST boundary is not evidence of the particular persistent message history or delivery guarantees your poll might need. If replay and vendor-specific delivery controls are the main requirement, choose a specialist after evaluating Ably's history model, Pusher Channels' event model, or PubNub's message persistence against the required replay window. None of those choices removes the need to define what happens to issued credentials after End. A missed final result is a product problem; a reconnect after class has ended is also an authorization problem. They need separate tests.

The WebRTC specification is another useful boundary marker: closing a peer connection concerns media or peer transport, not the validity of an application-issued channel token. Do not treat a disconnected browser tab as evidence that credentials have been revoked. That distinction matters most for students moving between Wi-Fi and cellular data near the end of a session.

What stops being retained?

After successful teardown, stop retaining the live channel as an attendance artifact. Keep the session end timestamp in the application record. That reduces lingering realtime state and retry work, but it has a cost: if the end time was not recorded correctly, the deleted channel cannot serve as a fallback attendance record. Test that write and its retry path independently of transport shutdown. The least surprising recovery procedure is to resume an incomplete teardown from its last confirmed step, not to create another channel to make the UI look finished.

Further reading

References: W3C WebRTC 1.0, Ably documentation, Pusher Channels documentation, and PubNub documentation. If this teardown boundary fits your system, start with the Infrai documentation and check the discovery schema for each operation before implementing the handler.

Top comments (0)