realtime systems

HitCounter

A small but serious WebSocket playground: daily state, Redis-backed coordination, and a React surface that stays live.

PythonFastAPIWebSocketRedisReactAWS
Open repository

Realtime model

One bounded action, shared live.

Daily truth Redis Broadcast

Daily counter loop

One unique hit becomes durable, time-bounded state.

Browsermeaningful hitReact UIPOST /hitFastAPIrequest ownerDay bucketIP + timezoneRedistransaction + TTLCount + datebroadcast factConnected viewslive updateWS /ws snapshot

HTTP, WebSocket, and identity

One browser origin, proxied APIs, and durable presence.

React browsercounter + chatNginx proxyone public originFastAPIHTTP + WebSocketWebSocket fanoutbroadcast clientsRediscounter + identity TTLIdentity routeGET / POST nameHTTP /api and WS /api/ws

Legend

Synchronous requestAsynchronous eventInternal flowProcess or serviceState store
Initial snapshotOptimistic Redis retryLive WebSocket broadcast

The smallest system that makes realtime feel real.

HitCounter starts with a basic hit counter and grows into a compact WebSocket system. FastAPI handles the API, Redis owns bounded daily state, and connected browsers receive updates as they happen. The repository makes the edges visible: timezone buckets, uniqueness, TTLs, proxy upgrades, and a chat-ready identity flow.

The useful part is the sequence, not just the ingredients.

  1. 01

    The browser opens a WebSocket and receives the current snapshot.

  2. 02

    A hit resolves the configured daily time bucket.

  3. 03

    Redis records bounded state with uniqueness and TTL rules.

  4. 04

    The API broadcasts the new state to connected clients.

  5. 05

    The React surface stays current without a refresh.

Patterns that keep the system understandable as it grows.

01

Snapshot plus stream

A realtime client needs an initial truth as well as future updates, so the connection starts with state before it listens for change.

02

Bounded state

Redis keys use daily buckets, uniqueness rules, and TTLs so the demo stays deterministic without accumulating unbounded history.

03

Identity before chat

The chat-ready surface introduces a visitor identity flow before pretending the message timeline already exists.

04

Proxy-aware realtime

The web layer keeps HTTP and WebSocket traffic on one origin while preserving the upgrade path through the proxy.

Where this foundation could connect next.

Redis Streams or NATS

A next step when one in-memory broadcast loop needs replayable events or a more explicit message backbone.

Kubernetes / EKS

The repository already documents an AWS-shaped path; a cluster adds room for independent web, API, and worker scaling.

OpenTelemetry

Useful for following a hit from browser request to Redis write to WebSocket broadcast.

Not every open-source project has to be Gastrotech. This one demonstrates a useful building block for any future product where presence, live state, and shared context matter.