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.
Design a thread-safe logger that receives records from multiple producer threads and emits batches for consecutive five-second windows.
### 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?
### What a Strong Answer Covers
Atomic admission and window rotation, timer behavior, separation of shared state from slow output, ordered emission, and deterministic boundary/concurrency tests.
### 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?
Overview: 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.
Design a thread-safe logger that receives records from multiple producer threads and emits batches for consecutive five-second windows.
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 Guidance
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?
What a Strong Answer Covers Guidance
Atomic admission and window rotation, timer behavior, separation of shared state from slow output, ordered emission, and deterministic boundary/concurrency tests.
Follow-up Questions Guidance
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?