I have a data modeling round at Faire. This is the background:
The customer support team wants to build a better data model for a much better customer experience. They are interested in three metrics:
Time to resolve
Representative utilization
CSAT score
One of the pain points is all of these events are coming in a single stream.
Here are the questions:
Can you build a data model for the metrics they care about?
Can you write SQL queries against the model?
Can you convert the event streams to tables?
How will the utilization change if the reps can be assigned multiple tickets at the same time?
Assistant
Absolutely, I'd be happy to help you think through these questions. Let's tackle them one by one:
1. Can you build a data model for the metrics they care about?
Understanding the Metrics:
Time to Resolve: The duration from when a ticket is opened to when it's resolved.
Representative Utilization: How effectively customer support representatives (reps) are engaged with handling tickets during their working hours.
CSAT Score: Customer Satisfaction scores collected after ticket resolution.
Challenges:
All events are coming in a single stream, meaning different event types are mixed together.
Approach to Building the Data Model:
a. Identify Key Entities:
Tickets: Represents customer issues that need resolution.
Representatives: Customer support agents handling the tickets.
Customers: Individuals who submit tickets.
Events: Actions or changes related to tickets, reps, or customers.
Representatives are associated with Ticket_Events when they interact with tickets.
Tickets may receive a CSAT Score after resolution.
Representatives have availability periods in Rep_Availability.
e. Capturing Event Data:
Event Stream Processing: Parse the single event stream and classify events into appropriate types to populate the tables.
2. Can you write SQL queries against the model?
Yes, using this data model, you can write SQL queries to compute the desired metrics.
Example Queries:
a. Time to Resolve
Calculate the average time to resolve tickets.
sql
SELECT
AVG(TIMESTAMPDIFF(SECOND, created_timestamp, resolved_timestamp)) / 3600 AS avg_resolution_time_hours
FROM
Tickets
WHERE
resolved_timestamp IS NOT NULL;
b. Representative Utilization
Calculate utilization for each rep based on assigned tickets.
sql
-- First, calculate total working time per rep from Rep_Availability
WITH Rep_Working_Time AS (
SELECT
representative_id,
SUM(TIMESTAMPDIFF(SECOND, start_time, end_time)) AS total_working_seconds
FROM
Rep_Availability
WHERE
status = 'Available'
GROUP BY
representative_id
),
-- Then, calculate time spent on tickets
Rep_Assignment_Time AS (
SELECT
representative_id,
SUM(TIMESTAMPDIFF(SECOND, MIN(event_timestamp), MAX(event_timestamp))) AS total_assignment_seconds
FROM
Ticket_Events
WHERE
event_type IN ('Assigned', 'Resolved') -- Assuming these events mark the assignment period
GROUP BY
representative_id,
ticket_id
)
-- Finally, compute utilization
SELECT
rwt.representative_id,
(rat.total_assignment_seconds / rwt.total_working_seconds) * 100 AS utilization_percentage
FROM
Rep_Working_Time rwt
JOIN
Rep_Assignment_Time rat ON rwt.representative_id = rat.representative_id;
c. CSAT Score
Calculate the average CSAT score.
sql
SELECT
AVG(score) AS average_csat_score
FROM
CSAT_Scores;
3. Can you convert the event streams to tables?
Yes, to convert the event streams into tables, you can:
a. Use an ETL Process:
Extract: Read the raw event stream data.
Transform:
Parse Events: For each event, extract relevant information (event type, timestamps, identifiers).
Classify Events: Determine which table(s) the event data belongs to.
Load: Insert the transformed data into the respective tables in your database.
b. Example Pseudocode for Event Processing:
pseudo
FOR each event IN event_stream:
IF event.type == 'Ticket Created':
INSERT INTO Tickets (...);
INSERT INTO Ticket_Events (...);
ELSE IF event.type == 'Ticket Assigned':
INSERT INTO Ticket_Events (...);
ELSE IF event.type == 'Ticket Resolved':
UPDATE Tickets SET resolved_timestamp = event.timestamp WHERE ticket_id = event.ticket_id;
INSERT INTO Ticket_Events (...);
ELSE IF event.type == 'CSAT Feedback Submitted':
INSERT INTO CSAT_Scores (...);
ELSE IF event.type == 'Rep Availability Change':
INSERT INTO Rep_Availability (...);
// Handle other event types similarly
c. Tools and Technologies:
Stream Processing Frameworks: Use tools like Apache Kafka, Apache Flink, or AWS Kinesis to handle event streams.
Data Integration Platforms: Tools like Apache NiFi or Talend can facilitate complex ETL processes.
Custom Scripts: Write scripts in languages like Python or Java to process and load events into the database.
4. How will the utilization change if the reps can be assigned multiple tickets at the same time?
Impact on Utilization Calculation:
Overlapping Assignments: When reps can handle multiple tickets simultaneously, time spent on tickets may overlap.
Potential Overestimation: Simply summing the assignment times may overestimate utilization because overlapping periods are counted multiple times.
Approach to Adjust Utilization:
a. Calculate Effective Assignment Time:
For each rep, create a timeline of their assignments.
Merge Overlapping Periods:
Combine overlapping time intervals to avoid double-counting.
This gives the total effective time the rep was handling any tickets.
b. Revised Utilization Formula:
[ \text{Utilization} = \left( \frac{\text{Total Effective Assignment Time}}{\text{Total Available Working Time}} \right) \times 100% ]
c. Steps to Calculate:
Collect Assignment Intervals:
For each ticket assigned to a rep, record the assignment start and end times.
Merge Intervals:
Sort intervals by start time.
Iterate through them, merging any that overlap or are contiguous.
Sum Merged Intervals:
The total duration of merged intervals represents the effective assignment time.
Calculate Utilization:
Divide the effective assignment time by the rep's total working time (from Rep_Availability).
d. Example SQL Query Concept:
Since standard SQL doesn't have built-in functions for interval merging, you might:
Extract Assignment Intervals into a temporary table.
Use procedural SQL or a programming language to merge intervals for each rep.
Sum the effective assignment times after merging.
e. Considerations:
Granularity: Accurate calculations depend on precise timestamps.
Data Volume: Merging intervals can be computationally intensive with large datasets.
Technology Choice: Use of analytical databases or big data technologies might be necessary.
Summary:
Data Modeling: Create structured tables from the single event stream to capture necessary data for metrics.
SQL Queries: Write queries that calculate metrics, adjusting for complexities like overlapping assignments.
Event Stream Conversion: Implement ETL processes to parse and load events into your tables.
Utilization Calculation Adjustments: Modify the utilization calculation to account for reps handling multiple tickets simultaneously, ensuring accurate measurement.
Additional Tips for Your Data Modeling Round:
Explain Assumptions: Clearly state any assumptions you're making, especially regarding how events and data are structured.
Data Integrity: Consider how to handle data anomalies, missing data, or incorrect timestamps.
Scalability: Think about how your data model and calculations will scale with increasing data volumes.
Performance Optimization: Be prepared to discuss indexing strategies or queries optimization.