Real-Time

This document explains Azu's real-time capabilities through WebSocket channels and how they enable bidirectional communication.

Why Real-Time?

Traditional HTTP is request-response:

Client: "Give me data"
Server: "Here's data"
Client: "Give me data again"
Server: "Here's data"
...

Real-time applications need:

  • Instant updates without polling

  • Server-initiated messages

  • Efficient bidirectional communication

WebSockets provide:

Client ←→ Server
    Persistent connection
    Messages flow both ways
    Low latency

WebSocket Channels

Channels are the Azu abstraction for WebSocket connections:

Channel Lifecycle

Connection Management

Tracking Connections

Channels typically maintain a collection of active connections:

Broadcasting

Send messages to multiple clients:

This enables:

  • Chat rooms

  • Live notifications

  • Real-time dashboards

  • Collaborative editing

Message Protocol

JSON Messages

Typically, messages are JSON:

Client Protocol

Common Patterns

Room-Based Channels

Organize connections into rooms:

User-Targeted Messages

Associate connections with users:

Presence Tracking

Track who's online:

Authentication

WebSocket connections can be authenticated:

Client-side:

Scaling Considerations

Single Server

On a single server, channel state is in-memory:

Multiple Servers

For multiple servers, use Redis pub/sub:

Error Handling

Handle connection errors gracefully:

See Also

Last updated

Was this helpful?