---
id: realtime/realtime-application
title: Realtime application
summary: Add JSKIT realtime events with an optional Redis backplane and an explicit shell status contribution.
keywords: redis, realtime, socket.io, sockets, status, websocket
requires: @jskit-ai/realtime, @jskit-ai/shell-web
---

# Realtime application

## Use when

Use this pattern when the product needs server-to-client events or live query
refresh. Install the realtime package normally, then add only the product's
listeners and desired shell contribution.

## Do not use when

Do not add realtime merely to poll less often, or before event ownership and
delivery semantics are clear. A single-process application does not need Redis.

## Product decisions

Decide which events are public contracts, their scopes and payloads, reconnect
behavior, whether a connection indicator belongs in the UI, and whether
staging or production needs a Redis backplane.

## Invariants

- Empty `REALTIME_REDIS_URL` means the in-process adapter.
- Redis credentials stay outside Git.
- Listeners are registered through the public provider seams.
- The status indicator is an explicit app placement, not a source mutation.
- Event payloads do not become an undocumented second API.
- Socket.IO owns `/socket.io`; other WebSocket routes keep their own upgrade
  and access-check lifecycle without Socket.IO's one-second cleanup timeout.
- Realtime connects over WebSocket only, so no address carries its session id;
  whatever runs in front of the app passes WebSocket upgrades on `/socket.io`.

## Framework APIs

Server features declare their successful domain events on their actions. The
installed `RealtimeProvider` delivers only events with an explicit realtime
name and audience. Client features use `RealtimeClientProvider` and the public
listener registration helpers from `@jskit-ai/realtime`. Use the normal shell
placement registry for the optional status component.

An audience's `audienceUsers({ event, options })` reads in a context scoped to
the event's workspace, user or workspace user. An application whose action
events declare such an audience registers `RealtimeAudienceScopeFeature` from
`@jskit-ai/realtime/server/RealtimeAudienceScopeFeature`, which provides those
contexts, or realtime refuses to boot. An audience that reads only public
tables marks itself `publicTablesOnly: true` and reads with no context.

## Example files

`example/package.json` declares realtime and shell runtime packages.
`example/.env.example` documents the optional Redis input.
`example/src/placement.js` adds the standard connection indicator explicitly.

## Variation points

Omit the placement when the product does not need a visible connection state.
Change event listeners, Redis provisioning, and client invalidation behavior to
match the product. Keep transport retry policy in the realtime runtime.

When every realtime event belongs behind the application's authentication
boundary, let the selected `auth.service` opt in with
`realtime.requireAuthentication: true`. Socket.IO then rejects an
unauthenticated handshake before the client can join any broadcast room. A
browser whose login identity changes must disconnect and reconnect its socket
so the next handshake resolves the new actor.

Use `auth.service.realtime.authorizeEvent({ actor, event: { name, payload } })`
for resource-specific read authorization. Return `true` only when the current
actor can read that event's resource. Authentication is revalidated before
delivery and every 30 seconds while idle. Redis peers perform the same checks
locally. Realtime failures are logged without failing an already-successful
mutation; one mutation owner publishes each completion, while progress events
describe distinct lifecycle states.

## Verification

- Test in-process delivery without Redis.
- When authenticated-client mode is selected, reject an anonymous handshake
  and reconnect after login, logout, and identity changes.
- When Redis is selected, test delivery across two server processes.
- Disconnect and reconnect a browser and verify recovery behavior.
- Confirm the status contribution renders in compact and expanded shells.

## Avoid

- prompting for optional Redis configuration during package installation
- appending source into placement files
- leaking Redis values to client config
- generic “data changed” payloads with no scope
- receipts, provenance, or mutation history
