Functional Requirements
✅ Non-Functional Requirements
POST /messages/send
GET /messages/history?conversation_id
POST /messages/read
POST /users/block
POST /users/unblock
GET /users/presence
POST /reactions/add
POST /reactions/remove
Auth: OAuth2, JWT
Rate limiting and idempotency keys
WebSocket APIs:
connectsendMessagereceiveMessageupdatePresenceSQL (PostgreSQL, MySQL) → users, friendships, block lists
NoSQL (Cassandra, DynamoDB) → messages, reactions, presence
Redis → online presence, unread counters, ephemeral data
Blob storage (S3, GCS) → media files
ER Model core tables:
API Gateway
Authentication Service
User Service
Conversation Service
Message Service
Notification Service
Presence Service
Media Service (file storage, CDN)
WebSocket Gateway / Message Broker
Database Cluster (SQL for metadata, NoSQL for message storage)
Cache Layer (Redis, Memcached)
Search Engine (Elasticsearch for message search)
Send message:
Receive message:
Message Service
✅ Presence Service
✅ WebSocket Gateway
NoSQL over SQL for messages: High write throughput, horizontal scale
SQL for user data: Strong relations, ACID
Redis for presence: Low latency, fast expiration
WebSockets over polling: Lower latency, less overhead
Kafka decoupling: Prevents producer overload during spikes
Video/audio calls → use TURN/STUN servers, optimize for UDP
ML for spam/abuse detection
Dynamic scaling → auto-scale WebSocket and message layers
Cross-region replication → use CRDTs or conflict-free strategies
Optimize Redis operations → fine-tune pub/sub channels, shard presence data