0
0
HLDsystem_design~20 mins

Metrics collection in HLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Metrics Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Metrics Collection Purpose

What is the primary purpose of collecting metrics in a database system?

ATo monitor system performance and detect anomalies
BTo store user data permanently
CTo create database backups automatically
DTo encrypt sensitive information
Attempts:
2 left
💡 Hint

Think about why you would want to watch how the database behaves over time.

query_result
intermediate
2:00remaining
Interpreting a Metrics Query Result

Given a metrics table with columns metric_name, value, and timestamp, what will this query return?

SELECT metric_name, AVG(value) FROM metrics WHERE timestamp > NOW() - INTERVAL '1 hour' GROUP BY metric_name;
AAll metric names without any values
BSum of all metric values in the last hour
CThe latest value of each metric regardless of time
DAverage values of each metric collected in the last hour
Attempts:
2 left
💡 Hint

Look at the AVG(value) and the time filter in the WHERE clause.

🧠 Conceptual
advanced
1:30remaining
Identifying Syntax Error in Metrics Collection Query

Which option contains a syntax error in this metrics collection SQL query?

SELECT metric_name, COUNT(*) FROM metrics GROUP BY metric_name HAVING COUNT(*) > 10;
ASELECT metric_name, COUNT(*) FROM metrics WHERE COUNT(*) > 10 GROUP BY metric_name;
BSELECT metric_name, COUNT(*) FROM metrics GROUP BY metric_name HAVING COUNT(*) < 5;
CSELECT metric_name, COUNT(*) FROM metrics GROUP BY metric_name;
DSELECT metric_name, COUNT(*) FROM metrics GROUP BY metric_name HAVING COUNT(*) > 10;
Attempts:
2 left
💡 Hint

Remember that WHERE cannot filter on aggregate functions like COUNT().

optimization
advanced
2:00remaining
Optimizing Metrics Query Performance

You have a large metrics table with millions of rows. Which index would best improve the performance of this query?

SELECT metric_name, AVG(value) FROM metrics WHERE timestamp > NOW() - INTERVAL '1 day' GROUP BY metric_name;
ACreate an index on <code>(value)</code>
BCreate an index on <code>(timestamp, metric_name)</code>
CCreate an index on <code>(metric_name)</code> only
DCreate an index on <code>(timestamp)</code> only
Attempts:
2 left
💡 Hint

Think about which columns are used in filtering and grouping.

🔍 Analysis
expert
2:30remaining
Debugging Missing Metrics Data

A metrics collection system shows no data for the last hour, but older data exists. Which issue is most likely causing this?

AThe metrics query uses <code>WHERE timestamp &lt; NOW() - INTERVAL '1 hour'</code> instead of <code>&gt;</code>
BThe database table is full and rejecting new inserts
CThe system clock is incorrect, causing timestamps to be in the future
DThe metrics values are all zero, so they don't appear in results
Attempts:
2 left
💡 Hint

Consider how timestamps affect filtering recent data.