This isn't just a chat app; it's a full-stack event-driven system. It demonstrates the bridge between stateless RESTful services and stateful real-time communication. By utilizing STOMP over WebSockets, the application provides a seamless, low-latency experience for global users.
A common bottleneck in chat apps is handling millions of concurrent connections. Here is how this architecture is designed to grow:
Currently, the system uses an In-Memory Broker. To scale for 1M+ users:
- The Plan: Integrate Redis Pub/Sub or RabbitMQ.
- The Goal: This allows us to run multiple backend instances behind a Load Balancer; if User A is on Server 1 and User B is on Server 2, the message broker ensures they can still talk.
- Sharding: As the chat history grows, MongoDB's sharding capabilities will be utilized to distribute data based on
room_id, preventing any single database instance from becoming a bottleneck.
- NGINX / AWS ALB: Implementing "Sticky Sessions" or "Session Affinity" to ensure WebSocket connections stay pinned to the correct server during a session.
- The Connection Lifecycle: Managing "Ghost Connections" (users who disconnect without closing the socket) to save server resources.
- Message Delivery Guarantees: Implementing a structured JSON payload that includes timestamps and unique IDs to ensure messages appear in the correct order on all clients.
- CORS & Security: Configuring Spring Security to allow cross-origin communication from the React frontend while protecting the WebSocket handshake.
# Bring up the entire stack with one command
docker-compose up -d🛣️ Roadmap: To the Cloud [ ] Auth: JWT-based stateless authentication.
[ ] Broker: Externalizing the message broker (RabbitMQ/Kafka) for horizontal scaling.
[ ] Cloud: Migrating from Render to AWS ECS (Fargate) for auto-scaling capabilities.
I'm an engineer fascinated by distributed systems and real-time data flow. I'm always open to discussing system design, backend optimizations, or potential collaborations.
"Scalability is not an afterthought; it's a design requirement."