Endpoint: POST /status
Description: This API updates the status of a user. It is called whenever a user's status changes.
Payload:
{
"userId": "string",
"status": "string" // Values: "online", "idle", "offline"
}
Response:
{
"success": true,
"message": "Status updated successfully."
}
Endpoint: GET /status/{userId}
Parameters: userId is the identifier of the user.
Description: Retrieves the current status of a user.
Response:
{
"userId": "string",
"status": "string",
"lastUpdated": "timestamp"
}
Endpoint: POST /statuses
Description: Retrieves the statuses for a batch of users, useful for applications needing to update multiple user statuses in one go.
Payload:
{
"userIds": ["string"]
}
Response:
{
"statuses": [
{
"userId": "string",
"status": "string",
"lastUpdated": "timestamp"
}
]
}
Given the requirements, we'll consider a combination of NoSQL for primary real-time status data and possibly another database for logging and analytical purposes. Below is a detailed schema using Cassandra and an auxiliary system like PostgreSQL for detailed logs and analytics.
UserStatus Table
UserActivity Table
UserDetails Table
UserStatus.userId.Web Servers
Load Balancer
Cache Layer
Database Layer
Message Queue
Notification Service
We'll examine two main scenarios:
This flow describes what happens when a user changes their status (e.g., from "online" to "idle").
Sequence of Events:
This flow covers how a user’s current status is fetched.
Sequence of Events:
Purpose: The Web Server handles all incoming API requests for updating and retrieving user statuses.
Key Responsibilities:
Scalability:
Technologies:
Purpose: The Cache Layer provides fast access to frequently accessed data, such as user statuses, to reduce latency and database load.
Key Responsibilities:
Scalability:
Technologies:
Purpose: Manages the distribution of real-time status updates to other clients and services.
Key Responsibilities:
Scalability:
Technologies:
Trade-off:
Technology Choice: Cassandra for real-time operations due to its superior performance in handling large volumes of data with high write and read throughput. PostgreSQL was chosen for detailed logs and analytics where complex queries are more common.
Trade-off:
Technology Choice: Using stateless architecture facilitated by a load balancer (like NGINX or AWS ELB) to ensure requests can be served by any server, enhancing reliability and ease of scaling.
Trade-off:
Technology Choice: Redis, known for its quick data access speeds and robustness, fitting the requirement for a high-performance, in-memory data store that supports rapid read and write operations.
Trade-off:
Technology Choice: RabbitMQ offers reliable messaging with strong delivery guarantees and is widely used in systems requiring high levels of decoupling and scalability.
Trade-off:
Technology Choice: Chose WebSockets for real-time bidirectional communication to ensure that users receive status updates without any perceptible delay.
Database Failure
Cache Failure
Message Queue Overload
Web Server Downtime
Network Issues
Cache Hotspots
Database Write Throughput
Real-Time Notification Delays