If you get an interview with this team, first of all, congratulations, you're in for some bad luck. During the interview, the interviewer won't give you any feedback, and communication is pretty rough — I'd guess the interviewer himself hadn't really read the problem carefully. By the middle of the interview I had already implemented about half of a solution, but the interviewer eventually decided it was the wrong approach and wanted a different one. By then there wasn't enough time left, so he just had me keep implementing it through to the end anyway, which obviously wasn't a satisfying result.
The question itself is a real-world data platform problem. Just clarifying the requirements takes at least 20 minutes, and then you also need to implement an end-to-end solution. At the end they give you a JSON input and you need to test whether your solution actually works.
{"event_name": "send_message", "timestamp": "2016-11-08T14:09:57Z", "user_id": "1", "channel_id": "1"}
{"event_name": "send_message", "timestamp": "2016-11-08T14:10:01Z", "user_id": "1", "channel_id": "1"}
{"event_name": "send_message", "timestamp": "2016-11-08T14:10:07Z", "user_id": "2", "channel_id": "1"}
But if you're lucky enough to see this post and you land an interview with this team, congrats — I'll post the full interview report below. Run it through GPT and you'll pass.
We have a backend system that receives a "send_message" event notification whenever a user sends a message to a channel. Each message has the form:
{"event_name": "send_message", "timestamp": "2016-11-08T14:09:57Z", "user_id": "1", "channel_id": "1"}
You have been assigned a ticket with the following (somewhat vague) description: Create a system to monitor this event stream and generate a new stream containing "user sessions". A "user session" is defined as a sequence of events for a user where each event occurs within 30 minutes (inclusive) of the previous event.
You will be given a JSON file containing a chronologically-ordered series of send_message events (one event per line). We want to parse this stream and emit a stream of "user sessions" with the following information for each user session:
- user_id
- session_start_ts: timestamp of the first event
- session_end_ts: timestamp of the last event
- messages_sent: total count of messages
- top_channel_id: channel_id that received the most messages
- top_channel_messages_sent: count of messages sent to top_channel_id
The output format doesn't matter too much as long as all this data is in there. Example JSON output for a user session:
{'user_id': 1, 'session_start_ts': '2016-11-08T14:09:57Z', 'session_end_ts': '2016-11-08T14:09:57Z', 'messages_sent': 15, 'top_channel_id': 3, 'top_channel_messages_sent': 12}
To simplify things you can assume that events always arrive in chronological order with no missing, duplicated, or corrupt events. To complicate things you must not assume that the stream of events is finite. This means that your solution can't rely on anything being executed "after the end of the stream".
Discussion
Loading comments…