Design a multi-threaded synchronous log writer
Company: Databricks
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Technical Screen
### Problem
Design a log writer component that is called from **multiple application threads** and writes logs to a **single file on disk**.
Requirements:
- Callers can log concurrently: `log(message)` may be invoked by many threads.
- Writes must be **synchronous/durable**: once `log()` returns, the message must be persisted such that it survives a process crash (assume you must `fsync`/flush).
- Preserve a well-defined ordering (e.g., FIFO based on call time, or per-thread order—state your choice).
- High throughput: avoid doing an `fsync` per message if possible.
### Tasks
- Propose an implementation approach (data structures, threading model).
- Explain how you ensure durability, ordering, and performance.
- Discuss failure modes (disk full, partial writes, crash during write) and how to handle them.
Quick Answer: This question evaluates a candidate's understanding of concurrent programming, durable I/O, synchronization primitives, ordering guarantees, and system reliability under contention.