KatInterview

Building an Append-Only Log Store with Real-Time File Following

System DesignModel answer
MediumModel answerSystem Designsystem-designlog-storagepartitioning

Last updated

Design a durable, scalable store that ingests huge volumes of appended log records, serves whole-file reads, and lets readers follow files that are still being written.

Problem

Design a storage service for a very large stream of log records. Producers keep appending records to named log files. The service must store them durably and let users read the files back. Some users read a file that is still being written and want to see new records soon after they arrive.

Reads are by file only: read from the start, or resume from where the reader stopped. There are no range queries and no searching inside records.

The write rate, record size, retention and freshness targets are not given. Ask about them or state your own assumptions and size the system from them.

Questions to answer

  1. Write volume and partitioning. How does the system absorb a huge write rate, and how is data spread across storage nodes? Cover the ingestion tier, the partition key, hot files, adding nodes, replication, and what an acknowledgement promises.
  2. Locating data. If a file's data lives on many nodes, how does a reader find it? Cover the metadata layer, its schema, its consistency with the data nodes, and how it scales and survives failures without sitting on the per-record write path.
  3. Write efficiency. How do you raise write throughput under heavy load? Cover batching, on-disk layout, compression, the durability and latency cost of buffering, and backpressure.
  4. Following a live file. How do readers see new data promptly, and how does the system track what is new for each reader? Compare polling with a long-lived push connection, and describe positions, reconnects, and exposing only durable data in order.
  5. Many readers and further scale. Do long-lived connections overload the servers? How do you scale storage, metadata and delivery independently, including tiering of old data?

State your assumptions about durability, freshness and retention, and justify each design choice with the access pattern above.

Hints

Hint 1

Since reads are always whole-file or resume-from-offset, think about which partition key keeps one file's data together and sequential, and what you do when a single file is extremely hot.

Hint 2

Keep metadata (file to segments to nodes) small and off the per-record path: update it per segment or per rollover, not per record. A reader's position can be a simple monotonically increasing offset.

Hint 3

For live readers, only advance a 'committed offset' once data is replicated, let readers ask for data after their offset, and consider a separate delivery tier so reader fan-out never competes with ingestion.