Real-Time Chat Backend API with WebSockets, Persistence, and Presence Tracking
Create and construct a WebSockets-based scalable backend API for a real-time chat application. The system should support low-latency bidirectional communication between clients and servers.
Conditions:
- WebSocket Interaction:
- Create and maintain long-term WebSocket connections.
- Manage the broadcasting of messages (1:1 and group chats).
- Make that the connection lifecycle (connect, detach, reconnect) is managed effectively.
- Handling and Storing Messages:
- Save chat messages with timestamps, sender IDs, and message statuses in a database.
- Provide pagination support for message history retrieval.
- Make sure the data is reliable and consistent.
- Monitoring User Presence:
- Monitor and instantly update a user’s online and offline status.
- Notify the appropriate users of changes in your presence.
- Address edge circumstances such as sudden disconnections.
- Performance and Scalability:
- Design with horizontal scalability in mind (e.g., distributed systems, load balancing).
- Aim for low latency and high concurrency.
- Reliability & Security:
- Put authentication into practice (e.g., session-based or JWT).
- Make sure that messages are transmitted securely.
- Retries and errors should be handled politely.
- Technology Stack (preferred but not required):
- Indicate your desired backend framework or language (e.g., Node.js, Python, .NET).
- Make use of the proper databases (Redis for presence, NoSQL for chat logs, etc.).
Anticipated Results:
- Overview of API architecture
- WebSocket events and important endpoints
- Schema design and data models
- Examples of implementation snippets
- Best practices for scalability and deployment
