A high-performance, scalable WebSocket-based chat system built with Java, RabbitMQ, and AWS. Designed to handle high-throughput concurrent messaging across multiple server instances with horizontal scaling capabilities.
Note: This project was developed as part of a distributed systems course project, demonstrating real-world scalability patterns and production-ready architecture.
- Real-time Messaging: WebSocket-based bidirectional communication for instant message delivery
- Horizontal Scaling: Load-balanced architecture supporting multiple server instances via AWS Application Load Balancer
- Message Queue Integration: RabbitMQ for reliable message distribution and decoupling
- Room-based Chat: Support for multiple chat rooms with isolated message broadcasting
- High Throughput: Optimized to handle 4,000+ messages per second
- Connection Pooling: Efficient resource management with channel pooling and thread pools
- Health Monitoring: Built-in health check endpoints for load balancer integration
- Message Deduplication: Prevents duplicate message delivery across distributed instances
┌─────────────┐
│ Client │
│ (WebSocket) │
└──────┬──────┘
│
▼
┌────────────────────────────────┐
│ Chat Server Instance │
│ ┌──────────┐ ┌─────────────┐ │
│ │WebSocket │ │Message Pub. │ │
│ │ Server │ │ (Pool:100) │ │
│ └────┬─────┘ └──────┬──────┘ │
│ │ │ │
│ ┌────▼───────────────▼──┐ │
│ │ RabbitMQ Exchange │ │
│ └────────────┬──────────┘ │
└──────────────-┼────────────────┘
│
▼
┌─────────────────────────────────┐
│ RabbitMQ Broker │
│ ┌──────────────────────────┐ │
│ │ (room.1 - room.20) │ │
│ └──────────┬───────────────┘ │
└─────────────┼───────────────────┘
│
▼
┌─────────────────────────────────┐
│ Chat Server Instance │
│ ┌─────────────┐ ┌──────────┐ │
│ │Message Cons.│ │Broadcast │ │
│ │(Pool:40) │─►│ Engine │ │
│ └─────────────┘ └────┬─────┘ │
└────────────────────────┼────────┘
│
▼
┌─────────────┐
│ Clients │
│ (WebSocket) │
└─────────────┘
- Client Connection: Client connects via WebSocket to
/chat/{roomId} - Message Publishing: Server receives message and publishes to RabbitMQ topic exchange
- Queue Distribution: RabbitMQ routes message to room-specific queue
- Message Consumption: All server instances consume from their respective queues
- Broadcasting: Each server broadcasts to connected clients in that room
- Deduplication: Message IDs prevent duplicate delivery
- Thread Pool Architecture: Separate pools for message processing (100), broadcasting (20), and consuming (40)
- Channel Pooling: 100-channel pool for RabbitMQ publishing to minimize connection overhead
- Prefetch Optimization: QOS prefetch of 20 messages per consumer for balanced throughput
- Queue TTL: 5-minute message TTL with max length of 50k messages per queue
- Language: Java 11
- WebSocket: Java-WebSocket 1.5.4
- Message Broker: RabbitMQ 5.18.0
- JSON Processing: Gson 2.10.1
- Build Tool: Maven 3.x
- Cloud Infrastructure: AWS EC2, Application Load Balancer
- Monitoring: RabbitMQ Management Console, Custom metrics
- Java 11 or higher
- Maven 3.6+
- RabbitMQ Server (3.8+)
# Build server
cd server-v2
mvn clean package
# Build client
cd ../client-v2
mvn clean packageThe build process creates JAR files with all dependencies:
server-v2/target/chatflow-server-1.0-jar-with-dependencies.jarclient-v2/target/chatflow-client-1.0-jar-with-dependencies.jar
# On RabbitMQ EC2 instance
cd server-v2/src/main/java/io/chatflow/deployment
./setup-rabbitmq.sh
# Access management console at http://<rabbitmq-ip>:15672
# Default credentials: admin/admin# Copy JAR to server instances
scp -i ~/.ssh/key.pem \
target/chatflow-server-1.0-jar-with-dependencies.jar \
ec2-user@<ec2-ip>:~/
# SSH and start server
ssh -i ~/.ssh/key.pem ec2-user@<ec2-ip>
export RABBIT_HOST=<rabbitmq-private-ip>
java -cp chatflow-server-1.0-jar-with-dependencies.jar io.chatflow.server.ChatServer# Single instance test
java -cp target/chatflow-client-1.0-jar-with-dependencies.jar \
io.chatflow.client.ChatClient ws://<server-ip>:9090/chat/
# Load balanced test
java -cp target/chatflow-client-1.0-jar-with-dependencies.jar \
io.chatflow.client.ChatClient ws://<alb-dns>/chat/- WebSocket Server: 9090
- Health Check: 8081
- RabbitMQ AMQP: 5672
- RabbitMQ Management: 15672
# Thread Pool Sizes
message.processor.threads=100
consumer.threads=40
broadcast.threads=20
# RabbitMQ Settings
channel.pool.size=100
prefetch.count=20
# Queue Settings
queue.max.length=50000
message.ttl=300000 # 5 minutes- Type: Application Load Balancer (ALB)
- Target Group: 2-4 EC2 instances
- Health Check:
/healthendpoint on port 8081 - Stickiness: Disabled (for distributed testing)
- Algorithm: Round-robin
| Configuration | Throughput | Success Rate | Avg Queue Depth |
|---|---|---|---|
| 1 Instance | 5,571 msg/s | 99.94% | < 300 |
| 2 Instances | 5,725 msg/s | 99.97% | < 300 |
| 4 Instances | 4,402 msg/s | 99.95% | < 300 |
- Total Messages: 500,000
- Client Threads: 128
- Number of Rooms: 20
- Message Types: 90% TEXT, 5% JOIN, 5% LEAVE
- Consistent throughput across scaling configurations
- Queue depths remain stable (< 1000 messages)
- High success rate (> 99.9%)
- No message loss or duplicate delivery
- Efficient resource utilization
See monitoring/README.md for detailed performance analysis and screenshots.
.
├── server-v2/
│ ├── src/main/java/io/chatflow/
│ │ ├── server/
│ │ │ ├── ChatServer.java # Main WebSocket server
│ │ │ ├── RoomManager.java # Room management
│ │ │ ├── WebSocketBroadcaster.java # Message broadcasting
│ │ │ ├── HealthServer.java # Health check endpoint
│ │ │ └── Metrics.java # Performance metrics
│ │ ├── rabbitmq/
│ │ │ ├── MessagePublisher.java # RabbitMQ publisher with pooling
│ │ │ └── MessageConsumer.java # RabbitMQ consumer with deduplication
│ │ ├── deployment/
│ │ │ ├── setup-rabbitmq.sh # RabbitMQ setup script
│ │ │ └── start-server.sh # Server startup script
│ │ └── monitoring/
│ │ └── README.md # Performance analysis
│ └── pom.xml
├── client-v2/
│ ├── src/main/java/io/chatflow/
│ │ ├── client/
│ │ │ ├── ChatClient.java # Load test client
│ │ │ ├── SenderThread.java # WebSocket sender
│ │ │ ├── MessageGenerator.java # Message generation
│ │ │ └── Metrics.java # Client metrics
│ │ └── model/
│ │ └── ChatMessage.java # Message model
│ └── pom.xml
└── README.md
curl http://localhost:8081/healthResponse:
{
"status": "UP",
"timestamp": "2024-01-15T10:30:00Z"
}Access the RabbitMQ Management Console at http://<rabbitmq-ip>:15672 to monitor:
- Queue depths and rates
- Message throughput
- Connection status
- Consumer utilization
The included client can generate high-volume load tests:
java -cp chatflow-client-1.0-jar-with-dependencies.jar \
io.chatflow.client.ChatClient ws://<server-url>/chat/The client will:
- Generate 500,000 messages
- Distribute across 20 rooms
- Use 128 concurrent threads
- Report throughput and success rates
{
"userId": "12345",
"username": "user12345",
"message": "Hello, world!",
"timestamp": "2024-01-15T10:30:00Z",
"messageType": "TEXT"
}- Built a distributed chat system capable of handling 4,000+ messages/second
- Implemented efficient connection pooling and thread management
- Achieved 99.9%+ success rate under high load
- Designed scalable architecture with horizontal scaling support
- Integrated RabbitMQ for reliable message distribution
- Optimized queue management and message deduplication
This project is available for portfolio and educational purposes.
Sahilpreet Aneja
Developed as a demonstration of distributed systems architecture, real-time messaging, and cloud deployment expertise.
Note: This project demonstrates production-ready patterns for distributed systems, real-time communication, and scalable architecture design.