Batch Concurrent Logs into Five-Second Windows
OtherSoftware Engineer · OnsiteLast updated
Batch concurrent logs into half-open five-second processing-time windows with atomic rotation, a single ordered emitter, late-timer handling, and explicit shutdown and sink-failure policies.
Constraints & Assumptions
The source specifies concurrent producers and five-second batching but leaves timing and delivery policies open. For this practice design, use processing time from a monotonic clock, windows [origin+5k, origin+5(k+1)), and the time a record is admitted under the logger's lock. Omit empty windows. A final shutdown flush may emit the current partial window. Sink delivery must preserve batch order.
Clarifying Questions
Are windows based on arrival time or an event timestamp? What happens exactly at the boundary? Can the sink block or fail? What memory/backpressure policy is allowed? What happens at shutdown?
Follow-up questions
- What if the timer wakes late or no new log arrives after a window closes? Why can two threads flushing outside the lock reorder batches? How do retries avoid silently losing or duplicating a batch?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.