This one took me a while to even parse correctly.
Start by clarifying the event schema and defining the exact conditions for an abusive read. Then propose a streaming architecture with per-user and per-book state, using windowed aggregations and scalable storage. Finally, discuss concurrency control and trade-offs between accuracy and latency.
Pro tip: Emphasize that the 20% threshold requires a global view per book, so you need to aggregate across all users; consider using a distributed counter with eventual consistency and periodic recomputation to avoid hot keys.
Ask about event schema (e.g., user_id, book_id, position, timestamp), definition of 'completing' a section, and whether events are ordered. Confirm that 'abusive' is per user per book and that book flagging is based on total events.
For each (user, book) pair, track whether the user has completed the first 10% and whether they reached the last 5% before that. Use a compact state like a bitmask or two booleans, stored in a key-value store (e.g., Redis) with TTL.
Maintain per-book counters: total events and abusive events. When a user's state transitions to abusive, increment the abusive counter for that book. Use a distributed counter (e.g., Redis INCR) and compute the ratio periodically.
Use partitioning by user_id for per-user state to avoid contention. For book counters, use sharded counters or a stream processing framework (e.g., Kafka Streams, Flink) with windowed aggregations. Discuss exactly-once semantics and idempotency.
Compare latency vs accuracy: real-time flagging may be noisy; batch recomputation can correct. Mention handling late events, out-of-order data, and scaling to millions of users/books.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.