Skip to main content

SignalR Real-Time Application Development

Build real-time features with SignalR — hubs, groups, strongly-typed clients, authentication, and scaling with a Redis backplane.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Build real-time features for my collaborative document editor using SignalR in .NET 8. 1) Hub design: create a DocumentHub hub with methods for SendEdit, BroadcastCursorPosition, NotifyUserJoined, SyncDocument — use strongly-typed hub interface (ISomethingClient) for compile-time safety. 2) Client groups: implement group management for users editing the same document join a group identified by document ID — users join/leave groups dynamically, and messages target specific groups. 3) Authentication: secure the hub with JWT Bearer token passed as query string for WebSocket — show how to access user claims in hub methods and restrict access to Editor and Owner. 4) Client implementation: build a TypeScript browser client using @microsoft/signalr client that connects, handles reconnection with exponential backoff, and manages connection lifecycle properly. 5) Scaling: configure Redis backplane for horizontal scaling across 3 instances behind a load balancer server instances — handle sticky sessions vs backplane trade-offs. 6) Performance: implement streaming for streaming incremental document changes to all connected editors using IAsyncEnumerable to avoid loading large datasets into memory. 7) Error handling: add hub filters for logging, exception handling, and rate limiting of hub method invocations. 8) Testing: write integration tests for hub methods using HubConnection in-process.

What this prompt does

This prompt builds real-time features for an [application_type] using SignalR in [dotnet_version]. It designs a [hub_name] hub with methods for [hub_methods] behind a strongly-typed hub interface, implements group management for [group_scenario], secures the hub with [auth_method] restricted to [authorized_roles], builds a [client_type] client with reconnection and exponential backoff, scales across [instance_count] instances via a [backplane] backplane, and adds streaming for [streaming_scenario] using IAsyncEnumerable.

The structure works because live updates without polling only stay reliable if reconnection, auth, and scaling are handled deliberately. The strongly-typed hub interface keeps client and server in sync at compile time, the Redis backplane fans messages across instances behind a load balancer, and the streaming step avoids loading large datasets into memory. Hub filters for logging, exception handling, and rate limiting round out the design so a misbehaving client can't take the hub down.

When to use it

  • A client needs live updates — collaborative editing, dashboards, or notifications — without polling
  • You are designing a [hub_name] hub and want strongly-typed methods for [hub_methods]
  • You need dynamic group management so messages target the right [group_scenario]
  • You must secure the hub with [auth_method] and restrict access to [authorized_roles]
  • You are scaling SignalR across [instance_count] instances and need a [backplane] backplane
  • You want streaming for [streaming_scenario] instead of buffering large datasets in memory

Example output

Expect a design with code: a hub class with a strongly-typed client interface, group join/leave logic, authentication configuration accessing user claims and restricting roles, a client implementation handling connection lifecycle and reconnection with exponential backoff, backplane configuration for horizontal scaling, an IAsyncEnumerable streaming method, hub filters for logging, exception handling, and rate limiting, plus integration tests using HubConnection in-process.

Pro tips

  • Define a strongly-typed client interface for [hub_methods] so the compiler catches mismatched method names between server and [client_type] instead of failing silently at runtime
  • Plan group membership for [group_scenario] around a stable key like document ID, and handle rejoining groups after a reconnect, since group membership is lost on disconnect
  • For WebSocket auth, remember the token often rides in the query string, as [auth_method] notes, because custom headers aren't available on the WebSocket handshake
  • Add a [backplane] like Redis as soon as you run more than one instance; without it, messages only reach clients connected to the same server
  • Build reconnection with exponential backoff into the client from the start, since transient drops are normal and a client that gives up looks broken to users
  • Use IAsyncEnumerable streaming for [streaming_scenario] to avoid materializing large payloads, and apply hub filters for rate limiting so one client can't flood the hub
  • Write integration tests with an in-process HubConnection so you exercise real hub methods and group routing rather than mocking the SignalR pipeline away

Frequently Asked Questions

Why use a strongly-typed hub interface?
A strongly-typed client interface gives compile-time safety for your `[hub_methods]`, so a renamed or mistyped method between server and `[client_type]` is caught at build time rather than failing silently at runtime. It keeps client and server contracts in sync, which is especially valuable as the hub's method set grows.
Do I need a backplane to scale SignalR?
Yes, once you run more than one server instance. Without a `[backplane]` like Redis, a message sent on one instance only reaches clients connected to that same instance. The backplane relays messages across all `[instance_count]` instances behind your load balancer so every connected client receives them regardless of which server they hit.
How is authentication handled over WebSockets?
The prompt secures the hub with `[auth_method]`, and for WebSocket connections the token is typically passed via the query string because custom headers are not available during the WebSocket handshake. Inside hub methods you can access user claims and restrict access to `[authorized_roles]`, so authorization happens per connection and per method.
Does it handle client reconnection automatically?
It builds a client that handles reconnection with exponential backoff and manages the connection lifecycle properly. Note that on reconnect, group memberships are lost, so the client must rejoin groups for `[group_scenario]`. The prompt accounts for this, since transient disconnects are normal and a client that fails to recover looks broken to users.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in C# & .NET Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support