endEvent arriving before a startEvent.startEvent(event_id, timestamp): Record the start of an event.endEvent(event_id, timestamp): Record the end of an event.getOngoingEvents(timestamp): Return the count of events ongoing as of the specified timestamp. This can only be queried for timestamps older than 24 hours.getOngoingEvents is for historical data older than 24 hours), the system should still provide reasonable query response times.event_id: 16 bytes (UUID)event_type: 4 bytes (integer or short string)description: Assume average 128 bytes (could vary)start_time, end_time, and arrival_time: Assume 8 bytes each (typically stored as 64-bit timestamps)POST /api/events
Authorization: Bearer
Content-Type: application/json
{
"event_type": "USER_SIGNUP",
"source": "mobile_app",
"payload": {
"user_id": "abc123",
"timestamp": "2025-07-11T18:00:00Z"
}
}
GET /api/events/{event_id}
Authorization: Bearer
GET /api/events?type=USER_SIGNUP&start=2025-07-01&end=2025-07-10
Authorization: Bearer
POST /api/notifications
Authorization: Bearer
Content-Type: application/json
{
"user_id": "abc123",
"message": "Welcome to the platform!",
"event_id": "evt-789xyz"
}
Store event in Nosql DB, like Cassandra.
CREATE TABLE events_by_user_and_date (
user_id TEXT,
event_date DATE, -- YYYY-MM-DD, extracted from created_at
created_at TIMESTAMP,
event_id UUID,
event_type TEXT,
source TEXT,
payload TEXT, -- or JSON string
status TEXT,
PRIMARY KEY ((user_id, event_date), created_at)
) WITH CLUSTERING ORDER BY (created_at DESC);
1. Event Producer → Ingestion API
HTTP POST to /api/events
Payload: JSON event data
API validates and forwards the event
2. Ingestion Service → Kafka
The service publishes the event to a Kafka topic (e.g., events.incoming)
3. Kafka → Event Processor
Event Processor (Kafka Consumer):
Consumes the event
Validates/enriches/transforms it
Persists to Cassandra (events_by_user_and_date, etc.)
Publishes processed status to another Kafka topic (e.g., events.processed)
4. Event Processor → Notification Service
If event type requires notification:
Sends message to Notification Service
OR pushes to notifications.to_send Kafka topic
5. Notification Service → WebSocket Server
Sends real-time notification to connected WebSocket clients:
Message includes event ID, type, timestamp, etc.
6. Client Receives Notification
WebSocket client displays the update
POST /api/events → Ingestion ServiceGET /api/events → Query ServicePOST /api/notifications → Notification Serviceevents.incoming)events.incomingevents.incomingevents.processednotifications.to_sendevents.incomingevents_by_user_and_dateevents_by_type_and_dateevents_by_idevents.processed to KafkaGET /api/events?user_id=XGET /api/events?event_type=Ynotifications.to_send or receives HTTP triggerevents_by_user_and_dateevents_by_type_and_dateevents_by_idnotifications_by_userExplain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?