A scalable real-time messaging backend built with Rust, Actix-web, WebSockets, Redis Streams, and SQLite. Supports multi-user conversations, message delivery, receipts, reactions, and background workers for persistence.
- Multi-participant conversations
- Authenticated REST + WebSocket API
- Real-time message fan-out via Actix actors
- Redis Streams for durable event buffering
- Message receipts (delivered / read / reaction)
- Background workers for async DB persistence
- Participant caching for fast authorization
- HTTP API (Actix) — conversation & message management
- WebSocket Server (Actix actors) — live message delivery
- Redis Streams — message & receipt event bus
- SQLite (SQLx) — persistent storage
- Workers — consume Redis streams and persist events
- Client sends message via REST
- Message pushed to
messages_stream(Redis) - Message delivered live via WebSocket actor
- Background worker persists message to SQLite
- Receipts are generated and pushed to
receipts_stream
| Column | Type | Notes |
|---|---|---|
| name | TEXT | Conversation ID |
| title | TEXT | Optional title |
| admin | TEXT | Creator / owner |
| created | INT | Timestamp |
| Column | Type | Notes |
|---|---|---|
| conversation | TEXT | FK → conversations(name) |
| participant | TEXT | Username |
| Column | Type | Notes |
|---|---|---|
| id | TEXT | Message UUID |
| conversation | TEXT | FK → conversations(name) |
| source | TEXT | Sender |
| text | TEXT | Message body |
| reply_to | TEXT | Optional parent message |
| created | INT | Timestamp |
| Column | Type | Notes |
|---|---|---|
| message_id | TEXT | FK → messages(id) |
| user_id | TEXT | Receiver |
| delivered | BOOL | Delivered flag |
| read | BOOL | Read flag |
| reaction | INT | Optional reaction code |
| ts | INT | Event timestamp |
| Stream | Purpose |
|---|---|
messages_stream |
Buffer outgoing messages |
receipts_stream |
Buffer delivery/read events |
Workers consume these streams and write to SQLite.
All endpoints require authentication via Auth middleware.
Create a new conversation.
Body:
participants: [string]title?: stringname?: string
List all conversations the user participates in.
Get conversation metadata.
Send a message to a conversation.
Body:
text: stringreply_to?: string
Behavior:
- Validates participation
- Pushes event to Redis
- Delivers live to connected users
Retrieve message history.
Query filters supported via MessageFilters:
- pagination
- ordering
- limits
Also generates automatic delivery receipts.
Get delivery/read receipts for a message (sender only).
Send a reaction event for a message.
Mark a message as read.
Endpoint:
/ws
- Authenticated via middleware
- Users subscribe automatically to their conversations
- Messages are pushed in real-time via Actix actor system
- Consumes
messages_stream - Persists messages into SQLite
- Consumes
receipts_stream - Persists delivery, read, and reaction events
- Rust (stable)
- Redis
- SQLite
Create .env file or export variables:
# JWT / auth handled by auth_middleware
# Redis config loaded via redis_cfgcargo runServer starts on:
http://127.0.0.1:8082
Database file:
messages.db
Redis must be running before startup.
- Message delivery is non-blocking
- Persistence is eventually consistent
- Live delivery does not wait for DB writes
- Redis provides backpressure and durability
Suitable as:
- Messaging backend prototype
- WebSocket + Redis Streams reference
- Event-driven system example in Rust
- Chat system foundation for web or mobile apps
Advanced prototype. Missing production features:
- Message deletion / editing
- Typing indicators
- Pagination indexes tuning
- Conversation ACLs
- Backfill / retention policies
Not specified yet.