Back to Rivet

Stream Processor

examples/stream-render/README.md

2.3.22.5 KB
Original Source

Note: This is the Render-optimized version of the stream example. It adds a production HTTP server, Vite build, and a render.yaml Blueprint for deploying to Render.

Stream Processor

Example project demonstrating real-time top-K stream processing.

Getting Started

sh
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/stream
npm install
npm run dev

Features

  • Top-K Processing: Maintains the top 3 highest values in real-time
  • Real-time Updates: All connected clients see changes immediately
  • Stream Statistics: Total count, highest value, and live metrics
  • Interactive Input: Add custom values or generate random numbers
  • Reset Functionality: Clear the stream and start fresh
  • Responsive Design: Clean, modern interface with live statistics

Implementation

This stream processor uses a Top-K algorithm to efficiently maintain the top 3 values using insertion sort. Updates are instantly sent to all connected clients via event broadcasting.

  • Actor Definition (src/actors.ts): streamProcessor maintaining a sorted top-3 leaderboard with broadcast updates
  • Server Setup (src/server.ts): Hono app routing /api/rivet/* to the registry handler
  • React Frontend (frontend/app/App.tsx): useActor hook with live stats and event-driven UI

Deploy on Render

  1. Set Root Directory to examples/stream-render if deploying from the monorepo.
  2. Add the following environment variables in your Render service:
VariableDescription
RIVET_ENDPOINTBackend endpoint URL from your Rivet Cloud project
RIVET_PUBLIC_ENDPOINTPublic endpoint URL from your Rivet Cloud project
  1. In the Rivet dashboard, point Connect your backend at your service's HTTPS URL.

RIVET_ENVOY_VERSION is automatically derived from Render's RENDER_GIT_COMMIT — no manual bump needed per deploy. Set it explicitly to override.

Resources

License

MIT