Clarify the problem requirements and constraints, then design a streaming solution that tracks per-user and per-book state to identify abusive events. Use a two-pass or streaming aggregation approach to compute the percentage of abusive events per book, and discuss trade-offs between accuracy, memory, and latency.
Pro tip: Emphasize the importance of defining 'abusive' precisely and handling edge cases like users who jump without prior progress, and discuss how to scale the solution using distributed stream processing frameworks like Apache Flink or Kafka Streams.
Ask questions to understand data volume, latency requirements, and whether the detection should be real-time or batch. Clarify the definition of 'abusive' and how to handle edge cases.
Define the state needed per user (e.g., max position reached) and per book (counts of total and abusive events). Consider using a key-value store or in-memory state with appropriate partitioning.
For each event, check if the user has ever passed the 10% mark (using stored state). If not and the current position is in the last 5%, mark the event as abusive. Update user state and book counts accordingly.
Continuously compute the percentage of abusive events per book. If it exceeds 20%, flag the book. Use windowing or periodic aggregation to manage state and output.
Address how to scale with increasing data (e.g., sharding by book ID), ensure fault tolerance (e.g., checkpointing), and trade-offs between exactness and approximation (e.g., using probabilistic data structures).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.