Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sockudo/sockudo/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Sockudo is built with a modular architecture that enables horizontal scaling, flexible backend storage, and high-performance real-time communication. The server uses an adapter pattern throughout, allowing you to swap implementations based on your infrastructure needs.Core Components
Sockudo’s architecture is composed of several key subsystems:Connection Manager & Adapters
The Connection Manager handles all WebSocket connections and channel subscriptions. It uses an adapter pattern to support different scaling strategies:- Local Adapter - In-memory implementation for single-node deployments
- Redis Adapter - Distributed pub/sub using Redis for horizontal scaling
- Redis Cluster Adapter - High-availability setup with Redis Cluster
- NATS Adapter - Cloud-native messaging with NATS for multi-region deployments
ConnectionManager trait, making it easy to switch between implementations without changing application code.
App Manager
The App Manager handles application configuration and credentials. It supports multiple backend storage options:- Memory - In-memory storage for development
- MySQL - Traditional relational database
- PostgreSQL - Advanced relational database with JSON support
- ScyllaDB - High-performance NoSQL database
- DynamoDB - AWS managed NoSQL service
Cache Manager
The Cache Manager provides a flexible caching layer for:- Channel data caching
- App configuration caching
- Presence member lists
- Rate limiting counters
- Memory - Local LRU cache
- Redis - Distributed caching
- Redis Cluster - High-availability distributed caching
Queue Manager
The Queue Manager handles asynchronous job processing, primarily for webhooks:- Memory Queue - In-process queue for single-node setups
- Redis Queue - Distributed queue with Redis
- Redis Cluster Queue - High-availability queue
- SQS - AWS managed queue service
Horizontal Scaling
Sockudo achieves horizontal scaling through its adapter architecture:Choose an adapter
Select Redis, Redis Cluster, or NATS as your connection adapter. This enables pub/sub across multiple server instances.
Configure shared state
Use a database-backed App Manager (MySQL, PostgreSQL, DynamoDB) so all instances share the same application configuration.
Deploy multiple instances
Launch multiple Sockudo instances with identical configuration. Each instance maintains its own local connections.
How Messages Flow
- Client A connects to Instance 1 and subscribes to
channel-1 - Client B connects to Instance 2 and subscribes to
channel-1 - API request publishes message to
channel-1on Instance 1 - Instance 1 publishes message to Redis/NATS adapter
- Instance 2 receives message from adapter and delivers to Client B
Message Flow
The path of a message through Sockudo:- HTTP API receives event - REST endpoint accepts event data
- Authentication - HMAC-SHA256 signature validation
- Channel broadcast - Message sent to adapter for distribution
- Tag filtering (optional) - Server-side filtering based on subscriber filters
- Delta compression (optional) - Compute and send delta instead of full message
- WebSocket delivery - Message serialized and sent to connected clients
- Webhook queuing - Event queued for webhook delivery if configured
Performance Optimizations
Connection Pooling
All database and Redis connections use connection pooling automatically. Pool sizes are configurable:Bounded Buffers
WebSocket connections use bounded buffers to prevent slow consumers from exhausting memory:- Message-based limits - Maximum number of queued messages (default: 1000)
- Byte-based limits - Maximum buffer size in bytes (optional)
- Backpressure handling - Disconnect or drop messages when buffer is full
Zero-Copy Message Parsing
Sockudo usessonic-rs for JSON parsing with minimal allocations and zero-copy string handling where possible.
Lock-Free Data Structures
Critical paths use lock-free algorithms and atomic operations to minimize contention:- Atomic counters for metrics
- Lock-free channel caches
- Optimistic concurrency for presence updates
Security Architecture
Authentication Layers
- WebSocket Authentication - App key validation on connection
- Channel Authentication - HMAC signatures for private/presence channels
- API Authentication - Pusher-compatible request signing
- Origin Validation - Per-app CORS origin checking
Rate Limiting
Multi-level rate limiting protects against abuse:- HTTP API rate limiting - Per-IP limits on REST endpoints
- WebSocket rate limiting - Per-connection message rate limits
- Backend rate limiting - Redis-based distributed rate limiting
TLS/SSL Support
Sockudo supports TLS termination with:- Certificate-based HTTPS
- Automatic HTTP to HTTPS redirect
- Unix socket support for reverse proxy deployments
Monitoring & Observability
Sockudo exposes metrics and health endpoints:- Prometheus metrics -
/metricsendpoint with detailed server statistics - Health checks -
/upand/up/{app_id}for load balancer health probes - Structured logging - JSON or human-readable logs with configurable levels
- Debug mode - Detailed tracing for troubleshooting
Configuration Hierarchy
Configuration values are resolved in this order (highest priority first):- Environment variables -
ADAPTER_DRIVER=redis - Command-line arguments -
--config /path/to/config.json - Config file -
config/config.json - Default values - Hardcoded defaults
Next Steps
Pusher Protocol
Learn about protocol compatibility and message formats
Channels
Understand channel types and subscription management
Authentication
Implement HMAC authentication for private channels
Configuration
Configure Sockudo for your deployment